public void WhenArgumentsIncomplete_ThenAuthorizeKeyAsyncThrowsArgumentException() { var service = new OsLoginService(new Mock <IOsLoginAdapter>().Object); AssertEx.ThrowsAggregateException <ArgumentException>(() => service.AuthorizeKeyAsync( "", OsLoginSystemType.Linux, new Mock <ISshKey>().Object, TimeSpan.FromDays(1), CancellationToken.None).Wait()); AssertEx.ThrowsAggregateException <ArgumentException>(() => service.AuthorizeKeyAsync( null, OsLoginSystemType.Linux, new Mock <ISshKey>().Object, TimeSpan.FromDays(1), CancellationToken.None).Wait()); AssertEx.ThrowsAggregateException <ArgumentNullException>(() => service.AuthorizeKeyAsync( "project-1", OsLoginSystemType.Linux, null, TimeSpan.FromDays(1), CancellationToken.None).Wait()); }
public void WhenValidityIsZeroOrNegative_ThenAuthorizeKeyAsyncThrowsArgumentException() { var service = new OsLoginService(new Mock <IOsLoginAdapter>().Object); AssertEx.ThrowsAggregateException <ArgumentException>(() => service.AuthorizeKeyAsync( "project-1", OsLoginSystemType.Linux, new Mock <ISshKey>().Object, TimeSpan.FromDays(-1), CancellationToken.None).Wait()); AssertEx.ThrowsAggregateException <ArgumentException>(() => service.AuthorizeKeyAsync( "project-1", OsLoginSystemType.Linux, new Mock <ISshKey>().Object, TimeSpan.FromSeconds(0), CancellationToken.None).Wait()); }
public async Task WhenAdapterReturnsMultipleAccounts_ThenAuthorizeKeyAsyncSelectsPrimary() { var adapter = new Mock <IOsLoginAdapter>(); adapter .Setup(a => a.ImportSshPublicKeyAsync( It.IsAny <string>(), It.IsAny <ISshKey>(), It.IsAny <TimeSpan>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new LoginProfile() { PosixAccounts = new [] { new PosixAccount() { AccountId = "1", Primary = false, OperatingSystemType = "DOS", Username = "******" }, new PosixAccount() { AccountId = "2", Primary = true, OperatingSystemType = "DOS", Username = "******" }, new PosixAccount() { AccountId = "3", Primary = true, OperatingSystemType = "LINUX", Username = "******" } } }); var service = new OsLoginService(adapter.Object); var key = await service.AuthorizeKeyAsync( "project-1", OsLoginSystemType.Linux, new Mock <ISshKey>().Object, TimeSpan.FromDays(1), CancellationToken.None); Assert.AreEqual("joe3", key.Username); Assert.AreEqual(AuthorizeKeyMethods.Oslogin, key.AuthorizationMethod); }
public void WhenAdapterReturnsNoAccount_ThenAuthorizeKeyAsyncThrowsOsLoginSshKeyImportFailedException() { var adapter = new Mock <IOsLoginAdapter>(); adapter .Setup(a => a.ImportSshPublicKeyAsync( It.IsAny <string>(), It.IsAny <ISshKey>(), It.IsAny <TimeSpan>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new LoginProfile()); var service = new OsLoginService(adapter.Object); AssertEx.ThrowsAggregateException <OsLoginSshKeyImportFailedException>( () => service.AuthorizeKeyAsync( "project-1", OsLoginSystemType.Linux, new Mock <ISshKey>().Object, TimeSpan.FromDays(1), CancellationToken.None).Wait()); }