use of org.springframework.security.web.firewall.HttpFirewall in project spring-security by spring-projects.
the class MiscHttpConfigTests method getWhenUsingCustomHttpFirewallThenFirewallIsInvoked.
@Test
public void getWhenUsingCustomHttpFirewallThenFirewallIsInvoked() throws Exception {
this.spring.configLocations(xml("HttpFirewall")).autowire();
FirewalledRequest request = new FirewalledRequest(new MockHttpServletRequest()) {
@Override
public void reset() {
}
};
HttpServletResponse response = new MockHttpServletResponse();
HttpFirewall firewall = this.spring.getContext().getBean(HttpFirewall.class);
given(firewall.getFirewalledRequest(any(HttpServletRequest.class))).willReturn(request);
given(firewall.getFirewalledResponse(any(HttpServletResponse.class))).willReturn(response);
this.mvc.perform(get("/unprotected"));
verify(firewall).getFirewalledRequest(any(HttpServletRequest.class));
verify(firewall).getFirewalledResponse(any(HttpServletResponse.class));
}
use of org.springframework.security.web.firewall.HttpFirewall in project spring-security by spring-projects.
the class FilterChainProxyTests method bothWrappersAreResetWithNestedFcps.
// SEC-1639
@Test
public void bothWrappersAreResetWithNestedFcps() throws Exception {
HttpFirewall fw = mock(HttpFirewall.class);
FilterChainProxy firstFcp = new FilterChainProxy(new DefaultSecurityFilterChain(this.matcher, this.fcp));
firstFcp.setFirewall(fw);
this.fcp.setFirewall(fw);
FirewalledRequest firstFwr = mock(FirewalledRequest.class, "firstFwr");
given(firstFwr.getRequestURI()).willReturn("/");
given(firstFwr.getContextPath()).willReturn("");
FirewalledRequest fwr = mock(FirewalledRequest.class, "fwr");
given(fwr.getRequestURI()).willReturn("/");
given(fwr.getContextPath()).willReturn("");
given(fw.getFirewalledRequest(this.request)).willReturn(firstFwr);
given(fw.getFirewalledRequest(firstFwr)).willReturn(fwr);
given(fwr.getRequest()).willReturn(firstFwr);
given(firstFwr.getRequest()).willReturn(this.request);
given(this.matcher.matches(any())).willReturn(true);
firstFcp.doFilter(this.request, this.response, this.chain);
verify(firstFwr).reset();
verify(fwr).reset();
}
use of org.springframework.security.web.firewall.HttpFirewall in project spring-security by spring-projects.
the class MiscHttpConfigTests method getWhenUsingCustomRequestRejectedHandlerThenRequestRejectedHandlerIsInvoked.
@Test
public void getWhenUsingCustomRequestRejectedHandlerThenRequestRejectedHandlerIsInvoked() throws Exception {
this.spring.configLocations(xml("RequestRejectedHandler")).autowire();
HttpServletResponse response = new MockHttpServletResponse();
RequestRejectedException rejected = new RequestRejectedException("failed");
HttpFirewall firewall = this.spring.getContext().getBean(HttpFirewall.class);
RequestRejectedHandler requestRejectedHandler = this.spring.getContext().getBean(RequestRejectedHandler.class);
given(firewall.getFirewalledRequest(any(HttpServletRequest.class))).willThrow(rejected);
this.mvc.perform(get("/unprotected"));
verify(requestRejectedHandler).handle(any(), any(), any());
}
use of org.springframework.security.web.firewall.HttpFirewall in project spring-security by spring-projects.
the class FilterChainProxyTests method requestRejectedHandlerIsCalledIfFirewallThrowsRequestRejectedException.
@Test
public void requestRejectedHandlerIsCalledIfFirewallThrowsRequestRejectedException() throws Exception {
HttpFirewall fw = mock(HttpFirewall.class);
RequestRejectedHandler rjh = mock(RequestRejectedHandler.class);
this.fcp.setFirewall(fw);
this.fcp.setRequestRejectedHandler(rjh);
RequestRejectedException requestRejectedException = new RequestRejectedException("Contains illegal chars");
given(fw.getFirewalledRequest(this.request)).willThrow(requestRejectedException);
this.fcp.doFilter(this.request, this.response, this.chain);
verify(rjh).handle(eq(this.request), eq(this.response), eq((requestRejectedException)));
}
use of org.springframework.security.web.firewall.HttpFirewall in project spring-security by spring-projects.
the class FilterChainProxyTests method wrapperIsResetWhenNoMatchingFilters.
@Test
public void wrapperIsResetWhenNoMatchingFilters() throws Exception {
HttpFirewall fw = mock(HttpFirewall.class);
FirewalledRequest fwr = mock(FirewalledRequest.class);
given(fwr.getRequestURI()).willReturn("/");
given(fwr.getContextPath()).willReturn("");
this.fcp.setFirewall(fw);
given(fw.getFirewalledRequest(this.request)).willReturn(fwr);
given(this.matcher.matches(any(HttpServletRequest.class))).willReturn(false);
this.fcp.doFilter(this.request, this.response, this.chain);
verify(fwr).reset();
}
Aggregations