(t *testing.T)
| 596 | } |
| 597 | |
| 598 | func TestRequestAccessTokenUsesDefaultTeamManageAppKey(t *testing.T) { |
| 599 | restoreOAuthCredentials(t) |
| 600 | setOAuthCredentials(tokenTeamManage, defaultTeamManageAppKey) |
| 601 | |
| 602 | origReadAuthorizationCode := readAuthorizationCode |
| 603 | origExchangeAuthorizationCode := exchangeAuthorizationCode |
| 604 | t.Cleanup(func() { |
| 605 | readAuthorizationCode = origReadAuthorizationCode |
| 606 | exchangeAuthorizationCode = origExchangeAuthorizationCode |
| 607 | }) |
| 608 | |
| 609 | readAppCredentials = func(tokType string) (appCredentials, error) { |
| 610 | t.Fatal("app credential prompt should not be used for the default team manage app key") |
| 611 | return appCredentials{}, nil |
| 612 | } |
| 613 | readAuthorizationCode = func() (string, error) { |
| 614 | return "auth-code", nil |
| 615 | } |
| 616 | exchangeAuthorizationCode = func(ctx context.Context, conf *oauth2.Config, code string, verifier string) (*oauth2.Token, error) { |
| 617 | if conf.ClientID != defaultTeamManageAppKey { |
| 618 | t.Fatalf("expected default team manage app key, got %q", conf.ClientID) |
| 619 | } |
| 620 | if conf.ClientSecret != "" { |
| 621 | t.Fatalf("expected no client secret for PKCE, got %q", conf.ClientSecret) |
| 622 | } |
| 623 | return &oauth2.Token{AccessToken: "access-token", RefreshToken: "refresh-token", TokenType: "Bearer", Expiry: time.Now().Add(time.Hour)}, nil |
| 624 | } |
| 625 | |
| 626 | token, err := requestAccessToken(tokenTeamManage, "") |
| 627 | if err != nil { |
| 628 | t.Fatal(err) |
| 629 | } |
| 630 | if token != "access-token" { |
| 631 | t.Fatalf("expected access token, got %q", token) |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | func TestRequestAccessTokenUsesDefaultPersonalAppKey(t *testing.T) { |
| 636 | restoreOAuthCredentials(t) |
nothing calls this directly
no test coverage detected