@Test public void shouldLogPasswordsOnTheLogAsStars() { LogFixture logFixture = LogFixture.startListening(); LogFixture.enableDebug(); CommandLine line = CommandLine.createCommandLine("notexist").withArg(new PasswordArgument("secret")); try { line.runOrBomb(null); } catch (Exception e) { // ignored } assertThat(ArrayUtil.join(logFixture.getMessages()), containsString("notexist ******")); logFixture.stopListening(); }
@Test @RunIf( value = EnhancedOSChecker.class, arguments = {DO_NOT_RUN_ON, OSChecker.WINDOWS}) public void shouldNotLogPasswordsFromStream() { LogFixture logFixture = LogFixture.startListening(); CommandLine line = CommandLine.createCommandLine("/bin/echo") .withArg("=>") .withArg(new PasswordArgument("secret")); line.runOrBomb(null); System.out.println(ArrayUtil.join(logFixture.getMessages())); assertThat(ArrayUtil.join(logFixture.getMessages()), not(containsString("secret"))); assertThat(ArrayUtil.join(logFixture.getMessages()), containsString("=> ******")); logFixture.stopListening(); }
@Test @RunIf( value = EnhancedOSChecker.class, arguments = {DO_NOT_RUN_ON, OSChecker.WINDOWS}) public void shouldNotLogPasswordsOnExceptionThrown() throws IOException { File dir = FileUtil.createTempFolder(); File file = new File(dir, "test.sh"); FileOutputStream out = new FileOutputStream(file); out.write("echo $1 && exit 10".getBytes()); out.close(); CommandLine line = CommandLine.createCommandLine("/bin/sh") .withArg(file.getAbsolutePath()) .withArg(new PasswordArgument("secret")); try { line.runOrBomb(null); } catch (CommandLineException e) { assertThat(e.getMessage(), not(containsString("secret"))); } }