Fix bodyclose

This commit is contained in:
Mark Sagi-Kazar 2019-12-18 16:04:03 +01:00
parent 2f8d1f8e42
commit 65c77e9db2
No known key found for this signature in database
GPG Key ID: 34CC109EB5ED1C2A
4 changed files with 30 additions and 5 deletions

View File

@ -19,7 +19,6 @@ linters:
- unparam - unparam
- golint - golint
- goconst - goconst
- bodyclose
- staticcheck - staticcheck
- nakedret - nakedret
- ineffassign - ineffassign

View File

@ -209,6 +209,8 @@ func (p *conn) getAdminToken(ctx context.Context) (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
defer resp.Body.Close()
token := resp.Header.Get("X-Subject-Token") token := resp.Header.Get("X-Subject-Token")
return token, nil return token, nil
} }
@ -228,6 +230,7 @@ func (p *conn) checkIfUserExists(ctx context.Context, userID string, token strin
if err != nil { if err != nil {
return false, err return false, err
} }
defer resp.Body.Close()
if resp.StatusCode == 200 { if resp.StatusCode == 200 {
return true, nil return true, nil

View File

@ -154,7 +154,12 @@ func delete(t *testing.T, token, id, uri string) {
t.Fatalf("error: %v", err) t.Fatalf("error: %v", err)
} }
req.Header.Set("X-Auth-Token", token) req.Header.Set("X-Auth-Token", token)
client.Do(req)
resp, err := client.Do(req)
if err != nil {
t.Fatalf("error: %v", err)
}
defer resp.Body.Close()
} }
func createGroup(t *testing.T, token, description, name string) string { func createGroup(t *testing.T, token, description, name string) string {
@ -208,7 +213,13 @@ func addUserToGroup(t *testing.T, token, groupID, userID string) error {
return err return err
} }
req.Header.Set("X-Auth-Token", token) req.Header.Set("X-Auth-Token", token)
client.Do(req)
resp, err := client.Do(req)
if err != nil {
t.Fatalf("error: %v", err)
}
defer resp.Body.Close()
return nil return nil
} }

View File

@ -590,6 +590,8 @@ func TestOAuth2CodeFlow(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("get failed: %v", err) t.Fatalf("get failed: %v", err)
} }
defer resp.Body.Close()
if reqDump, err = httputil.DumpRequest(resp.Request, false); err != nil { if reqDump, err = httputil.DumpRequest(resp.Request, false); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -726,6 +728,8 @@ func TestOAuth2ImplicitFlow(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("get failed: %v", err) t.Fatalf("get failed: %v", err)
} }
defer resp.Body.Close()
if reqDump, err = httputil.DumpRequest(resp.Request, false); err != nil { if reqDump, err = httputil.DumpRequest(resp.Request, false); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -847,6 +851,8 @@ func TestCrossClientScopes(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("get failed: %v", err) t.Fatalf("get failed: %v", err)
} }
defer resp.Body.Close()
if reqDump, err = httputil.DumpRequest(resp.Request, false); err != nil { if reqDump, err = httputil.DumpRequest(resp.Request, false); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -967,6 +973,8 @@ func TestCrossClientScopesWithAzpInAudienceByDefault(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("get failed: %v", err) t.Fatalf("get failed: %v", err)
} }
defer resp.Body.Close()
if reqDump, err = httputil.DumpRequest(resp.Request, false); err != nil { if reqDump, err = httputil.DumpRequest(resp.Request, false); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -1222,9 +1230,11 @@ func TestRefreshTokenFlow(t *testing.T) {
RedirectURL: redirectURL, RedirectURL: redirectURL,
} }
if _, err = http.Get(oauth2Client.server.URL + "/login"); err != nil { resp, err := http.Get(oauth2Client.server.URL + "/login")
if err != nil {
t.Fatalf("get failed: %v", err) t.Fatalf("get failed: %v", err)
} }
defer resp.Body.Close()
tok := &oauth2.Token{ tok := &oauth2.Token{
RefreshToken: oauth2Client.token.RefreshToken, RefreshToken: oauth2Client.token.RefreshToken,
@ -1232,9 +1242,11 @@ func TestRefreshTokenFlow(t *testing.T) {
} }
// Login in again to receive a new token. // Login in again to receive a new token.
if _, err = http.Get(oauth2Client.server.URL + "/login"); err != nil { resp, err = http.Get(oauth2Client.server.URL + "/login")
if err != nil {
t.Fatalf("get failed: %v", err) t.Fatalf("get failed: %v", err)
} }
defer resp.Body.Close()
// try to refresh expired token with old refresh token. // try to refresh expired token with old refresh token.
if _, err := oauth2Client.config.TokenSource(ctx, tok).Token(); err == nil { if _, err := oauth2Client.config.TokenSource(ctx, tok).Token(); err == nil {