Esempio n. 1
0
  @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: "));
  }
Esempio n. 2
0
  @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));
  }
Esempio n. 3
0
  @Test
  @RunIf(
      value = EnhancedOSChecker.class,
      arguments = {DO_NOT_RUN_ON, OSChecker.WINDOWS})
  public void shouldBeAbleToRunCommandsFromRelativeDirectories() throws IOException {
    File shellScript = new File(tempFolder, "hello-world.sh");
    FileUtil.writeContentToFile("echo ${PWD}", shellScript);
    assertThat(shellScript.setExecutable(true), is(true));

    CommandLine line = CommandLine.createCommandLine("../hello-world.sh").withWorkingDir(subFolder);

    InMemoryStreamConsumer out = new InMemoryStreamConsumer();
    line.execute(out, new EnvironmentVariableContext(), null).waitForExit();

    assertThat(out.getAllOutput().trim(), endsWith("subFolder"));
  }
Esempio n. 4
0
  @Test
  @RunIf(
      value = EnhancedOSChecker.class,
      arguments = {DO_NOT_RUN_ON, OSChecker.WINDOWS})
  public void shouldNotRunLocalCommandsThatAreNotExecutable() throws IOException {
    createScript("echo", "echo 'this should not be here'");

    CommandLine line =
        CommandLine.createCommandLine("echo")
            .withArg("Using the REAL echo")
            .withWorkingDir(subFolder);

    InMemoryStreamConsumer out = new InMemoryStreamConsumer();
    line.execute(out, new EnvironmentVariableContext(), null).waitForExit();

    assertThat(out.getAllOutput(), containsString("Using the REAL echo"));
  }
Esempio n. 5
0
  @Test
  @RunIf(
      value = EnhancedOSChecker.class,
      arguments = {DO_NOT_RUN_ON, OSChecker.WINDOWS})
  public void shouldBeAbleToRunCommandsInSubdirectoriesWithNoWorkingDir() throws IOException {

    File shellScript = createScript("hello-world.sh", "echo 'Hello World!'");
    assertThat(shellScript.setExecutable(true), is(true));

    CommandLine line =
        CommandLine.createCommandLine("subFolder/hello-world.sh").withWorkingDir(tempFolder);

    InMemoryStreamConsumer out = new InMemoryStreamConsumer();
    line.execute(out, new EnvironmentVariableContext(), null).waitForExit();

    assertThat(out.getAllOutput(), containsString("Hello World!"));
  }
Esempio n. 6
0
  @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")));
  }
Esempio n. 7
0
  @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"));
  }