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

Function TestRequestAccessTokenRejectsEmptyAppCredentials

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

Source from the content-addressed store, hash-verified

777}
778
779func TestRequestAccessTokenRejectsEmptyAppCredentials(t *testing.T) {
780 restoreOAuthCredentials(t)
781 setOAuthCredentials(tokenTeamManage, "")
782
783 origReadAuthorizationCode := readAuthorizationCode
784 origExchangeAuthorizationCode := exchangeAuthorizationCode
785 t.Cleanup(func() {
786 readAuthorizationCode = origReadAuthorizationCode
787 exchangeAuthorizationCode = origExchangeAuthorizationCode
788 })
789
790 readAppCredentials = func(tokType string) (appCredentials, error) {
791 return appCredentials{Key: " "}, nil
792 }
793 readAuthorizationCode = func() (string, error) {
794 t.Fatal("authorization code prompt should not run when app credentials are invalid")
795 return "", nil
796 }
797 exchangeAuthorizationCode = func(ctx context.Context, conf *oauth2.Config, code string, verifier string) (*oauth2.Token, error) {
798 t.Fatal("authorization exchange should not run when app credentials are invalid")
799 return nil, nil
800 }
801
802 if _, err := requestAccessToken(tokenTeamManage, ""); err == nil {
803 t.Fatal("expected empty app credentials to fail")
804 } else if got, want := jsonErrorCode(err), jsonErrorCodeAppKeyRequired; got != want {
805 t.Fatalf("jsonErrorCode = %q, want %q", got, want)
806 }
807}

Callers

nothing calls this directly

Calls 4

restoreOAuthCredentialsFunction · 0.85
setOAuthCredentialsFunction · 0.85
requestAccessTokenFunction · 0.85
jsonErrorCodeFunction · 0.85

Tested by

no test coverage detected