diff --git a/src/main/java/io/gravitee/policy/transformheaders/TransformHeadersPolicy.java b/src/main/java/io/gravitee/policy/transformheaders/TransformHeadersPolicy.java index c13e5615..ddefd59e 100644 --- a/src/main/java/io/gravitee/policy/transformheaders/TransformHeadersPolicy.java +++ b/src/main/java/io/gravitee/policy/transformheaders/TransformHeadersPolicy.java @@ -110,7 +110,7 @@ private Completable transformHeaders(final TemplateEngine templateEngine, final httpHeaders .names() .forEach(headerName -> { - if (!configuration.getWhitelistHeaders().contains(headerName)) { + if (configuration.getWhitelistHeaders().stream().noneMatch(headerName::equalsIgnoreCase)) { headersToRemove.add(headerName); } }); diff --git a/src/main/java/io/gravitee/policy/transformheaders/v3/TransformHeadersPolicyV3.java b/src/main/java/io/gravitee/policy/transformheaders/v3/TransformHeadersPolicyV3.java index febd9512..f2d15003 100644 --- a/src/main/java/io/gravitee/policy/transformheaders/v3/TransformHeadersPolicyV3.java +++ b/src/main/java/io/gravitee/policy/transformheaders/v3/TransformHeadersPolicyV3.java @@ -186,7 +186,7 @@ void transform(HttpHeaders httpHeaders, ExecutionContext executionContext) { httpHeaders .names() .forEach(headerName -> { - if (!configuration.getWhitelistHeaders().contains(headerName)) { + if (configuration.getWhitelistHeaders().stream().noneMatch(headerName::equalsIgnoreCase)) { headersToRemove.add(headerName); } }); diff --git a/src/test/java/io/gravitee/policy/transformheaders/TransformHeadersPolicyV4IntegrationTest.java b/src/test/java/io/gravitee/policy/transformheaders/TransformHeadersPolicyV4IntegrationTest.java index 179c9647..94c94fb2 100644 --- a/src/test/java/io/gravitee/policy/transformheaders/TransformHeadersPolicyV4IntegrationTest.java +++ b/src/test/java/io/gravitee/policy/transformheaders/TransformHeadersPolicyV4IntegrationTest.java @@ -99,11 +99,11 @@ void should_add_update_and_remove_headers_with_proxy_api(HttpClient client) thro get("/endpoint") .willReturn( ok() - .withHeader("toUpdateKeyResponse", "responseToUpdate") - .withHeader("toRemoveKeyResponse", "willBeRemoved") - .withHeader("whitelistedKeyResponse", "whitelisted") - .withHeader("notInWhitelistKeyResponse1", "excluded") - .withHeader("notInWhitelistKeyResponse2", "excluded") + .withHeader("toupdatekeyresponse", "responseToUpdate") + .withHeader("toremovekeyresponse", "willBeRemoved") + .withHeader("whitelistedkeyresponse", "whitelisted") + .withHeader("notinwhitelistkeyresponse1", "excluded") + .withHeader("notinwhitelistkeyresponse2", "excluded") ) ); @@ -111,11 +111,11 @@ void should_add_update_and_remove_headers_with_proxy_api(HttpClient client) thro .request(HttpMethod.GET, "/test") .flatMap(request -> request - .putHeader("toUpdateKey", "firstValue") - .putHeader("toRemoveKey", "willBeRemoved") - .putHeader("whitelistedKey", "whitelisted") - .putHeader("notInWhitelistKey1", "excluded") - .putHeader("notInWhitelistKey2", "excluded") + .putHeader("toupdatekey", "firstValue") + .putHeader("toremovekey", "willBeRemoved") + .putHeader("whitelistedkey", "whitelisted") + .putHeader("notinwhitelistkey1", "excluded") + .putHeader("notinwhitelistkey2", "excluded") .rxSend() ) .test(); @@ -137,12 +137,12 @@ void should_add_update_and_remove_headers_with_proxy_api(HttpClient client) thro wiremock.verify( getRequestedFor(urlPathEqualTo("/endpoint")) - .withHeader("headerKey", equalTo("headerValue")) - .withHeader("toUpdateKey", equalTo("updatedValue")) - .withHeader("whitelistedKey", equalTo("whitelisted")) - .withoutHeader("toRemoveKey") - .withoutHeader("notInWhitelistKey1") - .withoutHeader("notInWhitelistKey2") + .withHeader("headerkey", equalTo("headerValue")) + .withHeader("toupdatekey", equalTo("updatedValue")) + .withHeader("whitelistedkey", equalTo("whitelisted")) + .withoutHeader("toremovekey") + .withoutHeader("notinwhitelistkey1") + .withoutHeader("notinwhitelistkey2") ); } @@ -153,11 +153,11 @@ void should_add_update_and_remove_headers_on_request_message(HttpClient httpClie .rxRequest(POST, "/test") .flatMap(request -> request - .putHeader("toUpdateKey", "firstValue") - .putHeader("toRemoveKey", "willBeRemoved") - .putHeader("whitelistedKey", "whitelisted") - .putHeader("notInWhitelistKey1", "excluded") - .putHeader("notInWhitelistKey2", "excluded") + .putHeader("toupdatekey", "firstValue") + .putHeader("toremovekey", "willBeRemoved") + .putHeader("whitelistedkey", "whitelisted") + .putHeader("notinwhitelistkey1", "excluded") + .putHeader("notinwhitelistkey2", "excluded") .rxSend("message") ) .flatMap(response -> { diff --git a/src/test/java/io/gravitee/policy/transformheaders/v3/TransformHeadersPolicyV3IntegrationTest.java b/src/test/java/io/gravitee/policy/transformheaders/v3/TransformHeadersPolicyV3IntegrationTest.java index 04faedad..ab3cdf7b 100644 --- a/src/test/java/io/gravitee/policy/transformheaders/v3/TransformHeadersPolicyV3IntegrationTest.java +++ b/src/test/java/io/gravitee/policy/transformheaders/v3/TransformHeadersPolicyV3IntegrationTest.java @@ -48,11 +48,11 @@ void shouldAddUpdateAndRemoveHeaders(HttpClient client) throws InterruptedExcept get("/endpoint") .willReturn( ok() - .withHeader("toUpdateKeyResponse", "responseToUpdate") - .withHeader("toRemoveKeyResponse", "willBeRemoved") - .withHeader("whitelistedKeyResponse", "whitelisted") - .withHeader("notInWhitelistKeyResponse1", "excluded") - .withHeader("notInWhitelistKeyResponse2", "excluded") + .withHeader("toupdatekeyresponse", "responseToUpdate") + .withHeader("toremovekeyresponse", "willBeRemoved") + .withHeader("whitelistedkeyresponse", "whitelisted") + .withHeader("notinwhitelistkeyresponse1", "excluded") + .withHeader("notinwhitelistkeyresponse2", "excluded") ) ); @@ -60,11 +60,11 @@ void shouldAddUpdateAndRemoveHeaders(HttpClient client) throws InterruptedExcept .request(HttpMethod.GET, "/test") .flatMap(request -> request - .putHeader("toUpdateKey", "firstValue") - .putHeader("toRemoveKey", "willBeRemoved") - .putHeader("whitelistedKey", "whitelisted") - .putHeader("notInWhitelistKey1", "excluded") - .putHeader("notInWhitelistKey2", "excluded") + .putHeader("toupdatekey", "firstValue") + .putHeader("toremovekey", "willBeRemoved") + .putHeader("whitelistedkey", "whitelisted") + .putHeader("notinwhitelistkey1", "excluded") + .putHeader("notinwhitelistkey2", "excluded") .rxSend() ) .test(); @@ -86,12 +86,12 @@ void shouldAddUpdateAndRemoveHeaders(HttpClient client) throws InterruptedExcept wiremock.verify( getRequestedFor(urlPathEqualTo("/endpoint")) - .withHeader("headerKey", equalTo("headerValue")) - .withHeader("toUpdateKey", equalTo("updatedValue")) - .withHeader("whitelistedKey", equalTo("whitelisted")) - .withoutHeader("toRemoveKey") - .withoutHeader("notInWhitelistKey1") - .withoutHeader("notInWhitelistKey2") + .withHeader("headerkey", equalTo("headerValue")) + .withHeader("toupdatekey", equalTo("updatedValue")) + .withHeader("whitelistedkey", equalTo("whitelisted")) + .withoutHeader("toremovekey") + .withoutHeader("notinwhitelistkey1") + .withoutHeader("notinwhitelistkey2") ); } } diff --git a/src/test/java/io/gravitee/policy/transformheaders/v3/TransformHeadersPolicyV3Test.java b/src/test/java/io/gravitee/policy/transformheaders/v3/TransformHeadersPolicyV3Test.java index b9864bb2..23e722d3 100644 --- a/src/test/java/io/gravitee/policy/transformheaders/v3/TransformHeadersPolicyV3Test.java +++ b/src/test/java/io/gravitee/policy/transformheaders/v3/TransformHeadersPolicyV3Test.java @@ -301,9 +301,9 @@ void test_OnResponse_removeHeaderNull() { @Test void test_OnResponse_removeHeaderAndWhiteList() { // Prepare - responseHttpHeaders.set("X-Gravitee-ToRemove", "Initial"); - responseHttpHeaders.set("X-Gravitee-White", "Initial"); - responseHttpHeaders.set("X-Gravitee-Black", "Initial"); + responseHttpHeaders.set("x-gravitee-toremove", "Initial"); + responseHttpHeaders.set("x-gravitee-white", "Initial"); + responseHttpHeaders.set("x-gravitee-black", "Initial"); when(transformHeadersPolicyConfiguration.getScope()).thenReturn(PolicyScope.RESPONSE); when(transformHeadersPolicyConfiguration.getAddHeaders()).thenReturn(null); when(transformHeadersPolicyConfiguration.getRemoveHeaders()).thenReturn(Collections.singletonList("X-Gravitee-ToRemove")); @@ -350,8 +350,8 @@ void test_OnRequest_doNothing() { @Test void test_OnResponse_whitelistHeader() { // Prepare - responseHttpHeaders.set("X-Walter", "Initial"); - responseHttpHeaders.set("X-White", "Initial"); + responseHttpHeaders.set("x-walter", "Initial"); + responseHttpHeaders.set("x-white", "Initial"); when(transformHeadersPolicyConfiguration.getScope()).thenReturn(PolicyScope.RESPONSE); when(transformHeadersPolicyConfiguration.getWhitelistHeaders()).thenReturn(Collections.singletonList("X-White")); @@ -367,8 +367,8 @@ void test_OnResponse_whitelistHeader() { @Test void test_OnRequest_whitelistHeader() { // Prepare - requestHttpHeaders.set("X-Walter", "Initial"); - requestHttpHeaders.set("X-White", "Initial"); + requestHttpHeaders.set("x-walter", "Initial"); + requestHttpHeaders.set("x-white", "Initial"); when(transformHeadersPolicyConfiguration.getScope()).thenReturn(PolicyScope.REQUEST); when(transformHeadersPolicyConfiguration.getWhitelistHeaders()).thenReturn(Collections.singletonList("X-White"));