(t *testing.T)
| 342 | } |
| 343 | |
| 344 | func TestGetAccessTokenRefreshFailureLeavesAuthFileUnchanged(t *testing.T) { |
| 345 | expired := time.Now().Add(-time.Hour).UTC() |
| 346 | authFile := filepath.Join(t.TempDir(), "auth.json") |
| 347 | tokens := TokenMap{ |
| 348 | "": { |
| 349 | tokenPersonal: { |
| 350 | AccessToken: "old-access", |
| 351 | RefreshToken: "old-refresh", |
| 352 | TokenType: "Bearer", |
| 353 | Expiry: &expired, |
| 354 | AppKey: "stored-app-key", |
| 355 | }, |
| 356 | }, |
| 357 | } |
| 358 | if err := writeTokens(authFile, tokens); err != nil { |
| 359 | t.Fatal(err) |
| 360 | } |
| 361 | before, err := os.ReadFile(authFile) |
| 362 | if err != nil { |
| 363 | t.Fatal(err) |
| 364 | } |
| 365 | t.Setenv(envAuthFile, authFile) |
| 366 | |
| 367 | restoreOAuthCredentials(t) |
| 368 | refreshOAuthToken = func(ctx context.Context, conf *oauth2.Config, token *oauth2.Token) (*oauth2.Token, error) { |
| 369 | return nil, errors.New("refresh failed") |
| 370 | } |
| 371 | |
| 372 | _, _, err = getAccessToken(tokenPersonal, "", false) |
| 373 | if err == nil { |
| 374 | t.Fatal("expected refresh failure") |
| 375 | } |
| 376 | if got, want := jsonErrorCode(err), jsonErrorCodeAuthRefreshFailed; got != want { |
| 377 | t.Fatalf("jsonErrorCode = %q, want %q", got, want) |
| 378 | } |
| 379 | if !strings.Contains(err.Error(), "dbxcli login") { |
| 380 | t.Fatalf("expected login hint, got %q", err) |
| 381 | } |
| 382 | |
| 383 | after, err := os.ReadFile(authFile) |
| 384 | if err != nil { |
| 385 | t.Fatal(err) |
| 386 | } |
| 387 | if string(after) != string(before) { |
| 388 | t.Fatalf("expected auth file to remain unchanged\nbefore: %s\nafter: %s", before, after) |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | func TestGetAccessTokenRefreshWithoutAppKeyReturnsAppKeyRequired(t *testing.T) { |
| 393 | expired := time.Now().Add(-time.Hour).UTC() |
nothing calls this directly
no test coverage detected