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)
| 806 | // guards (cli/cli#14451 review): a leftover refreshable record short-circuits activateUser, so the new token is never |
| 807 | // copied into the host-level oauth_token slot and go-gh extensions can no longer read a token. |
| 808 | func TestLoginPurgesRefreshableRecord(t *testing.T) { |
| 809 | authCfg := newTestAuthConfig(t) |
| 810 | |
| 811 | // A prior expiring login stores a refreshable credential in the keyring. |
| 812 | credential := gh.Credential{Token: "access", RefreshToken: "refresh"} |
| 813 | _, err := authCfg.LoginRefreshable("github.com", "test-user", credential, "ssh", true) |
| 814 | require.NoError(t, err) |
| 815 | |
| 816 | // Switching back to a non-refreshable token with insecure storage must purge the refreshable record. |
| 817 | _, err = authCfg.Login("github.com", "test-user", "plain-token", "ssh", false) |
| 818 | require.NoError(t, err) |
| 819 | |
| 820 | // The refreshable record is gone from both storage forms. |
| 821 | _, err = refreshableFromKeyring("github.com", "test-user") |
| 822 | require.ErrorIs(t, err, errRefreshableNotFound) |
| 823 | requireNoKey(t, authCfg.cfg, refreshablePath("github.com", "test-user")) |
| 824 | |
| 825 | // TokenForUser resolves the new non-refreshable token. |
| 826 | cred, err := authCfg.TokenForUser("github.com", "test-user") |
| 827 | require.NoError(t, err) |
| 828 | require.Equal(t, "plain-token", cred.Token) |
| 829 | |
| 830 | // And it was copied into the host-level oauth_token slot that go-gh reads for extensions, which regressed before |
| 831 | // this fix because the stale refreshable record short-circuited activation. |
| 832 | hostToken, err := authCfg.cfg.Get([]string{hostsKey, "github.com", oauthTokenKey}) |
| 833 | require.NoError(t, err) |
| 834 | require.Equal(t, "plain-token", hostToken) |
| 835 | } |
| 836 | |
| 837 | // TestLoginFailsWhenOtherCredentialKindSurvivesPurge covers the purge post-condition checks: an OS keyring can report a |
| 838 | // delete as successful while the secret remains, and the surviving credential would then outrank the new login. Login |
nothing calls this directly
no test coverage detected