|
27 | 27 | import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
|
28 | 28 | import org.springframework.mock.web.server.MockServerWebExchange;
|
29 | 29 | import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher;
|
| 30 | +import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher.MatchResult; |
30 | 31 | import org.springframework.test.web.reactive.server.WebTestClient;
|
31 | 32 | import org.springframework.web.bind.annotation.RequestMapping;
|
32 | 33 | import org.springframework.web.bind.annotation.RestController;
|
|
42 | 43 | import static org.mockito.Mockito.mock;
|
43 | 44 | import static org.mockito.Mockito.verifyZeroInteractions;
|
44 | 45 | import static org.mockito.Mockito.when;
|
45 |
| -import static org.mockito.Mockito.verify; |
46 |
| -import static org.mockito.Mockito.spy; |
47 | 46 | import static org.springframework.mock.web.server.MockServerWebExchange.from;
|
48 | 47 | import static org.springframework.web.reactive.function.BodyInserters.fromMultipartData;
|
49 | 48 |
|
@@ -189,15 +188,13 @@ public void filterWhenPostAndEstablishedCsrfTokenAndHeaderValidTokenThenContinue
|
189 | 188 | }
|
190 | 189 |
|
191 | 190 | @Test
|
192 |
| - public void matchesRequireCSRFProtectionWhenNonStandardHTTPMethodIsUsed() { |
193 |
| - final String NON_STANDARD_HTTP_METHOD = "non-standard-http-method"; |
194 |
| - MockServerWebExchange nonStandardHttpRequest = from(MockServerHttpRequest.method(HttpMethod.resolve(NON_STANDARD_HTTP_METHOD), "/")); |
| 191 | + // gh-8452 |
| 192 | + public void matchesRequireCsrfProtectionWhenNonStandardHTTPMethodIsUsed() { |
| 193 | + HttpMethod customHttpMethod = HttpMethod.resolve("non-standard-http-method"); |
| 194 | + MockServerWebExchange nonStandardHttpRequest = from(MockServerHttpRequest.method(customHttpMethod, "/")); |
195 | 195 |
|
196 |
| - ServerWebExchangeMatcher serverWebExchangeMatcher = spy(CsrfWebFilter.DEFAULT_CSRF_MATCHER); |
197 |
| - serverWebExchangeMatcher.matches(nonStandardHttpRequest); |
198 |
| - |
199 |
| - verify(serverWebExchangeMatcher).matches(nonStandardHttpRequest); |
200 |
| - assertThat(serverWebExchangeMatcher.matches(nonStandardHttpRequest).block().isMatch()).isTrue(); |
| 196 | + ServerWebExchangeMatcher serverWebExchangeMatcher = CsrfWebFilter.DEFAULT_CSRF_MATCHER; |
| 197 | + assertThat(serverWebExchangeMatcher.matches(nonStandardHttpRequest).map(MatchResult::isMatch).block()).isTrue(); |
201 | 198 | }
|
202 | 199 |
|
203 | 200 | @Test
|
|
0 commit comments