Obfuscate { public static String secureSensitive(String value) { if (value == null) { return null; } if (isDisabled(secureLogs) && isDisabled(secureSensitive)) { return value; } if ("hash".equalsIgnoreCase(secureSensitive)) { return "hash:" + computeSha(value).substring(0, 4); } return "****"; }  static String secure(String value, String delim); static String secure(String value); static String secureSensitiveChar(char[] value); static String secureSensitive(String value);  }
@Test void disabledHidingSecretRequiresSecureLogsOff() { Obfuscate.secureSensitive = "TRUE"; assertThat(Obfuscate.secureSensitive(TEST_STRING)).isEqualTo("****"); Obfuscate.secureSensitive = "OFF"; Obfuscate.secureLogs = "OFF"; assertThat(Obfuscate.secureSensitive(TEST_STRING)).isEqualTo(TEST_STRING); }
@Test void hidingSecretWithHash() { Obfuscate.secureSensitive = "HASH"; assertThat(Obfuscate.secureSensitive(TEST_STRING)).isEqualTo("hash:9eRM"); }
@Test void hidingSecretTrue() { Obfuscate.secureSensitive = "TRUE"; assertThat(Obfuscate.secureSensitive(TEST_STRING)).isEqualTo("****"); Obfuscate.secureSensitive = "true"; assertThat(Obfuscate.secureSensitive(TEST_STRING)).isEqualTo("****"); }
@Test void hidingSecretNull() { Obfuscate.secureSensitive = null; assertThat(Obfuscate.secureSensitive(TEST_STRING)).isEqualTo("****"); }
@Test void hidingSecretEmpty() { Obfuscate.secureSensitive = ""; assertThat(Obfuscate.secureSensitive(TEST_STRING)).isEqualTo("****"); }