(t *testing.T)
| 326 | } |
| 327 | |
| 328 | func TestLogoutRemovesAllUserCredentialRecords(t *testing.T) { |
| 329 | // This populates every credential representation the write paths can produce for the user at once: a non-expiring |
| 330 | // token and a refreshable credential, in both the keyring and the config file. The non-expiring token also has a |
| 331 | // host active ("") slot, which refreshable credentials do not use. That combined state is not realistic - the |
| 332 | // write paths keep the storage forms mutually exclusive - but populating it lets the test prove that Logout leaves |
| 333 | // nothing behind for the user on the host. |
| 334 | authCfg := newTestAuthConfig(t) |
| 335 | |
| 336 | credential := gh.Credential{Token: "access", RefreshToken: "refresh"} |
| 337 | |
| 338 | // Non-expiring tokens in the keyring (per-user and host active slot). |
| 339 | require.NoError(t, keyring.Set(keyringServiceName("github.com"), "test-user", "keyring-user-token")) |
| 340 | require.NoError(t, keyring.Set(keyringServiceName("github.com"), "", "keyring-active-token")) |
| 341 | |
| 342 | // Refreshable credential in the keyring (per-user slot only). |
| 343 | setRefreshableKeyring(t, "github.com", "test-user", credential) |
| 344 | |
| 345 | // Non-expiring tokens in the config (per-user and host active slot). |
| 346 | authCfg.cfg.Set([]string{hostsKey, "github.com", usersKey, "test-user", oauthTokenKey}, "config-user-token") |
| 347 | authCfg.cfg.Set([]string{hostsKey, "github.com", oauthTokenKey}, "config-active-token") |
| 348 | |
| 349 | // Refreshable credential in the config (per-user slot only). |
| 350 | setRefreshableConfigField(t, authCfg, "github.com", "test-user", "access_token", "access") |
| 351 | setRefreshableConfigField(t, authCfg, "github.com", "test-user", "refresh_token", "refresh") |
| 352 | |
| 353 | authCfg.cfg.Set([]string{hostsKey, "github.com", userKey}, "test-user") |
| 354 | |
| 355 | require.NoError(t, authCfg.Logout("github.com", "test-user")) |
| 356 | |
| 357 | // Every non-expiring keyring record for the host, per-user and host active, is gone. |
| 358 | for _, user := range []string{"test-user", ""} { |
| 359 | _, err := keyring.Get(keyringServiceName("github.com"), user) |
| 360 | require.Error(t, err) |
| 361 | } |
| 362 | // The per-user refreshable keyring record is gone. |
| 363 | _, err := keyring.Get(refreshableServiceName("github.com"), "test-user") |
| 364 | require.Error(t, err) |
| 365 | |
| 366 | // The whole host entry, and therefore every config-stored credential, is gone. |
| 367 | _, err = authCfg.cfg.Get([]string{hostsKey, "github.com"}) |
| 368 | require.Error(t, err) |
| 369 | require.Empty(t, authCfg.UsersForHost("github.com")) |
| 370 | } |
| 371 | |
| 372 | func TestLogoutAcquiresRefreshLock(t *testing.T) { |
| 373 | // Logout must run under the same lock the refresh path uses so it wins any race with an in-flight refresh. Pin |
nothing calls this directly
no test coverage detected