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

Function TestLogoutOfActiveUserSwitchesUserIfPossible

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

Source from the content-addressed store, hash-verified

383}
384
385func TestLogoutOfActiveUserSwitchesUserIfPossible(t *testing.T) {
386 // Given we have two accounts logged into a host
387 authCfg := newTestAuthConfig(t)
388 _, err := authCfg.Login("github.com", "inactive-user", "test-token-1", "ssh", true)
389 require.NoError(t, err)
390
391 _, err = authCfg.Login("github.com", "active-user", "test-token-2", "https", true)
392 require.NoError(t, err)
393
394 // When we logout of the active user
395 err = authCfg.Logout("github.com", "active-user")
396
397 // Then we return success and the inactive user is now active
398 require.NoError(t, err)
399 activeUser, err := authCfg.ActiveUser("github.com")
400 require.NoError(t, err)
401 require.Equal(t, "inactive-user", activeUser)
402
403 token, err := authCfg.TokenFromKeyring("github.com")
404 require.NoError(t, err)
405 require.Equal(t, "test-token-1", token)
406
407 usersForHost := authCfg.UsersForHost("github.com")
408 require.NotContains(t, "active-user", usersForHost)
409}
410
411func TestLogoutOfInactiveUserDoesNotSwitchUser(t *testing.T) {
412 // 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