(t *testing.T)
| 617 | } |
| 618 | |
| 619 | func TestLoginReloadsFreshConfigBeforeMutating(t *testing.T) { |
| 620 | // A concurrent refresh can persist a rotated credential while login is in flight. Because login reloads the |
| 621 | // freshest config under the lock before it stores the new credential and purges the refreshable record, it sees |
| 622 | // and supersedes whatever the refresh just wrote. Pin that reload happens, and that it happens before the |
| 623 | // mutation, so login wins the race. Without the wrap Login never reloads and this fails. |
| 624 | authCfg := newTestAuthConfig(t) |
| 625 | |
| 626 | reloaded := false |
| 627 | authCfg.reloadConfig = func() error { |
| 628 | reloaded = true |
| 629 | // Reload runs under the lock before any mutation, so the user's token slot is still empty at this point. |
| 630 | _, err := authCfg.cfg.Get([]string{hostsKey, "github.com", usersKey, "test-user", oauthTokenKey}) |
| 631 | require.Error(t, err, "reload must run before login stores the credential") |
| 632 | return nil |
| 633 | } |
| 634 | |
| 635 | _, err := authCfg.Login("github.com", "test-user", "gho_token", "https", false) |
| 636 | require.NoError(t, err) |
| 637 | require.True(t, reloaded, "login must reload the config under the refresh lock") |
| 638 | |
| 639 | token, err := authCfg.cfg.Get([]string{hostsKey, "github.com", usersKey, "test-user", oauthTokenKey}) |
| 640 | require.NoError(t, err) |
| 641 | require.Equal(t, "gho_token", token) |
| 642 | } |
| 643 | |
| 644 | func TestLoginSucceedsWhenKeyringUnavailable(t *testing.T) { |
| 645 | // 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