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

Function TestLogoutOfActiveUserSwitchesUserIfPossible

internal/config/auth_config_test.go:400–424  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

398}
399
400func TestLogoutOfActiveUserSwitchesUserIfPossible(t *testing.T) {
401 // Given we have two accounts logged into a host
402 authCfg := newTestAuthConfig(t)
403 _, err := authCfg.Login("github.com", "inactive-user", "test-token-1", "ssh", true)
404 require.NoError(t, err)
405
406 _, err = authCfg.Login("github.com", "active-user", "test-token-2", "https", true)
407 require.NoError(t, err)
408
409 // When we logout of the active user
410 err = authCfg.Logout("github.com", "active-user")
411
412 // Then we return success and the inactive user is now active
413 require.NoError(t, err)
414 activeUser, err := authCfg.ActiveUser("github.com")
415 require.NoError(t, err)
416 require.Equal(t, "inactive-user", activeUser)
417
418 token, err := authCfg.TokenFromKeyring("github.com")
419 require.NoError(t, err)
420 require.Equal(t, "test-token-1", token)
421
422 usersForHost := authCfg.UsersForHost("github.com")
423 require.NotContains(t, "active-user", usersForHost)
424}
425
426func TestLogoutOfInactiveUserDoesNotSwitchUser(t *testing.T) {
427 // Given we have two accounts logged into a host

Callers

nothing calls this directly

Calls 7

newTestAuthConfigFunction · 0.85
EqualMethod · 0.80
LoginMethod · 0.65
LogoutMethod · 0.65
ActiveUserMethod · 0.65
TokenFromKeyringMethod · 0.65
UsersForHostMethod · 0.65

Tested by

no test coverage detected