示例#1
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")));
  }
示例#2
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"));
  }