MCPcopy Index your code
hub / github.com/cli/cli / TestTokenPrioritizesActiveUserToken

Function TestTokenPrioritizesActiveUserToken

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

Source from the content-addressed store, hash-verified

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