Skip to content

Commit

Permalink
Fix bodyclose
Browse files Browse the repository at this point in the history
  • Loading branch information
sagikazarmark committed Dec 18, 2019
1 parent 2f8d1f8 commit 65c77e9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ linters:
- unparam
- golint
- goconst
- bodyclose
- staticcheck
- nakedret
- ineffassign
Expand Down
3 changes: 3 additions & 0 deletions connector/keystone/keystone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
15 changes: 13 additions & 2 deletions connector/keystone/keystone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
16 changes: 14 additions & 2 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -1222,19 +1230,23 @@ 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,
Expiry: time.Now().Add(-time.Hour),
}

// 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 {
Expand Down

0 comments on commit 65c77e9

Please sign in to comment.