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

Function TestGetAccessTokenUsesExistingToken

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

Source from the content-addressed store, hash-verified

218}
219
220func TestGetAccessTokenUsesExistingToken(t *testing.T) {
221 authFile := filepath.Join(t.TempDir(), "auth.json")
222 if err := os.WriteFile(authFile, []byte(`{"":{"personal":"existing-token"}}`), 0600); err != nil {
223 t.Fatal(err)
224 }
225 t.Setenv(envAuthFile, authFile)
226
227 origReadAuthorizationCode := readAuthorizationCode
228 origExchangeAuthorizationCode := exchangeAuthorizationCode
229 t.Cleanup(func() {
230 readAuthorizationCode = origReadAuthorizationCode
231 exchangeAuthorizationCode = origExchangeAuthorizationCode
232 })
233 readAuthorizationCode = func() (string, error) {
234 t.Fatal("authorization prompt should not be used for existing token")
235 return "", nil
236 }
237 exchangeAuthorizationCode = func(ctx context.Context, conf *oauth2.Config, code string, verifier string) (*oauth2.Token, error) {
238 t.Fatal("authorization exchange should not be used for existing token")
239 return nil, nil
240 }
241
242 token, filePath, err := getAccessToken(tokenPersonal, "", false)
243 if err != nil {
244 t.Fatal(err)
245 }
246 if token != "existing-token" {
247 t.Fatalf("expected existing token, got %q", token)
248 }
249 if filePath != authFile {
250 t.Fatalf("expected auth file %q, got %q", authFile, filePath)
251 }
252}
253
254func TestGetAccessTokenForceRefreshesToken(t *testing.T) {
255 authFile := filepath.Join(t.TempDir(), "auth.json")

Callers

nothing calls this directly

Calls 1

getAccessTokenFunction · 0.85

Tested by

no test coverage detected