|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | | - |
17 | 16 | package org.springframework.security.web.servlet.util.matcher; |
18 | 17 |
|
19 | | -import jakarta.servlet.Servlet; |
20 | | -import jakarta.servlet.ServletContext; |
21 | | -import jakarta.servlet.ServletRegistration; |
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
| 19 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
22 | 20 | import org.junit.jupiter.api.Test; |
23 | | - |
24 | 21 | import org.springframework.http.HttpMethod; |
25 | 22 | import org.springframework.mock.web.MockHttpServletRequest; |
26 | 23 | import org.springframework.security.web.servlet.MockServletContext; |
| 24 | +import static org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher.pathPattern; |
27 | 25 | import org.springframework.security.web.util.matcher.RequestMatcher; |
| 26 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
28 | 27 | import org.springframework.web.util.ServletRequestPathUtils; |
29 | 28 |
|
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; |
| 29 | +import jakarta.servlet.Servlet; |
| 30 | +import jakarta.servlet.ServletContext; |
| 31 | +import jakarta.servlet.ServletRegistration; |
34 | 32 |
|
35 | 33 | /** |
36 | 34 | * Tests for {@link PathPatternRequestMatcher} |
@@ -146,6 +144,14 @@ void matcherWhenBasePathIsRootThenNoDoubleSlash() { |
146 | 144 | assertThat(matcher.matches(mock)).isTrue(); |
147 | 145 | } |
148 | 146 |
|
| 147 | + @Test |
| 148 | + void matcherWhenRequestMethodIsNullThenNoNullPointerException() { |
| 149 | + RequestMatcher matcher = pathPattern(HttpMethod.GET, "/"); |
| 150 | + MockHttpServletRequest mock = new MockHttpServletRequest(null, "/"); |
| 151 | + ServletRequestPathUtils.parseAndCache(mock); |
| 152 | + assertThat(matcher.matches(mock)).isFalse(); |
| 153 | + } |
| 154 | + |
149 | 155 | MockHttpServletRequest request(String uri) { |
150 | 156 | MockHttpServletRequest request = new MockHttpServletRequest("GET", uri); |
151 | 157 | ServletRequestPathUtils.parseAndCache(request); |
|
0 commit comments