Skip to content

Commit e292d4c

Browse files
Added test scope for NPE in RequestMethod
Signed-off-by: Soumik Sarker <ronodhirsoumik@gmail.com>
1 parent 9126aaf commit e292d4c

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

web/src/test/java/org/springframework/security/web/servlet/util/matcher/PathPatternRequestMatcherTests.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,20 @@
1616

1717
package org.springframework.security.web.servlet.util.matcher;
1818

19-
import jakarta.servlet.Servlet;
20-
import jakarta.servlet.ServletContext;
21-
import jakarta.servlet.ServletRegistration;
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
2221
import org.junit.jupiter.api.Test;
23-
2422
import org.springframework.http.HttpMethod;
2523
import org.springframework.mock.web.MockHttpServletRequest;
2624
import org.springframework.security.web.servlet.MockServletContext;
25+
import static org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher.pathPattern;
2726
import org.springframework.security.web.util.matcher.RequestMatcher;
27+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
2828
import org.springframework.web.util.ServletRequestPathUtils;
2929

30-
import static org.assertj.core.api.Assertions.assertThat;
31-
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
32-
import static org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher.pathPattern;
33-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
30+
import jakarta.servlet.Servlet;
31+
import jakarta.servlet.ServletContext;
32+
import jakarta.servlet.ServletRegistration;
3433

3534
/**
3635
* Tests for {@link PathPatternRequestMatcher}
@@ -146,6 +145,14 @@ void matcherWhenBasePathIsRootThenNoDoubleSlash() {
146145
assertThat(matcher.matches(mock)).isTrue();
147146
}
148147

148+
@Test
149+
void matcherWhenRequestMethodIsNullThenNoNullPointerException() {
150+
RequestMatcher matcher = pathPattern(HttpMethod.GET, "/");
151+
MockHttpServletRequest mock = new MockHttpServletRequest(null, "/");
152+
ServletRequestPathUtils.parseAndCache(mock);
153+
assertThat(matcher.matches(mock)).isFalse();
154+
}
155+
149156
MockHttpServletRequest request(String uri) {
150157
MockHttpServletRequest request = new MockHttpServletRequest("GET", uri);
151158
ServletRequestPathUtils.parseAndCache(request);

0 commit comments

Comments
 (0)