RequestSignerImpl implements RequestSigner { @VisibleForTesting static Map<String, List<String>> ignoreCaseHeaders( final Map<String, List<String>> originalHeaders) { Map<String, List<String>> transformedMap = new HashMap<>(); for (Entry<String, List<String>> entry : originalHeaders.entrySet()) { transformedMap.put(entry.getKey().toLowerCase(), entry.getValue()); } return transformedMap; } RequestSignerImpl(
            @Nonnull final KeySupplier<RSAPrivateKey> keySupplier,
            @Nonnull final SigningStrategy signingStrategy,
            @Nonnull final Supplier<String> keyIdSupplier);  RequestSignerImpl(
            @Nonnull final KeySupplier<RSAPrivateKey> keySupplier,
            @Nonnull final SigningConfiguration signingConfiguration,
            @Nonnull final Supplier<String> keyIdSupplier); @Override Map<String, String> signRequest(
            @Nonnull final URI uri,
            @Nonnull final String httpMethod,
            @Nonnull final Map<String, List<String>> headers,
            @Nullable final Object body); static Map<String, String> signRequest(
            final Algorithm algorithm,
            final URI uri,
            final String httpMethod,
            final Map<String, List<String>> headers,
            final Object body,
            final String versionName,
            final String keyId,
            final KeySupplier<RSAPrivateKey> keySupplier,
            final SigningConfiguration signingConfiguration);  }
@Test public void ignoreCaseHeaders_shouldReturnMapWithLowerCaseKeys_whenHeadersContainUpperCaseKeys() throws Exception { final Map<String, List<String>> headers = new HashMap<>(); headers.put("Content-Length", Collections.singletonList("238")); headers.put("Content-Type", Collections.singletonList(MediaType.APPLICATION_JSON)); headers.put("OPC-REQUEST-ID", Collections.singletonList("RequestID")); final Map<String, List<String>> actual = RequestSignerImpl.ignoreCaseHeaders(headers); assertNotNull("Map should not be null", actual); assertEquals("Map should contain 3 entries", 3, actual.size()); for (Map.Entry<String, List<String>> expectedEntry : headers.entrySet()) { final String expectedKey = expectedEntry.getKey(); final List<String> expectedValue = expectedEntry.getValue(); assertTrue( "Actual map should contain matching key for lower case value", actual.containsKey(expectedKey.toLowerCase())); final List<String> actualValue = actual.get(expectedKey.toLowerCase()); assertEquals( "Values should be equal for key: " + expectedKey, expectedValue, actualValue); } }
@PrepareForTest({LoggerFactory.class, RestClientFactory.class, RequestSignerImpl.class}) @Test public void ignoreCaseHeaders_whenDuplicateHeaderKeysExists() throws Exception { final Map<String, List<String>> headers = new HashMap<>(); headers.put("content-length", Collections.singletonList("238")); headers.put("opc-request-id", Lists.newArrayList("ID1", "ID2")); final Map<String, List<String>> actual = RequestSignerImpl.ignoreCaseHeaders(headers); assertNotNull("Map should not be null", actual); assertEquals("Map should contain 2 entries", 2, actual.size()); for (Map.Entry<String, List<String>> expectedEntry : headers.entrySet()) { final String expectedKey = expectedEntry.getKey(); final List<String> expectedValue = expectedEntry.getValue(); assertTrue( "Actual map should contain matching key for lower case value", actual.containsKey(expectedKey.toLowerCase())); final List<String> actualValue = actual.get(expectedKey.toLowerCase()); assertEquals( "Values should be equal for key: " + expectedKey, expectedValue, actualValue); } }