@Override public void process(final WilmaHttpEntity entity) throws ApplicationException { WilmaHttpRequest request = (WilmaHttpRequest) entity; /** * If this method was called then localhost blocking is turned on, * so we only need to check if the request targets localhost in order to determine if it needs to be rerouted. */ boolean requestNeedsRerouting = localhostRequestChecker.checkIfRequestTargetsLocalhost(request); if (requestNeedsRerouting) { localhostRequestRouter.reroute(request); request.setRerouted(true); } }
@Test public void testThatRerouteShouldSetRequestUriToServletAddress() throws URISyntaxException { //GIVEN URI expected = new URI("http://127.0.0.1:0/local/"); //WHEN underTest.reroute(request); //THEN verify(request).setUri(expected); }
@Test public void testIfEnabledShouldNotRerouteNonLocalhostRequest() throws ApplicationException { //GIVEN underTest.setEnabled(true); given(localhostRequestChecker.checkIfRequestTargetsLocalhost(Mockito.any(WilmaHttpRequest.class))).willReturn(false); //WHEN underTest.process(request); //THEN verify(localhostRequestRouter, never()).reroute(request); verify(request, never()).setRerouted(true); }
@Test public void testIfEnabledShouldRerouteLocalhostRequest() throws ApplicationException { //GIVEN underTest.setEnabled(true); given(localhostRequestChecker.checkIfRequestTargetsLocalhost(Mockito.any(WilmaHttpRequest.class))).willReturn(true); //WHEN underTest.process(request); //THEN verify(localhostRequestRouter).reroute(request); verify(request).setRerouted(true); }