RequestPropertyFilter { public static FilterResult filterProperty(HttpServerRequest request, String filterPropertyKey, String filterPropertyValue, boolean reject) { CaseInsensitiveHeaders headers = new CaseInsensitiveHeaders(); headers.setAll(request.headers()); if (URL.equals(filterPropertyKey)) { boolean matches = filterRequestURL(request, filterPropertyValue); FilterResult result = rejectIfNeeded(reject, matches); logFilterResult(request, filterPropertyKey, filterPropertyValue, result); return result; } if (METHOD.equals(filterPropertyKey)) { boolean matches = filterRequestMethod(request, filterPropertyValue); FilterResult result = rejectIfNeeded(reject, matches); logFilterResult(request, filterPropertyKey, filterPropertyValue, result); return result; } if (headers.names().contains(filterPropertyKey) && headers.get(filterPropertyKey).equalsIgnoreCase(filterPropertyValue)) { FilterResult result = reject ? FilterResult.REJECT : FilterResult.FILTER; logFilterResult(request, filterPropertyKey, filterPropertyValue, result); return result; } logFilterResult(request, filterPropertyKey, filterPropertyValue, FilterResult.REJECT, true); return FilterResult.REJECT; }  static FilterResult filterProperty(HttpServerRequest request, String filterPropertyKey, String filterPropertyValue, boolean reject); static final String URL; static final String METHOD; }
@Test public void testPropertyUrlFilterRequest(TestContext context){ context.assertEquals(FilterResult.FILTER, RequestPropertyFilter.filterProperty(new PUTRequest(), RequestPropertyFilter.URL, PUT_REQUEST_REGEX, false)); }
@Test public void testPropertyUrlRejectRequest(TestContext context){ context.assertEquals(FilterResult.REJECT, RequestPropertyFilter.filterProperty(new PUTRequest(), RequestPropertyFilter.URL, PUT_REQUEST_REGEX, true)); }
@Test public void testPropertyUrlNoMatchRequest(TestContext context){ context.assertEquals(FilterResult.NO_MATCH, RequestPropertyFilter.filterProperty(new PUTRequest(), RequestPropertyFilter.URL, OTHER_PUT_REQUEST_URI, true)); }
@Test public void testPropertyMethodFilterRequest(TestContext context){ context.assertEquals(FilterResult.FILTER, RequestPropertyFilter.filterProperty(new PUTRequest(), RequestPropertyFilter.METHOD, METHOD_PUT, false)); context.assertEquals(FilterResult.FILTER, RequestPropertyFilter.filterProperty(new PUTRequest(), RequestPropertyFilter.METHOD, METHOD_PUT_POST_REGEX, false)); }
@Test public void testPropertyMethodRejectRequest(TestContext context){ context.assertEquals(FilterResult.REJECT, RequestPropertyFilter.filterProperty(new PUTRequest(), RequestPropertyFilter.METHOD, METHOD_PUT, true)); }
@Test public void testPropertyMethodNoMatchRequest(TestContext context){ context.assertEquals(FilterResult.NO_MATCH, RequestPropertyFilter.filterProperty(new PUTRequest(), RequestPropertyFilter.METHOD, METHOD_GET, false)); context.assertEquals(FilterResult.NO_MATCH, RequestPropertyFilter.filterProperty(new PUTRequest(), RequestPropertyFilter.METHOD, METHOD_GET, true)); }
@Test public void testPropertyHeaderFilterRequest(TestContext context){ PUTRequest request = new PUTRequest(); String headerName = "some_fancy_header"; String headerValue = "a_fancy_value"; request.addHeader(headerName, headerValue); context.assertEquals(FilterResult.FILTER, RequestPropertyFilter.filterProperty(request, headerName, headerValue, false)); }
@Test public void testPropertyHeaderRejectRequest(TestContext context){ PUTRequest request = new PUTRequest(); String headerName = "some_fancy_header"; String headerValue = "a_fancy_value"; request.addHeader(headerName, headerValue); context.assertEquals(FilterResult.REJECT, RequestPropertyFilter.filterProperty(request, headerName, headerValue, true)); }
@Test public void testPropertyHeaderNotMatchingRequest(TestContext context){ PUTRequest request = new PUTRequest(); String headerName = "some_fancy_header"; String headerValue = "a_fancy_value"; request.addHeader(headerName, headerValue); context.assertEquals(FilterResult.REJECT, RequestPropertyFilter.filterProperty(request, headerName, "another_fancy_value", true)); context.assertEquals(FilterResult.REJECT, RequestPropertyFilter.filterProperty(request, "another_fancy_header", headerValue, true)); context.assertEquals(FilterResult.REJECT, RequestPropertyFilter.filterProperty(request, headerName, "another_fancy_value", false)); context.assertEquals(FilterResult.REJECT, RequestPropertyFilter.filterProperty(request, "another_fancy_header", headerValue, false)); }