From 65c77e9db2e1e32fe4837970ea2da06758be42da Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Wed, 18 Dec 2019 16:04:03 +0100 Subject: [PATCH] Fix bodyclose --- .golangci.yml | 1 - connector/keystone/keystone.go | 3 +++ connector/keystone/keystone_test.go | 15 +++++++++++++-- server/server_test.go | 16 ++++++++++++++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 89e09982..1ff5dd64 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,7 +19,6 @@ linters: - unparam - golint - goconst - - bodyclose - staticcheck - nakedret - ineffassign diff --git a/connector/keystone/keystone.go b/connector/keystone/keystone.go index 71a59de8..6ce22d1a 100644 --- a/connector/keystone/keystone.go +++ b/connector/keystone/keystone.go @@ -209,6 +209,8 @@ func (p *conn) getAdminToken(ctx context.Context) (string, error) { if err != nil { return "", err } + defer resp.Body.Close() + token := resp.Header.Get("X-Subject-Token") return token, nil } @@ -228,6 +230,7 @@ func (p *conn) checkIfUserExists(ctx context.Context, userID string, token strin if err != nil { return false, err } + defer resp.Body.Close() if resp.StatusCode == 200 { return true, nil diff --git a/connector/keystone/keystone_test.go b/connector/keystone/keystone_test.go index d8bb0268..784cdc4f 100644 --- a/connector/keystone/keystone_test.go +++ b/connector/keystone/keystone_test.go @@ -154,7 +154,12 @@ func delete(t *testing.T, token, id, uri string) { t.Fatalf("error: %v", err) } 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 { @@ -208,7 +213,13 @@ func addUserToGroup(t *testing.T, token, groupID, userID string) error { return err } 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 } diff --git a/server/server_test.go b/server/server_test.go index ef49ed6f..8fe84c9a 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -590,6 +590,8 @@ func TestOAuth2CodeFlow(t *testing.T) { if err != nil { t.Fatalf("get failed: %v", err) } + defer resp.Body.Close() + if reqDump, err = httputil.DumpRequest(resp.Request, false); err != nil { t.Fatal(err) } @@ -726,6 +728,8 @@ func TestOAuth2ImplicitFlow(t *testing.T) { if err != nil { t.Fatalf("get failed: %v", err) } + defer resp.Body.Close() + if reqDump, err = httputil.DumpRequest(resp.Request, false); err != nil { t.Fatal(err) } @@ -847,6 +851,8 @@ func TestCrossClientScopes(t *testing.T) { if err != nil { t.Fatalf("get failed: %v", err) } + defer resp.Body.Close() + if reqDump, err = httputil.DumpRequest(resp.Request, false); err != nil { t.Fatal(err) } @@ -967,6 +973,8 @@ func TestCrossClientScopesWithAzpInAudienceByDefault(t *testing.T) { if err != nil { t.Fatalf("get failed: %v", err) } + defer resp.Body.Close() + if reqDump, err = httputil.DumpRequest(resp.Request, false); err != nil { t.Fatal(err) } @@ -1222,9 +1230,11 @@ func TestRefreshTokenFlow(t *testing.T) { 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) } + defer resp.Body.Close() tok := &oauth2.Token{ RefreshToken: oauth2Client.token.RefreshToken, @@ -1232,9 +1242,11 @@ func TestRefreshTokenFlow(t *testing.T) { } // 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) } + defer resp.Body.Close() // try to refresh expired token with old refresh token. if _, err := oauth2Client.config.TokenSource(ctx, tok).Token(); err == nil {