public async Task HostProvider_StoreCredentialAsync_EmptyCredential_DoesNotStoreCredential() { const string emptyUserName = ""; const string emptyPassword = ""; const string testCredentialKey = "git:test-cred-key"; var input = new InputArguments(new Dictionary <string, string> { ["username"] = emptyUserName, ["password"] = emptyPassword, }); var context = new TestCommandContext(); var provider = new TestHostProvider(context) { CredentialKey = testCredentialKey }; await((IHostProvider)provider).StoreCredentialAsync(input); Assert.Empty(context.CredentialStore); }
public async Task HostProvider_EraseCredentialAsync_DifferentHost_DoesNothing() { const string service2 = "https://example2.com"; const string service3 = "https://example3.com"; const string userName = "******"; var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "example1.com", }); var context = new TestCommandContext(); context.CredentialStore.Add(service2, userName, "keep-me"); context.CredentialStore.Add(service3, userName, "also-keep-me"); var provider = new TestHostProvider(context); await((IHostProvider)provider).EraseCredentialAsync(input); Assert.Equal(2, context.CredentialStore.Count); Assert.True(context.CredentialStore.Contains(service2, userName)); Assert.True(context.CredentialStore.Contains(service3, userName)); }
public async Task HostProvider_EraseCredentialAsync_InputUser_CredentialExists_UserMatch_ErasesCredential() { const string userName = "******"; const string password = "******"; // [SuppressMessage("Microsoft.Security", "CS001:SecretInline", Justification="Fake credential")] const string service = "https://example.com"; var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "example.com", ["username"] = userName, ["password"] = password, // [SuppressMessage("Microsoft.Security", "CS001:SecretInline", Justification="Fake credential")] }); var context = new TestCommandContext(); context.CredentialStore.Add(service, userName, password); var provider = new TestHostProvider(context); await((IHostProvider)provider).EraseCredentialAsync(input); Assert.Equal(0, context.CredentialStore.Count); Assert.False(context.CredentialStore.Contains(service, userName)); }
public async Task HostProvider_EraseCredentialAsync_NoInputUser_CredentialExists_ErasesOneCredential() { const string service = "https://example.com"; const string userName1 = "john.doe"; const string userName2 = "alice"; const string userName3 = "bob"; var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "example.com", }); var context = new TestCommandContext(); context.CredentialStore.Add(service, userName1, "letmein123"); context.CredentialStore.Add(service, userName2, "do-not-erase-me"); context.CredentialStore.Add(service, userName3, "here-forever"); var provider = new TestHostProvider(context); await((IHostProvider)provider).EraseCredentialAsync(input); Assert.Equal(2, context.CredentialStore.Count); }
public async Task HostProvider_StoreCredentialAsync_NonEmptyCredential_StoresCredential() { const string userName = "******"; const string password = "******"; // [SuppressMessage("Microsoft.Security", "CS001:SecretInline", Justification="Fake credential")] const string service = "https://example.com"; var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "example.com", ["username"] = userName, ["password"] = password, // [SuppressMessage("Microsoft.Security", "CS001:SecretInline", Justification="Fake credential")] }); var context = new TestCommandContext(); var provider = new TestHostProvider(context); await((IHostProvider)provider).StoreCredentialAsync(input); Assert.Equal(1, context.CredentialStore.Count); Assert.True(context.CredentialStore.TryGet(service, userName, out var storedCredential)); Assert.Equal(userName, storedCredential.Account); Assert.Equal(password, storedCredential.Password); }
public async Task HostProvider_EraseCredentialAsync_InputUser_CredentialExists_UserNotMatch_DoesNothing() { const string userName1 = "john.doe"; const string userName2 = "alice"; const string password = "******"; const string service = "https://example.com"; var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "example.com", ["username"] = userName1, ["password"] = password, }); var context = new TestCommandContext(); context.CredentialStore.Add(service, userName2, password); var provider = new TestHostProvider(context); await((IHostProvider)provider).EraseCredentialAsync(input); Assert.Equal(1, context.CredentialStore.Count); Assert.True(context.CredentialStore.Contains(service, userName2)); }
public async Task HostProvider_StoreCredentialAsync_NonEmptyCredential_StoresCredential() { const string testUserName = "******"; const string testPassword = "******"; const string testCredentialKey = "git:test-cred-key"; var input = new InputArguments(new Dictionary <string, string> { ["username"] = testUserName, ["password"] = testPassword, }); var context = new TestCommandContext(); var provider = new TestHostProvider(context) { CredentialKey = testCredentialKey }; await((IHostProvider)provider).StoreCredentialAsync(input); Assert.Single(context.CredentialStore); Assert.True(context.CredentialStore.TryGetValue(testCredentialKey, out ICredential storedCredential)); Assert.Equal(testUserName, storedCredential.UserName); Assert.Equal(testPassword, storedCredential.Password); }