(t *testing.T)
| 770 | } |
| 771 | |
| 772 | func 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 | |
| 810 | func TestTokenWithActiveUserNotInKeyringFallsBackToBlank(t *testing.T) { |
| 811 | // Given a keyring that contains a token for a host |
nothing calls this directly
no test coverage detected