(t *testing.T)
| 633 | } |
| 634 | |
| 635 | func TestRequestAccessTokenUsesDefaultPersonalAppKey(t *testing.T) { |
| 636 | restoreOAuthCredentials(t) |
| 637 | setOAuthCredentials(tokenPersonal, defaultPersonalAppKey) |
| 638 | |
| 639 | origReadAuthorizationCode := readAuthorizationCode |
| 640 | origExchangeAuthorizationCode := exchangeAuthorizationCode |
| 641 | t.Cleanup(func() { |
| 642 | readAuthorizationCode = origReadAuthorizationCode |
| 643 | exchangeAuthorizationCode = origExchangeAuthorizationCode |
| 644 | }) |
| 645 | |
| 646 | readAppCredentials = func(tokType string) (appCredentials, error) { |
| 647 | t.Fatal("app credential prompt should not be used for the default personal app key") |
| 648 | return appCredentials{}, nil |
| 649 | } |
| 650 | readAuthorizationCode = func() (string, error) { |
| 651 | return "auth-code", nil |
| 652 | } |
| 653 | exchangeAuthorizationCode = func(ctx context.Context, conf *oauth2.Config, code string, verifier string) (*oauth2.Token, error) { |
| 654 | if conf.ClientID != defaultPersonalAppKey { |
| 655 | t.Fatalf("expected default personal app key, got %q", conf.ClientID) |
| 656 | } |
| 657 | if conf.ClientSecret != "" { |
| 658 | t.Fatalf("expected no client secret for PKCE, got %q", conf.ClientSecret) |
| 659 | } |
| 660 | return &oauth2.Token{AccessToken: "access-token", RefreshToken: "refresh-token", TokenType: "Bearer", Expiry: time.Now().Add(time.Hour)}, nil |
| 661 | } |
| 662 | |
| 663 | if _, err := requestAccessToken(tokenPersonal, ""); err != nil { |
| 664 | t.Fatal(err) |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | func TestRequestAccessTokenUsesPKCEOfflineAuthURL(t *testing.T) { |
| 669 | mockOAuthAppCredentials(t) |
nothing calls this directly
no test coverage detected