HttpRequestClientIdentifierSupplier implements ClientIdentifierSupplier { @VisibleForTesting static String toObfuscated(String str) { Matcher ipv4Matcher = PATTERN_IPV4_ADDRESS.matcher(str); if (ipv4Matcher.matches()) { return HASH.hashString(str, Charsets.UTF_8).toString() + "." + ipv4Matcher.group(4); } return HASH.hashString(str, Charsets.UTF_8).toString(); }  @Override Optional<String> get();  }
@Test public void testObfuscate_notIpv4() { String input = "How Now Brown Cow.6"; String output = HttpRequestClientIdentifierSupplier.toObfuscated(input); Assertions.assertThat(output).matches("^[0-9a-f]+$"); }
@Test public void testObfuscate_ipv4() { String input = "1.2.3.4"; String output = HttpRequestClientIdentifierSupplier.toObfuscated(input); Assertions.assertThat(output).endsWith(".4"); }