MCPcopy Create free account
hub / github.com/dropbox/dbxcli / TestRequestAccessTokenUsesDefaultPersonalAppKey

Function TestRequestAccessTokenUsesDefaultPersonalAppKey

cmd/auth_test.go:635–666  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

633}
634
635func 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
668func TestRequestAccessTokenUsesPKCEOfflineAuthURL(t *testing.T) {
669 mockOAuthAppCredentials(t)

Callers

nothing calls this directly

Calls 3

restoreOAuthCredentialsFunction · 0.85
setOAuthCredentialsFunction · 0.85
requestAccessTokenFunction · 0.85

Tested by

no test coverage detected