Skip to content

Commit

Permalink
fix: make acceptlist case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
phiz71 committed Nov 13, 2023
1 parent 90f1fc5 commit 4748140
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,23 @@ 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")
)
);

final TestObserver<HttpClientResponse> obs = client
.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();
Expand All @@ -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")
);
}

Expand All @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ 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")
)
);

final TestObserver<HttpClientResponse> obs = client
.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();
Expand All @@ -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")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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"));

Expand All @@ -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"));

Expand Down

0 comments on commit 4748140

Please sign in to comment.