|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2017 the original author or authors. |
| 2 | + * Copyright 2002-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
20 | 20 | import org.junit.runner.RunWith;
|
21 | 21 | import org.mockito.Mock;
|
22 | 22 | import org.mockito.junit.MockitoJUnitRunner;
|
| 23 | + |
| 24 | +import org.springframework.http.HttpMethod; |
23 | 25 | import org.springframework.http.HttpStatus;
|
24 | 26 | import org.springframework.http.MediaType;
|
25 | 27 | import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
|
26 | 28 | import org.springframework.mock.web.server.MockServerWebExchange;
|
27 | 29 | import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher;
|
| 30 | +import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher.MatchResult; |
28 | 31 | import org.springframework.test.web.reactive.server.WebTestClient;
|
29 | 32 | import org.springframework.web.bind.annotation.RequestMapping;
|
30 | 33 | import org.springframework.web.bind.annotation.RestController;
|
|
45 | 48 |
|
46 | 49 | /**
|
47 | 50 | * @author Rob Winch
|
| 51 | + * @author Parikshit Dutta |
48 | 52 | * @since 5.0
|
49 | 53 | */
|
50 | 54 | @RunWith(MockitoJUnitRunner.class)
|
@@ -183,6 +187,16 @@ public void filterWhenPostAndEstablishedCsrfTokenAndHeaderValidTokenThenContinue
|
183 | 187 | chainResult.assertWasSubscribed();
|
184 | 188 | }
|
185 | 189 |
|
| 190 | + @Test |
| 191 | + // gh-8452 |
| 192 | + public void matchesRequireCsrfProtectionWhenNonStandardHTTPMethodIsUsed() { |
| 193 | + HttpMethod customHttpMethod = HttpMethod.resolve("non-standard-http-method"); |
| 194 | + MockServerWebExchange nonStandardHttpRequest = from(MockServerHttpRequest.method(customHttpMethod, "/")); |
| 195 | + |
| 196 | + ServerWebExchangeMatcher serverWebExchangeMatcher = CsrfWebFilter.DEFAULT_CSRF_MATCHER; |
| 197 | + assertThat(serverWebExchangeMatcher.matches(nonStandardHttpRequest).map(MatchResult::isMatch).block()).isTrue(); |
| 198 | + } |
| 199 | + |
186 | 200 | @Test
|
187 | 201 | public void doFilterWhenSkipExchangeInvokedThenSkips() {
|
188 | 202 | PublisherProbe<Void> chainResult = PublisherProbe.empty();
|
|
0 commit comments