(t *testing.T)
| 744 | } |
| 745 | |
| 746 | func TestRequestAccessTokenUsesConfiguredAppCredentials(t *testing.T) { |
| 747 | restoreOAuthCredentials(t) |
| 748 | setOAuthCredentials(tokenPersonal, "configured-key") |
| 749 | |
| 750 | origReadAuthorizationCode := readAuthorizationCode |
| 751 | origExchangeAuthorizationCode := exchangeAuthorizationCode |
| 752 | t.Cleanup(func() { |
| 753 | readAuthorizationCode = origReadAuthorizationCode |
| 754 | exchangeAuthorizationCode = origExchangeAuthorizationCode |
| 755 | }) |
| 756 | |
| 757 | readAppCredentials = func(tokType string) (appCredentials, error) { |
| 758 | t.Fatal("app credential prompt should not be used") |
| 759 | return appCredentials{}, nil |
| 760 | } |
| 761 | readAuthorizationCode = func() (string, error) { |
| 762 | return "auth-code", nil |
| 763 | } |
| 764 | exchangeAuthorizationCode = func(ctx context.Context, conf *oauth2.Config, code string, verifier string) (*oauth2.Token, error) { |
| 765 | if conf.ClientID != "configured-key" { |
| 766 | t.Fatalf("expected configured app key, got %q", conf.ClientID) |
| 767 | } |
| 768 | if conf.ClientSecret != "" { |
| 769 | t.Fatalf("expected no client secret for PKCE, got %q", conf.ClientSecret) |
| 770 | } |
| 771 | return &oauth2.Token{AccessToken: "access-token", RefreshToken: "refresh-token", TokenType: "Bearer", Expiry: time.Now().Add(time.Hour)}, nil |
| 772 | } |
| 773 | |
| 774 | if _, err := requestAccessToken(tokenPersonal, ""); err != nil { |
| 775 | t.Fatal(err) |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | func TestRequestAccessTokenRejectsEmptyAppCredentials(t *testing.T) { |
| 780 | restoreOAuthCredentials(t) |
nothing calls this directly
no test coverage detected