(t *testing.T)
| 788 | } |
| 789 | |
| 790 | func TestTokenPrioritizesActiveUserToken(t *testing.T) { |
| 791 | // Given a keyring where the active slot contains the token from a previous user |
| 792 | authCfg := newTestAuthConfig(t) |
| 793 | require.NoError(t, keyring.Set(keyringServiceName("github.com"), "", "test-token")) |
| 794 | require.NoError(t, keyring.Set(keyringServiceName("github.com"), "test-user1", "test-token")) |
| 795 | require.NoError(t, keyring.Set(keyringServiceName("github.com"), "test-user2", "test-token2")) |
| 796 | |
| 797 | // When no active user is set |
| 798 | authCfg.cfg.Remove([]string{hostsKey, "github.com", userKey}) |
| 799 | |
| 800 | // And get the token from the auth config |
| 801 | cred := authCfg.ActiveToken("github.com") |
| 802 | token, source := cred.Token, cred.Source |
| 803 | |
| 804 | // Then it returns the token from the keyring active slot |
| 805 | require.Equal(t, "keyring", source) |
| 806 | require.Equal(t, "test-token", token) |
| 807 | |
| 808 | // When we set the active user to test-user1 |
| 809 | authCfg.cfg.Set([]string{hostsKey, "github.com", userKey}, "test-user1") |
| 810 | |
| 811 | // And get the token from the auth config |
| 812 | cred = authCfg.ActiveToken("github.com") |
| 813 | token, source = cred.Token, cred.Source |
| 814 | |
| 815 | // Then it returns the token from the active user entry in the keyring |
| 816 | require.Equal(t, "keyring", source) |
| 817 | require.Equal(t, "test-token", token) |
| 818 | |
| 819 | // When we set the active user to test-user2 |
| 820 | authCfg.cfg.Set([]string{hostsKey, "github.com", userKey}, "test-user2") |
| 821 | |
| 822 | // And get the token from the auth config |
| 823 | cred = authCfg.ActiveToken("github.com") |
| 824 | token, source = cred.Token, cred.Source |
| 825 | |
| 826 | // Then it returns the token from the active user entry in the keyring |
| 827 | require.Equal(t, "keyring", source) |
| 828 | require.Equal(t, "test-token2", token) |
| 829 | } |
| 830 | |
| 831 | // TestActiveTokenPrefersPerUserConfigTokenOverUnkeyedKeyring pins an intentional behavior change introduced with the |
| 832 | // refreshable-credential groundwork. ActiveToken now resolves the active user through TokenForUser, which consults the |
nothing calls this directly
no test coverage detected