mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-26 05:42:31 +00:00
Polish matchesRequireCsrfProtectionWhenNonStandardHTTPMethodIsUsed
Issue gh-8149
This commit is contained in:
parent
0f92415395
commit
4473dca022
@ -27,6 +27,7 @@ import org.springframework.http.MediaType;
|
|||||||
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
|
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
|
||||||
import org.springframework.mock.web.server.MockServerWebExchange;
|
import org.springframework.mock.web.server.MockServerWebExchange;
|
||||||
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher;
|
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher;
|
||||||
|
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher.MatchResult;
|
||||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@ -42,8 +43,6 @@ import static org.mockito.ArgumentMatchers.any;
|
|||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.springframework.mock.web.server.MockServerWebExchange.from;
|
import static org.springframework.mock.web.server.MockServerWebExchange.from;
|
||||||
import static org.springframework.web.reactive.function.BodyInserters.fromMultipartData;
|
import static org.springframework.web.reactive.function.BodyInserters.fromMultipartData;
|
||||||
|
|
||||||
@ -189,15 +188,13 @@ public class CsrfWebFilterTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchesRequireCSRFProtectionWhenNonStandardHTTPMethodIsUsed() {
|
// gh-8452
|
||||||
final String NON_STANDARD_HTTP_METHOD = "non-standard-http-method";
|
public void matchesRequireCsrfProtectionWhenNonStandardHTTPMethodIsUsed() {
|
||||||
MockServerWebExchange nonStandardHttpRequest = from(MockServerHttpRequest.method(HttpMethod.resolve(NON_STANDARD_HTTP_METHOD), "/"));
|
HttpMethod customHttpMethod = HttpMethod.resolve("non-standard-http-method");
|
||||||
|
MockServerWebExchange nonStandardHttpRequest = from(MockServerHttpRequest.method(customHttpMethod, "/"));
|
||||||
|
|
||||||
ServerWebExchangeMatcher serverWebExchangeMatcher = spy(CsrfWebFilter.DEFAULT_CSRF_MATCHER);
|
ServerWebExchangeMatcher serverWebExchangeMatcher = CsrfWebFilter.DEFAULT_CSRF_MATCHER;
|
||||||
serverWebExchangeMatcher.matches(nonStandardHttpRequest);
|
assertThat(serverWebExchangeMatcher.matches(nonStandardHttpRequest).map(MatchResult::isMatch).block()).isTrue();
|
||||||
|
|
||||||
verify(serverWebExchangeMatcher).matches(nonStandardHttpRequest);
|
|
||||||
assertThat(serverWebExchangeMatcher.matches(nonStandardHttpRequest).block().isMatch()).isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user