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

Function TestLoginPurgesRefreshableRecord

internal/config/refreshable_test.go:647–674  ·  view source on GitHub ↗

TestLoginPurgesRefreshableRecord is the inverse of TestLoginRefreshablePurgesNonExpiringLogin: logging in with a non-refreshable token must remove the user's refreshable record so the two kinds never coexist. The regression it guards (cli/cli#14451 review): a leftover refreshable record short-circui

(t *testing.T)

Source from the content-addressed store, hash-verified

645// guards (cli/cli#14451 review): a leftover refreshable record short-circuits activateUser, so the new token is never
646// copied into the host-level oauth_token slot and go-gh extensions can no longer read a token.
647func TestLoginPurgesRefreshableRecord(t *testing.T) {
648 authCfg := newTestAuthConfig(t)
649
650 // A prior expiring login stores a refreshable credential in the keyring.
651 credential := gh.Credential{Token: "access", RefreshToken: "refresh"}
652 _, err := authCfg.LoginRefreshable("github.com", "test-user", credential, "ssh", true)
653 require.NoError(t, err)
654
655 // Switching back to a non-refreshable token with insecure storage must purge the refreshable record.
656 _, err = authCfg.Login("github.com", "test-user", "plain-token", "ssh", false)
657 require.NoError(t, err)
658
659 // The refreshable record is gone from both storage forms.
660 _, err = refreshableFromKeyring("github.com", "test-user")
661 require.ErrorIs(t, err, errRefreshableNotFound)
662 requireNoKey(t, authCfg.cfg, refreshablePath("github.com", "test-user"))
663
664 // TokenForUser resolves the new non-refreshable token.
665 cred, err := authCfg.TokenForUser("github.com", "test-user")
666 require.NoError(t, err)
667 require.Equal(t, "plain-token", cred.Token)
668
669 // And it was copied into the host-level oauth_token slot that go-gh reads for extensions, which regressed before
670 // this fix because the stale refreshable record short-circuited activation.
671 hostToken, err := authCfg.cfg.Get([]string{hostsKey, "github.com", oauthTokenKey})
672 require.NoError(t, err)
673 require.Equal(t, "plain-token", hostToken)
674}
675
676// TestLoginFailsWhenOtherCredentialKindSurvivesPurge covers the purge post-condition checks: an OS keyring can report a
677// delete as successful while the secret remains, and the surviving credential would then outrank the new login. Login

Callers

nothing calls this directly

Calls 9

newTestAuthConfigFunction · 0.85
refreshableFromKeyringFunction · 0.85
refreshablePathFunction · 0.85
EqualMethod · 0.80
requireNoKeyFunction · 0.70
LoginRefreshableMethod · 0.65
LoginMethod · 0.65
TokenForUserMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected