public async Task ExecuteCommand_SensitiveParameterNotFoundInCommandText_ExceptionThrown() { //Arrange var fakeClientDecorator = Substitute.For <ISshClientDecorator>(); var fakeLogger = Substitute.For <ILogger>(); var client = new SshClient( fakeClientDecorator, fakeLogger); //Act var exception = await Assert.ThrowsExceptionAsync <CommandSanitizationException>(async() => await client.ExecuteCommandAsync( SshRetryPolicy.AllowRetries, "some-text", new Dictionary <string, string>() { { "foo", "bar" } })); //Assert Assert.IsNotNull(exception); }
public async Task ExecuteCommand_SensitiveDataSensitivityAndFailedCommand_SensitiveDataNotIncludedInThrownException() { //Arrange var fakeClientDecorator = Substitute.For <ISshClientDecorator>(); var fakeLogger = Substitute.For <ILogger>(); var client = new SshClient( fakeClientDecorator, fakeLogger); fakeClientDecorator .ExecuteCommandAsync("'some-text'") .Returns( Task.FromResult(new SshCommandResult() { ExitCode = 1, Text = "some-result" })); //Act var exception = await Assert.ThrowsExceptionAsync <SshCommandExecutionException>(async() => await client.ExecuteCommandAsync( SshRetryPolicy.ProhibitRetries, "@alias", new Dictionary <string, string>() { { "alias", "some-text" } })); //Assert Assert.IsNotNull(exception); Assert.AreEqual("@alias", exception.CommandText); Assert.AreEqual(1, exception.Result.ExitCode); }
public async Task ExecuteCommand_SensitiveDataSensitivityAndSuccessfulCommand_HighwayTest() { //Arrange var fakeClientDecorator = Substitute.For <ISshClientDecorator>(); var fakeLogger = Substitute.For <ILogger>(); var client = new SshClient( fakeClientDecorator, fakeLogger); fakeClientDecorator .ExecuteCommandAsync("'some-text'") .Returns( Task.FromResult(new SshCommandResult() { ExitCode = 0, Text = "some-result" })); //Act var result = await client.ExecuteCommandAsync( SshRetryPolicy.ProhibitRetries, "@alias", new Dictionary <string, string>() { { "alias", "some-text" } }); //Assert Assert.AreEqual("some-result", result); }
public async Task ExecuteCommand_ProhibitRetriesAndFailedCommand_ThrowsException() { //Arrange var fakeClientDecorator = Substitute.For <ISshClientDecorator>(); var fakeLogger = Substitute.For <ILogger>(); var client = new SshClient( fakeClientDecorator, fakeLogger); fakeClientDecorator .ExecuteCommandAsync("some-text") .Returns( Task.FromResult(new SshCommandResult() { ExitCode = 1 })); //Act var exception = await Assert.ThrowsExceptionAsync <SshCommandExecutionException>(async() => await client.ExecuteCommandAsync( SshRetryPolicy.ProhibitRetries, "some-text")); //Assert Assert.IsNotNull(exception); await fakeClientDecorator .Received(1) .ExecuteCommandAsync( Arg.Any <string>()); }
public async Task ExecuteCommand_ProhibitRetriesAndSuccessfulCommand_ReturnsInstantly() { //Arrange var fakeClientDecorator = Substitute.For <ISshClientDecorator>(); var fakeLogger = Substitute.For <ILogger>(); var client = new SshClient( fakeClientDecorator, fakeLogger); fakeClientDecorator .ExecuteCommandAsync("some-text") .Returns( Task.FromResult(new SshCommandResult())); //Act await client.ExecuteCommandAsync( SshRetryPolicy.ProhibitRetries, "some-text"); //Assert await fakeClientDecorator .Received(1) .ExecuteCommandAsync( Arg.Any <string>()); }
public async Task ExecuteCommand_AllowRetriesAndFailedCommand_RetriesAgain() { //Arrange var fakeClientDecorator = Substitute.For <ISshClientDecorator>(); var fakeLogger = Substitute.For <ILogger>(); var client = new SshClient( fakeClientDecorator, fakeLogger); fakeClientDecorator .ExecuteCommandAsync("some-text") .Returns( Task.FromResult(new SshCommandResult() { ExitCode = 1 }), Task.FromResult(new SshCommandResult())); //Act await client.ExecuteCommandAsync( SshRetryPolicy.AllowRetries, "some-text"); //Assert await fakeClientDecorator .Received(2) .ExecuteCommandAsync( Arg.Any <string>()); }
public async Task SanitizeBashCommand_DummyCommandGiven_InsertsEscapeCharactersEverywhere() { //Arrange const string input = "I'm a s@fe $tring which ends in newline\n"; //Act var output = SshClient.Sanitize(input); //Assert Assert.AreEqual("'I'\\''m a s@fe $tring which ends in newline\n'", output); }
public async Task Dispose_ClientDecoratorGiven_DisposesClientDecorator() { //Arrange var fakeClientDecorator = Substitute.For <ISshClientDecorator>(); var fakeLogger = Substitute.For <ILogger>(); var client = new SshClient( fakeClientDecorator, fakeLogger); //Act client.Dispose(); //Assert fakeClientDecorator .Received(1) .Dispose(); }
public async Task Connect_SuccessfulConnection_ReturnsInstantly() { //Arrange var fakeClientDecorator = Substitute.For <ISshClientDecorator>(); var fakeLogger = Substitute.For <ILogger>(); var client = new SshClient( fakeClientDecorator, fakeLogger); //Act await client.ConnectAsync(); //Assert await fakeClientDecorator .Received(1) .ConnectAsync(); }
public async Task Connect_FailedConnection_RetriesAgain() { //Arrange var fakeClientDecorator = Substitute.For <ISshClientDecorator>(); var fakeLogger = Substitute.For <ILogger>(); var client = new SshClient( fakeClientDecorator, fakeLogger); fakeClientDecorator .ConnectAsync() .Returns( Task.FromException(new SshConnectionException()), Task.CompletedTask); //Act await client.ConnectAsync(); //Assert await fakeClientDecorator .Received(2) .ConnectAsync(); }