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

Function TestGetAccessTokenForceRefreshesToken

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

Source from the content-addressed store, hash-verified

252}
253
254func TestGetAccessTokenForceRefreshesToken(t *testing.T) {
255 authFile := filepath.Join(t.TempDir(), "auth.json")
256 if err := os.WriteFile(authFile, []byte(`{"":{"personal":"old-token"}}`), 0600); err != nil {
257 t.Fatal(err)
258 }
259 t.Setenv(envAuthFile, authFile)
260 mockAuthorization(t, "auth-code", "new-token")
261
262 token, filePath, err := getAccessToken(tokenPersonal, "", true)
263 if err != nil {
264 t.Fatal(err)
265 }
266 if token != "new-token" {
267 t.Fatalf("expected new token, got %q", token)
268 }
269 if filePath != authFile {
270 t.Fatalf("expected auth file %q, got %q", authFile, filePath)
271 }
272
273 tokens, err := readTokens(authFile)
274 if err != nil {
275 t.Fatal(err)
276 }
277 if tokens[""][tokenPersonal].AccessToken != "new-token" {
278 t.Fatalf("expected saved token to be refreshed, got %q", tokens[""][tokenPersonal].AccessToken)
279 }
280 if tokens[""][tokenPersonal].RefreshToken == "" {
281 t.Fatal("expected saved token to include a refresh token")
282 }
283}
284
285func TestGetAccessTokenRefreshesExpiredCredential(t *testing.T) {
286 expired := time.Now().Add(-time.Hour).UTC()

Callers

nothing calls this directly

Calls 3

mockAuthorizationFunction · 0.85
getAccessTokenFunction · 0.85
readTokensFunction · 0.85

Tested by

no test coverage detected