diff --git a/cors/src/main/java/io/helidon/cors/CorsSupportHelper.java b/cors/src/main/java/io/helidon/cors/CorsSupportHelper.java index f25c2c8dc1f..e8a3be7dffd 100644 --- a/cors/src/main/java/io/helidon/cors/CorsSupportHelper.java +++ b/cors/src/main/java/io/helidon/cors/CorsSupportHelper.java @@ -371,7 +371,7 @@ public Aggregator aggregator() { } // For testing - static RequestTypeInfo isRequestTypeNormal(String originHeader, UriInfo requestedHostUri) { + static RequestTypeInfo requestType(String originHeader, UriInfo requestedHostUri) { return RequestTypeInfo.create(originHeader, requestedHostUri); } @@ -406,7 +406,7 @@ private static boolean isRequestTypeNormal(CorsRequestAdapter requestAdapter, return true; } - RequestTypeInfo result = isRequestTypeNormal(originOpt.get(), requestAdapter.requestedUri()); + RequestTypeInfo result = requestType(originOpt.get(), requestAdapter.requestedUri()); LogHelper.logIsRequestTypeNormal(result.isNormal, silent, requestAdapter, diff --git a/cors/src/main/java/io/helidon/cors/LogHelper.java b/cors/src/main/java/io/helidon/cors/LogHelper.java index af5b648f4d9..6cb13a7f94b 100644 --- a/cors/src/main/java/io/helidon/cors/LogHelper.java +++ b/cors/src/main/java/io/helidon/cors/LogHelper.java @@ -73,12 +73,10 @@ static void logIsRequestTypeNormalNoOrigin(boolean silent, CorsRequestAdapte if (silent || !CorsSupportHelper.LOGGER.isLoggable(DECISION_LEVEL)) { return; } - if (CorsSupportHelper.LOGGER.isLoggable(DECISION_LEVEL)) { - CorsSupportHelper.LOGGER.log(DECISION_LEVEL, - String.format("Request %s is not cross-host: %s", - requestAdapter, - List.of("header " + HeaderNames.ORIGIN + " is absent"))); - } + CorsSupportHelper.LOGGER.log(DECISION_LEVEL, + String.format("Request %s is not cross-host: %s", + requestAdapter, + List.of("header " + HeaderNames.ORIGIN + " is absent"))); } static void logIsRequestTypeNormal(boolean result, boolean silent, CorsRequestAdapter requestAdapter, diff --git a/cors/src/test/java/io/helidon/cors/CorsSupportHelperTest.java b/cors/src/test/java/io/helidon/cors/CorsSupportHelperTest.java index 0909f4f44b4..22d7dffba78 100644 --- a/cors/src/test/java/io/helidon/cors/CorsSupportHelperTest.java +++ b/cors/src/test/java/io/helidon/cors/CorsSupportHelperTest.java @@ -66,24 +66,24 @@ void testNormalize() { @Test void sameNodeDifferentPorts() { assertThat("Default different origin port", - CorsSupportHelper.isRequestTypeNormal("http://ok.com", - uriInfo("ok.com", 8010, false)).isNormal(), + CorsSupportHelper.requestType("http://ok.com", + uriInfo("ok.com", 8010, false)).isNormal(), is(false)); assertThat("Explicit different origin port", - CorsSupportHelper.isRequestTypeNormal("http://ok.com:8080", - uriInfo("ok.com", false)).isNormal(), + CorsSupportHelper.requestType("http://ok.com:8080", + uriInfo("ok.com", false)).isNormal(), is(false)); } @Test void sameNodeSamePort() { assertThat("Default origin port", - CorsSupportHelper.isRequestTypeNormal("http://ok.com", - uriInfo("ok.com", false)).isNormal(), + CorsSupportHelper.requestType("http://ok.com", + uriInfo("ok.com", false)).isNormal(), is(true)); assertThat("Explicit origin port", - CorsSupportHelper.isRequestTypeNormal("http://ok.com:80", - UriInfo.builder() + CorsSupportHelper.requestType("http://ok.com:80", + UriInfo.builder() .host("ok.com") .build()).isNormal(), is(true)); @@ -92,40 +92,40 @@ void sameNodeSamePort() { @Test void differentNode() { assertThat("Different node, same (default) port", - CorsSupportHelper.isRequestTypeNormal("http://bad.com", - uriInfo("ok.com", false)).isNormal(), + CorsSupportHelper.requestType("http://bad.com", + uriInfo("ok.com", false)).isNormal(), is(false)); assertThat("Different node, same explicit port", - CorsSupportHelper.isRequestTypeNormal("http://bad.com:80", - uriInfo("ok.com", false)).isNormal(), + CorsSupportHelper.requestType("http://bad.com:80", + uriInfo("ok.com", false)).isNormal(), is(false)); assertThat("Different node, different explicit port", - CorsSupportHelper.isRequestTypeNormal("http://bad.com:8080", - uriInfo("ok.com", false)).isNormal(), + CorsSupportHelper.requestType("http://bad.com:8080", + uriInfo("ok.com", false)).isNormal(), is(false)); } @Test void differentScheme() { assertThat("Same node, insecure origin, secure host", - CorsSupportHelper.isRequestTypeNormal("http://foo.com", - uriInfo("foo.com", true)).isNormal(), + CorsSupportHelper.requestType("http://foo.com", + uriInfo("foo.com", true)).isNormal(), is(false)); assertThat("Same node, secure origin, insecure host", - CorsSupportHelper.isRequestTypeNormal("https://foo.com", - uriInfo("foo.com", false)).isNormal(), + CorsSupportHelper.requestType("https://foo.com", + uriInfo("foo.com", false)).isNormal(), is(false)); assertThat("Different nodes, insecure origin, secure host", - CorsSupportHelper.isRequestTypeNormal("http://foo.com", - uriInfo("other.com", true)).isNormal(), + CorsSupportHelper.requestType("http://foo.com", + uriInfo("other.com", true)).isNormal(), is(false)); assertThat("Different nodes, secure origin, insecure host", - CorsSupportHelper.isRequestTypeNormal("https://foo.com", - uriInfo("other.com", false)).isNormal(), + CorsSupportHelper.requestType("https://foo.com", + uriInfo("other.com", false)).isNormal(), is(false)); } @@ -134,28 +134,28 @@ void sameSecureScheme() { // Note that the real UriInfo instances from real requests will set the port according to whether the request is // secure or not. assertThat("Same node, secure origin, secure host", - CorsSupportHelper.isRequestTypeNormal("https://foo.com", - uriInfo("foo.com", true)).isNormal(), + CorsSupportHelper.requestType("https://foo.com", + uriInfo("foo.com", true)).isNormal(), is(true)); assertThat("Different node, secure origin, secure host", - CorsSupportHelper.isRequestTypeNormal("https://foo.com", - uriInfo("other.com", true)).isNormal(), + CorsSupportHelper.requestType("https://foo.com", + uriInfo("other.com", true)).isNormal(), is(false)); assertThat("Same nodes, different ports, secure origin, secure host", - CorsSupportHelper.isRequestTypeNormal("https://foo.com:1234", - uriInfo("foo.com",5678, true)).isNormal(), + CorsSupportHelper.requestType("https://foo.com:1234", + uriInfo("foo.com",5678, true)).isNormal(), is(false)); assertThat("Same nodes, explicit origin port, secure origin, secure host", - CorsSupportHelper.isRequestTypeNormal("https://foo.com:443", - uriInfo("foo.com", true)).isNormal(), + CorsSupportHelper.requestType("https://foo.com:443", + uriInfo("foo.com", true)).isNormal(), is(true)); assertThat("Same nodes, explicit host port, secure origin, secure host", - CorsSupportHelper.isRequestTypeNormal("https://foo.com", - uriInfo("foo.com", 443, true)).isNormal(), + CorsSupportHelper.requestType("https://foo.com", + uriInfo("foo.com", 443, true)).isNormal(), is(true)); }