| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package auth | 5 package auth |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | |
| 9 "io/ioutil" | 8 "io/ioutil" |
| 10 "math/rand" | 9 "math/rand" |
| 11 "net/http" | 10 "net/http" |
| 12 "net/http/httptest" | 11 "net/http/httptest" |
| 13 "testing" | 12 "testing" |
| 14 "time" | 13 "time" |
| 15 | 14 |
| 16 "golang.org/x/net/context" | 15 "golang.org/x/net/context" |
| 17 "golang.org/x/oauth2" | 16 "golang.org/x/oauth2" |
| 18 | 17 |
| 19 "github.com/luci/luci-go/common/auth/internal" | 18 "github.com/luci/luci-go/common/auth/internal" |
| 20 "github.com/luci/luci-go/common/clock" | 19 "github.com/luci/luci-go/common/clock" |
| 21 "github.com/luci/luci-go/common/clock/testclock" | 20 "github.com/luci/luci-go/common/clock/testclock" |
| 22 "github.com/luci/luci-go/common/data/rand/mathrand" | 21 "github.com/luci/luci-go/common/data/rand/mathrand" |
| 23 "github.com/luci/luci-go/common/errors" | 22 "github.com/luci/luci-go/common/errors" |
| 23 "github.com/luci/luci-go/common/retry" |
| 24 | 24 |
| 25 . "github.com/luci/luci-go/common/testing/assertions" | 25 . "github.com/luci/luci-go/common/testing/assertions" |
| 26 . "github.com/smartystreets/goconvey/convey" | 26 . "github.com/smartystreets/goconvey/convey" |
| 27 ) | 27 ) |
| 28 | 28 |
| 29 var ( | 29 var ( |
| 30 now = time.Date(2015, time.January, 1, 0, 0, 0, 0, time.UTC) | 30 now = time.Date(2015, time.January, 1, 0, 0, 0, 0, time.UTC) |
| 31 past = time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC) | 31 past = time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC) |
| 32 future = now.Add(24 * time.Hour) | 32 future = now.Add(24 * time.Hour) |
| 33 ) | 33 ) |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 return p.tokenToMint, nil | 584 return p.tokenToMint, nil |
| 585 } | 585 } |
| 586 return &oauth2.Token{AccessToken: "some minted token"}, nil | 586 return &oauth2.Token{AccessToken: "some minted token"}, nil |
| 587 } | 587 } |
| 588 | 588 |
| 589 func (p *fakeTokenProvider) RefreshToken(ctx context.Context, prev, base *oauth2
.Token) (*oauth2.Token, error) { | 589 func (p *fakeTokenProvider) RefreshToken(ctx context.Context, prev, base *oauth2
.Token) (*oauth2.Token, error) { |
| 590 p.refreshTokenCalled = true | 590 p.refreshTokenCalled = true |
| 591 p.baseTokenInRefresh = base | 591 p.baseTokenInRefresh = base |
| 592 if p.transientRefreshErrors != 0 { | 592 if p.transientRefreshErrors != 0 { |
| 593 p.transientRefreshErrors-- | 593 p.transientRefreshErrors-- |
| 594 » » return nil, errors.WrapTransient(fmt.Errorf("transient error")) | 594 » » return nil, errors.New("transient error", retry.Tag) |
| 595 } | 595 } |
| 596 if p.revokedCreds { | 596 if p.revokedCreds { |
| 597 return nil, internal.ErrBadCredentials | 597 return nil, internal.ErrBadCredentials |
| 598 } | 598 } |
| 599 if p.revokedToken { | 599 if p.revokedToken { |
| 600 return nil, internal.ErrBadRefreshToken | 600 return nil, internal.ErrBadRefreshToken |
| 601 } | 601 } |
| 602 if p.tokenToRefresh != nil { | 602 if p.tokenToRefresh != nil { |
| 603 return p.tokenToRefresh, nil | 603 return p.tokenToRefresh, nil |
| 604 } | 604 } |
| 605 return &oauth2.Token{AccessToken: "some refreshed token"}, nil | 605 return &oauth2.Token{AccessToken: "some refreshed token"}, nil |
| 606 } | 606 } |
| OLD | NEW |