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

Function TestLogoutOfActiveUserSwitchesUserIfPossible

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

Source from the content-addressed store, hash-verified

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