-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54170d9
commit 4e4ca37
Showing
17 changed files
with
143 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 13 additions & 2 deletions
15
src/main/java/com/thoughtworks/go/scm/plugin/util/StringUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
package com.thoughtworks.go.scm.plugin.util; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Optional; | ||
|
||
public class StringUtil { | ||
public static boolean isBlank(String str) { | ||
return str == null || str.isBlank(); | ||
private static final String REDACT_REPLACEMENT = "******"; | ||
|
||
public static String replaceSecretText(String redactableText, Collection<String> secrets) { | ||
return Optional.ofNullable(secrets).orElse(Collections.emptySet()).stream() | ||
.filter(StringUtils::isNotBlank) | ||
.map(String::trim) | ||
.reduce(redactableText, (partiallyRedacted, secret) -> partiallyRedacted.replaceAll(secret, REDACT_REPLACEMENT)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/test/java/com/thoughtworks/go/scm/plugin/git/cmd/ConsoleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.thoughtworks.go.scm.plugin.git.cmd; | ||
|
||
import org.apache.commons.exec.CommandLine; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Set; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
class ConsoleTest { | ||
|
||
@TempDir | ||
File tempDir; | ||
|
||
@Test | ||
public void shouldRedactExceptionMessagesFromCommandLine() { | ||
CommandLine command = CommandLine.parse("badbinary https://secret:thing/here"); | ||
Set<String> secrets = Set.of("secret", "thing"); | ||
assertThatThrownBy(() -> Console.runOrBomb(command, tempDir, null, null, secrets)) | ||
.isExactlyInstanceOf(RuntimeException.class) | ||
.hasMessageContaining("Exception (Cannot run program \"badbinary\"") | ||
.hasMessageContaining("https://******:******/here") | ||
.hasMessageNotContainingAny(secrets.toArray(String[]::new)) | ||
.hasCauseExactlyInstanceOf(IOException.class); | ||
} | ||
|
||
@Test | ||
public void shouldRedactExceptionMessagesFromException() { | ||
CommandLine command = CommandLine.parse("secretthing and some args secret"); | ||
Set<String> secrets = Set.of("secret", "thing"); | ||
assertThatThrownBy(() -> Console.runOrBomb(command, tempDir, null, null, secrets)) | ||
.isExactlyInstanceOf(RuntimeException.class) | ||
.hasMessageContaining("Exception (Cannot run program \"************\"") | ||
.hasMessageContaining("************, and, some, args, ******") | ||
.hasMessageNotContainingAny(secrets.toArray(String[]::new)) | ||
.hasCauseExactlyInstanceOf(IOException.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.