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

Function TestTokenPrioritizesActiveUserToken

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

Source from the content-addressed store, hash-verified

771}
772
773func TestTokenPrioritizesActiveUserToken(t *testing.T) {
774 // Given a keyring where the active slot contains the token from a previous user
775 authCfg := newTestAuthConfig(t)
776 require.NoError(t, keyring.Set(keyringServiceName("github.com"), "", "test-token"))
777 require.NoError(t, keyring.Set(keyringServiceName("github.com"), "test-user1", "test-token"))
778 require.NoError(t, keyring.Set(keyringServiceName("github.com"), "test-user2", "test-token2"))
779
780 // When no active user is set
781 authCfg.cfg.Remove([]string{hostsKey, "github.com", userKey})
782
783 // And get the token from the auth config
784 token, source := authCfg.ActiveToken("github.com")
785
786 // Then it returns the token from the keyring active slot
787 require.Equal(t, "keyring", source)
788 require.Equal(t, "test-token", token)
789
790 // When we set the active user to test-user1
791 authCfg.cfg.Set([]string{hostsKey, "github.com", userKey}, "test-user1")
792
793 // And get the token from the auth config
794 token, source = authCfg.ActiveToken("github.com")
795
796 // Then it returns the token from the active user entry in the keyring
797 require.Equal(t, "keyring", source)
798 require.Equal(t, "test-token", token)
799
800 // When we set the active user to test-user2
801 authCfg.cfg.Set([]string{hostsKey, "github.com", userKey}, "test-user2")
802
803 // And get the token from the auth config
804 token, source = authCfg.ActiveToken("github.com")
805
806 // Then it returns the token from the active user entry in the keyring
807 require.Equal(t, "keyring", source)
808 require.Equal(t, "test-token2", token)
809}
810
811func TestTokenWithActiveUserNotInKeyringFallsBackToBlank(t *testing.T) {
812 // Given a keyring that contains a token for a host

Callers

nothing calls this directly

Calls 7

SetFunction · 0.92
newTestAuthConfigFunction · 0.85
EqualMethod · 0.80
keyringServiceNameFunction · 0.70
RemoveMethod · 0.65
ActiveTokenMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected