Search in sources :

Example 51 with HttpServletRequest

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

the class DispatcherTypeRequestMatcherTests method does_not_match_with_wrong_http_method.

@Test
public void does_not_match_with_wrong_http_method() {
    HttpServletRequest request = mockHttpServletRequest(DispatcherType.ERROR, HttpMethod.GET);
    DispatcherTypeRequestMatcher matcher = new DispatcherTypeRequestMatcher(DispatcherType.ERROR, HttpMethod.POST);
    assertThat(matcher.matches(request)).isFalse();
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 52 with HttpServletRequest

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

the class RegexRequestMatcherTests method requestHasNullMethodNoMatch.

// SEC-2084
@Test
public void requestHasNullMethodNoMatch() {
    RegexRequestMatcher matcher = new RegexRequestMatcher("/something/.*", "GET");
    HttpServletRequest request = createRequestWithNullMethod("/nomatch");
    assertThat(matcher.matches(request)).isFalse();
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 53 with HttpServletRequest

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

the class RegexRequestMatcherTests method requestHasNullMethodAndNullMatcherNoMatch.

@Test
public void requestHasNullMethodAndNullMatcherNoMatch() {
    RegexRequestMatcher matcher = new RegexRequestMatcher("/something/.*", null);
    HttpServletRequest request = createRequestWithNullMethod("/nomatch");
    assertThat(matcher.matches(request)).isFalse();
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 54 with HttpServletRequest

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

the class AntPathRequestMatcherTests method requestHasNullMethodNoMatch.

// SEC-2084
@Test
public void requestHasNullMethodNoMatch() {
    AntPathRequestMatcher matcher = new AntPathRequestMatcher("/something/*", "GET");
    HttpServletRequest request = createRequestWithNullMethod("/nomatch");
    assertThat(matcher.matches(request)).isFalse();
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 55 with HttpServletRequest

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

the class AntPathRequestMatcherTests method requestHasNullMethodMatches.

@Test
public void requestHasNullMethodMatches() {
    AntPathRequestMatcher matcher = new AntPathRequestMatcher("/something/*", "GET");
    HttpServletRequest request = createRequestWithNullMethod("/something/here");
    assertThat(matcher.matches(request)).isTrue();
}
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)289 Test (org.junit.jupiter.api.Test)160 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)93 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)88 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)21 ServletException (jakarta.servlet.ServletException)20 HttpServlet (jakarta.servlet.http.HttpServlet)19 HashMap (java.util.HashMap)17 FilterDef (org.apache.tomcat.util.descriptor.web.FilterDef)16 FilterChain (jakarta.servlet.FilterChain)15 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