public async Task GenericHostProvider_CreateCredentialAsync_LegacyAuthorityBasic_ReturnsBasicCredentialNoWiaCheck() { var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "example.com", }); const string testUserName = "******"; const string testPassword = "******"; var basicCredential = new GitCredential(testUserName, testPassword); var context = new TestCommandContext { Settings = { LegacyAuthorityOverride = "basic" } }; var basicAuthMock = new Mock <IBasicAuthentication>(); basicAuthMock.Setup(x => x.GetCredentials(It.IsAny <string>(), It.IsAny <string>())) .Returns(basicCredential) .Verifiable(); var wiaAuthMock = new Mock <IWindowsIntegratedAuthentication>(); var provider = new GenericHostProvider(context, basicAuthMock.Object, wiaAuthMock.Object); ICredential credential = await provider.GenerateCredentialAsync(input); Assert.NotNull(credential); Assert.Equal(testUserName, credential.Account); Assert.Equal(testPassword, credential.Password); wiaAuthMock.Verify(x => x.GetIsSupportedAsync(It.IsAny <Uri>()), Times.Never); basicAuthMock.Verify(x => x.GetCredentials(It.IsAny <string>(), It.IsAny <string>()), Times.Once); }
private static async Task TestCreateCredentialAsync_ReturnsEmptyCredential(bool wiaSupported) { var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "example.com", }); var context = new TestCommandContext(); var basicAuthMock = new Mock <IBasicAuthentication>(); basicAuthMock.Setup(x => x.GetCredentials(It.IsAny <string>(), It.IsAny <string>())) .Verifiable(); var wiaAuthMock = new Mock <IWindowsIntegratedAuthentication>(); wiaAuthMock.Setup(x => x.GetIsSupportedAsync(It.IsAny <Uri>())) .ReturnsAsync(wiaSupported); var provider = new GenericHostProvider(context, basicAuthMock.Object, wiaAuthMock.Object); ICredential credential = await provider.GenerateCredentialAsync(input); Assert.NotNull(credential); Assert.Equal(string.Empty, credential.Account); Assert.Equal(string.Empty, credential.Password); basicAuthMock.Verify(x => x.GetCredentials(It.IsAny <string>(), It.IsAny <string>()), Times.Never); }
public void GenericHostProvider_IsSupported(string protocol, bool expected) { var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = protocol, ["host"] = "example.com", ["path"] = "foo/bar", }); var provider = new GenericHostProvider(new TestCommandContext()); Assert.Equal(expected, provider.IsSupported(input)); }
public void GenericHostProvider_GetCredentialServiceUrl_ReturnsCorrectKey() { const string expectedService = "https://example.com/foo/bar"; var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "example.com", ["path"] = "foo/bar", ["username"] = "******", }); var provider = new GenericHostProvider(new TestCommandContext()); string actualService = provider.GetServiceName(input); Assert.Equal(expectedService, actualService); }