@Test public void shouldPrefixStderrOutput() { CommandLine line = CommandLine.createCommandLine("rmdir").withArg("/a/directory/that/does/not/exist"); InMemoryStreamConsumer output = new InMemoryStreamConsumer(); ProcessWrapper processWrapper = line.execute(output, new EnvironmentVariableContext(), null); processWrapper.waitForExit(); assertThat(output.getAllOutput(), containsString("STDERR: ")); }
@Test @RunIf( value = EnhancedOSChecker.class, arguments = {DO_NOT_RUN_ON, OSChecker.WINDOWS}) public void shouldBeAbleToSpecifyEncoding() throws IOException { String chrisWasHere = "?????"; CommandLine line = CommandLine.createCommandLine("echo").withArg(chrisWasHere).withEncoding("UTF-8"); InMemoryStreamConsumer output = new InMemoryStreamConsumer(); ProcessWrapper processWrapper = line.execute(output, new EnvironmentVariableContext(), null); processWrapper.waitForExit(); assertThat(output.getAllOutput(), containsString(chrisWasHere)); }
@Test @RunIf(value = OSChecker.class, arguments = OSChecker.WINDOWS) public void shouldLogPasswordsOnOutputAsStarsUnderWindows() throws IOException { CommandLine line = CommandLine.createCommandLine("cmd") .withArg("/c") .withArg("echo") .withArg("My Password is:") .withArg(new PasswordArgument("secret")); InMemoryStreamConsumer output = new InMemoryStreamConsumer(); InMemoryStreamConsumer displayOutputStreamConsumer = InMemoryStreamConsumer.inMemoryConsumer(); ProcessWrapper processWrapper = line.execute(output, new EnvironmentVariableContext(), null); processWrapper.waitForExit(); assertThat(output.getAllOutput(), containsString("secret")); assertThat(displayOutputStreamConsumer.getAllOutput(), not(containsString("secret"))); }
@Test @RunIf( value = EnhancedOSChecker.class, arguments = {DO_NOT_RUN_ON, OSChecker.WINDOWS}) public void shouldLogPasswordsOnEnvironemntAsStarsUnderLinux() throws IOException { CommandLine line = CommandLine.createCommandLine("echo") .withArg("My Password is:") .withArg("secret") .withArg(new PasswordArgument("secret")); EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext(); environmentVariableContext.setProperty("ENV_PASSWORD", "secret", false); InMemoryStreamConsumer output = new InMemoryStreamConsumer(); InMemoryStreamConsumer forDisplay = InMemoryStreamConsumer.inMemoryConsumer(); ProcessWrapper processWrapper = line.execute(output, environmentVariableContext, null); processWrapper.waitForExit(); assertThat(forDisplay.getAllOutput(), not(containsString("secret"))); assertThat(output.getAllOutput(), containsString("secret")); }