Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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);
        }