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

Function TestRequestAccessTokenUsesPKCEOfflineAuthURL

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

Source from the content-addressed store, hash-verified

666}
667
668func TestRequestAccessTokenUsesPKCEOfflineAuthURL(t *testing.T) {
669 mockOAuthAppCredentials(t)
670
671 origReadAuthorizationCode := readAuthorizationCode
672 origExchangeAuthorizationCode := exchangeAuthorizationCode
673 t.Cleanup(func() {
674 readAuthorizationCode = origReadAuthorizationCode
675 exchangeAuthorizationCode = origExchangeAuthorizationCode
676 })
677
678 const verifier = "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"
679 const state = "test-oauth-state"
680 generateOAuthVerifier = func() string {
681 return verifier
682 }
683 generateOAuthState = func() string {
684 return state
685 }
686 readAuthorizationCode = func() (string, error) {
687 return "auth-code", nil
688 }
689 exchangeAuthorizationCode = func(ctx context.Context, conf *oauth2.Config, code string, gotVerifier string) (*oauth2.Token, error) {
690 if gotVerifier != verifier {
691 t.Fatalf("expected verifier %q, got %q", verifier, gotVerifier)
692 }
693 return &oauth2.Token{
694 AccessToken: "access-token",
695 RefreshToken: "refresh-token",
696 TokenType: "Bearer",
697 Expiry: time.Now().Add(time.Hour),
698 }, nil
699 }
700
701 var err error
702 out := captureStdout(t, func() {
703 _, err = requestAccessToken(tokenPersonal, "")
704 })
705 if err != nil {
706 t.Fatal(err)
707 }
708 if !strings.Contains(out, "token_access_type=offline") {
709 t.Fatalf("expected offline token access type in auth URL, got %q", out)
710 }
711 if !strings.Contains(out, "state=test-oauth-state") {
712 t.Fatalf("expected generated OAuth state in auth URL, got %q", out)
713 }
714 if !strings.Contains(out, "code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM") {
715 t.Fatalf("expected PKCE code challenge in auth URL, got %q", out)
716 }
717 if !strings.Contains(out, "code_challenge_method=S256") {
718 t.Fatalf("expected PKCE S256 method in auth URL, got %q", out)
719 }
720}
721
722func TestReadAppCredentialsReadsVisibleKey(t *testing.T) {
723 restoreOAuthCredentials(t)

Callers

nothing calls this directly

Calls 3

mockOAuthAppCredentialsFunction · 0.85
captureStdoutFunction · 0.85
requestAccessTokenFunction · 0.85

Tested by

no test coverage detected