Search in sources :

Example 21 with HttpServletRequest

use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.

the class StrictHttpFirewallTests method getFirewalledRequestGetParameterMapWhenControlCharacterInParameterNameThenException.

@Test
public void getFirewalledRequestGetParameterMapWhenControlCharacterInParameterNameThenException() {
    this.request.addParameter("Bad\0Name", "some value");
    HttpServletRequest request = this.firewall.getFirewalledRequest(this.request);
    assertThatExceptionOfType(RequestRejectedException.class).isThrownBy(request::getParameterMap);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 22 with HttpServletRequest

use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.

the class StrictHttpFirewallTests method getFirewalledRequestGetHeaderWhenControlCharacterInHeaderValueThenException.

@Test
public void getFirewalledRequestGetHeaderWhenControlCharacterInHeaderValueThenException() {
    this.request.addHeader("Something", "bad\0value");
    HttpServletRequest request = this.firewall.getFirewalledRequest(this.request);
    assertThatExceptionOfType(RequestRejectedException.class).isThrownBy(() -> request.getHeader("Something"));
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 23 with HttpServletRequest

use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.

the class StrictHttpFirewallTests method getFirewalledRequestGetHeadersWhenControlCharacterInHeaderNameThenException.

@Test
public void getFirewalledRequestGetHeadersWhenControlCharacterInHeaderNameThenException() {
    this.request.addHeader("Bad\0Name", "some value");
    HttpServletRequest request = this.firewall.getFirewalledRequest(this.request);
    assertThatExceptionOfType(RequestRejectedException.class).isThrownBy(() -> request.getHeaders("Bad\0Name"));
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 24 with HttpServletRequest

use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.

the class StrictHttpFirewallTests method getFirewalledRequestGetHeaderWhenUndefinedCharacterInHeaderNameThenException.

@Test
public void getFirewalledRequestGetHeaderWhenUndefinedCharacterInHeaderNameThenException() {
    this.request.addHeader("Bad\uFFFEName", "some value");
    HttpServletRequest request = this.firewall.getFirewalledRequest(this.request);
    assertThatExceptionOfType(RequestRejectedException.class).isThrownBy(() -> request.getHeader("Bad\uFFFEName"));
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 25 with HttpServletRequest

use of jakarta.servlet.http.HttpServletRequest in project spring-security by spring-projects.

the class StrictHttpFirewallTests method getFirewalledRequestGetParameterValuesWhenNotAllowedInParameterNameThenException.

@Test
public void getFirewalledRequestGetParameterValuesWhenNotAllowedInParameterNameThenException() {
    this.firewall.setAllowedParameterNames((value) -> !value.equals("bad name"));
    this.request.addParameter("bad name", "good value");
    HttpServletRequest request = this.firewall.getFirewalledRequest(this.request);
    assertThatExceptionOfType(RequestRejectedException.class).isThrownBy(() -> request.getParameterValues("bad name"));
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Aggregations

HttpServletRequest (jakarta.servlet.http.HttpServletRequest)334 Test (org.junit.jupiter.api.Test)200 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)93 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)91 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)67 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)44 Authentication (org.springframework.security.core.Authentication)31 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)31 Test (org.junit.Test)28 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)26 IOException (java.io.IOException)22 ServletException (jakarta.servlet.ServletException)21 HashMap (java.util.HashMap)20 HttpServlet (jakarta.servlet.http.HttpServlet)19 FilterChain (jakarta.servlet.FilterChain)17 FilterDef (org.apache.tomcat.util.descriptor.web.FilterDef)16 HttpSession (jakarta.servlet.http.HttpSession)14 MockFilterChain (org.springframework.mock.web.MockFilterChain)14 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)14 ServletRequest (jakarta.servlet.ServletRequest)13