MCPcopy Create free account
hub / github.com/cli/cli / TestLoginReloadsFreshConfigBeforeMutating

Function TestLoginReloadsFreshConfigBeforeMutating

internal/config/refreshable_test.go:619–642  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

617}
618
619func 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
644func TestLoginSucceedsWhenKeyringUnavailable(t *testing.T) {
645 // The refreshable-record purge is best effort against capability loss: an unavailable keyring must not fail an

Callers

nothing calls this directly

Calls 5

newTestAuthConfigFunction · 0.85
EqualMethod · 0.80
GetMethod · 0.65
LoginMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected