HttpUtils { public static String hideSecret(@NonNull String secret) { int hidingEndIndex = secret.length() - (secret.length() >= MAX_CHARACTERS_DISPLAYED_FOR_SECRET ? MAX_CHARACTERS_DISPLAYED_FOR_SECRET : 0); char[] fill = new char[hidingEndIndex]; Arrays.fill(fill, '*'); return new String(fill) + secret.substring(hidingEndIndex); } @VisibleForTesting  HttpUtils(); static boolean isRecoverableError(Throwable t); static String hideSecret(@NonNull String secret); static String hideApiKeys(@NonNull String apiKeys); static String hideTickets(@NonNull String tickets); static HttpClient createHttpClient(@NonNull Context context); static HttpClient createHttpClient(@NonNull Context context, boolean compressionEnabled); static HttpClient createHttpClientWithoutRetryer(@NonNull Context context, boolean compressionEnabled); @NonNull static HttpsURLConnection createHttpsConnection(@NonNull URL url); static final int THREAD_STATS_TAG; static final int READ_BUFFER_SIZE; static final int WRITE_BUFFER_SIZE; static final int CONNECT_TIMEOUT; static final int READ_TIMEOUT; }
@Test public void hideEmptySecret() { assertEquals("", HttpUtils.hideSecret("")); }
@Test public void hideShortSecret() { assertEquals("*****", HttpUtils.hideSecret("Short")); }
@Test public void hideLongSecret() { String secret = "This_is_very_long_secret_for_unit_test_in_http_utils"; String obfuscatedSecret = HttpUtils.hideSecret(secret); assertEquals(secret.length(), obfuscatedSecret.length()); assertTrue(obfuscatedSecret.endsWith("*" + secret.substring(secret.length() - MAX_CHARACTERS_DISPLAYED_FOR_SECRET))); }