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

Function TestRequestAccessTokenUsesConfiguredAppCredentials

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

Source from the content-addressed store, hash-verified

744}
745
746func 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
779func TestRequestAccessTokenRejectsEmptyAppCredentials(t *testing.T) {
780 restoreOAuthCredentials(t)

Callers

nothing calls this directly

Calls 3

restoreOAuthCredentialsFunction · 0.85
setOAuthCredentialsFunction · 0.85
requestAccessTokenFunction · 0.85

Tested by

no test coverage detected