Sanitizer { public static Map<String, Object> sanitize(ConfigBag input) { return (input == null) ? null : sanitize(input.getAllConfig()); } private  Sanitizer(Predicate<Object> sanitizingNeededCheck); static Sanitizer newInstance(Predicate<Object> sanitizingNeededCheck); static Sanitizer newInstance(); static Map<String, Object> sanitize(ConfigBag input); static Map<K, Object> sanitize(Map<K, ?> input); Map<K, Object> apply(Map<K, ?> input); static final List<String> SECRET_NAMES; static final Predicate<Object> IS_SECRET_PREDICATE; }
@Test public void testSanitize() throws Exception { Map<String, Object> map = ImmutableMap.<String, Object>builder() .put("PREFIX_password_SUFFIX", "pa55w0rd") .put("PREFIX_PASSWORD_SUFFIX", "pa55w0rd") .put("PREFIX_passwd_SUFFIX", "pa55w0rd") .put("PREFIX_credential_SUFFIX", "pa55w0rd") .put("PREFIX_secret_SUFFIX", "pa55w0rd") .put("PREFIX_private_SUFFIX", "pa55w0rd") .put("PREFIX_access.cert_SUFFIX", "myval") .put("PREFIX_access.key_SUFFIX", "myval") .put("mykey", "myval") .build(); Map<String, Object> expected = MutableMap.<String, Object>builder() .putAll(Maps.transformValues(map, Functions.constant("xxxxxxxx"))) .put("mykey", "myval") .build(); Map<String, Object> sanitized = Sanitizer.sanitize(ConfigBag.newInstance(map)); assertEquals(sanitized, expected); Map<String, Object> sanitized2 = Sanitizer.sanitize(map); assertEquals(sanitized2, expected); }
@Test public void testSanitizeWithNullKey() throws Exception { MutableMap<?, ?> map = MutableMap.of(null, null); Map<?, ?> sanitized = Sanitizer.sanitize(map); assertEquals(sanitized, map); }