(t *testing.T)
| 456 | } |
| 457 | |
| 458 | func TestLoginReloadsFreshConfigBeforeMutating(t *testing.T) { |
| 459 | // A concurrent refresh can persist a rotated credential while login is in flight. Because login reloads the |
| 460 | // freshest config under the lock before it stores the new credential and purges the refreshable record, it sees |
| 461 | // and supersedes whatever the refresh just wrote. Pin that reload happens, and that it happens before the |
| 462 | // mutation, so login wins the race. Without the wrap Login never reloads and this fails. |
| 463 | authCfg := newTestAuthConfig(t) |
| 464 | |
| 465 | reloaded := false |
| 466 | authCfg.reloadConfig = func() error { |
| 467 | reloaded = true |
| 468 | // Reload runs under the lock before any mutation, so the user's token slot is still empty at this point. |
| 469 | _, err := authCfg.cfg.Get([]string{hostsKey, "github.com", usersKey, "test-user", oauthTokenKey}) |
| 470 | require.Error(t, err, "reload must run before login stores the credential") |
| 471 | return nil |
| 472 | } |
| 473 | |
| 474 | _, err := authCfg.Login("github.com", "test-user", "gho_token", "https", false) |
| 475 | require.NoError(t, err) |
| 476 | require.True(t, reloaded, "login must reload the config under the refresh lock") |
| 477 | |
| 478 | token, err := authCfg.cfg.Get([]string{hostsKey, "github.com", usersKey, "test-user", oauthTokenKey}) |
| 479 | require.NoError(t, err) |
| 480 | require.Equal(t, "gho_token", token) |
| 481 | } |
| 482 | |
| 483 | func TestLoginSucceedsWhenKeyringUnavailable(t *testing.T) { |
| 484 | // The refreshable-record purge is best effort against capability loss: an unavailable keyring must not fail an |
nothing calls this directly
no test coverage detected