(t *testing.T, code string, accessToken string)
| 187 | } |
| 188 | |
| 189 | func mockAuthorization(t *testing.T, code string, accessToken string) { |
| 190 | t.Helper() |
| 191 | |
| 192 | mockOAuthAppCredentials(t) |
| 193 | |
| 194 | origReadAuthorizationCode := readAuthorizationCode |
| 195 | origExchangeAuthorizationCode := exchangeAuthorizationCode |
| 196 | t.Cleanup(func() { |
| 197 | readAuthorizationCode = origReadAuthorizationCode |
| 198 | exchangeAuthorizationCode = origExchangeAuthorizationCode |
| 199 | }) |
| 200 | |
| 201 | readAuthorizationCode = func() (string, error) { |
| 202 | return code, nil |
| 203 | } |
| 204 | exchangeAuthorizationCode = func(ctx context.Context, conf *oauth2.Config, gotCode string, verifier string) (*oauth2.Token, error) { |
| 205 | if gotCode != code { |
| 206 | t.Fatalf("expected authorization code %q, got %q", code, gotCode) |
| 207 | } |
| 208 | if verifier == "" { |
| 209 | t.Fatal("expected PKCE verifier") |
| 210 | } |
| 211 | return &oauth2.Token{ |
| 212 | AccessToken: accessToken, |
| 213 | RefreshToken: "refresh-token", |
| 214 | TokenType: "Bearer", |
| 215 | Expiry: time.Now().Add(time.Hour), |
| 216 | }, nil |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | func TestGetAccessTokenUsesExistingToken(t *testing.T) { |
| 221 | authFile := filepath.Join(t.TempDir(), "auth.json") |
no test coverage detected