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

Function mockAuthorization

cmd/auth_test.go:189–218  ·  view source on GitHub ↗
(t *testing.T, code string, accessToken string)

Source from the content-addressed store, hash-verified

187}
188
189func mockAuthorization(t *testing.T, code string, accessToken string) {
190 t.Helper()
191
192 mockOAuthAppCredentials(t)
193
194 origReadAuthorizationCode := readAuthorizationCode
195 origExchangeAuthorizationCode := exchangeAuthorizationCode
196 t.Cleanup(func() {
197 readAuthorizationCode = origReadAuthorizationCode
198 exchangeAuthorizationCode = origExchangeAuthorizationCode
199 })
200
201 readAuthorizationCode = func() (string, error) {
202 return code, nil
203 }
204 exchangeAuthorizationCode = func(ctx context.Context, conf *oauth2.Config, gotCode string, verifier string) (*oauth2.Token, error) {
205 if gotCode != code {
206 t.Fatalf("expected authorization code %q, got %q", code, gotCode)
207 }
208 if verifier == "" {
209 t.Fatal("expected PKCE verifier")
210 }
211 return &oauth2.Token{
212 AccessToken: accessToken,
213 RefreshToken: "refresh-token",
214 TokenType: "Bearer",
215 Expiry: time.Now().Add(time.Hour),
216 }, nil
217 }
218}
219
220func TestGetAccessTokenUsesExistingToken(t *testing.T) {
221 authFile := filepath.Join(t.TempDir(), "auth.json")

Calls 1

mockOAuthAppCredentialsFunction · 0.85

Tested by

no test coverage detected