Mock request with non-standard HTTP method in test

Fixes gh-8594
This commit is contained in:
Eleftheria Stein 2020-05-26 10:16:56 -04:00
parent f1db7167cb
commit 0a42aa26c8
1 changed files with 5 additions and 4 deletions

View File

@ -21,9 +21,9 @@ import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpRequest;
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;
@ -190,11 +190,12 @@ public class CsrfWebFilterTests {
@Test @Test
// gh-8452 // gh-8452
public void matchesRequireCsrfProtectionWhenNonStandardHTTPMethodIsUsed() { public void matchesRequireCsrfProtectionWhenNonStandardHTTPMethodIsUsed() {
HttpMethod customHttpMethod = HttpMethod.resolve("non-standard-http-method"); ServerHttpRequest nonStandardHttpRequest = mock(ServerHttpRequest.class);
MockServerWebExchange nonStandardHttpRequest = from(MockServerHttpRequest.method(customHttpMethod, "/")); ServerWebExchange nonStandardHttpExchange = mock(ServerWebExchange.class);
when(nonStandardHttpExchange.getRequest()).thenReturn(nonStandardHttpRequest);
ServerWebExchangeMatcher serverWebExchangeMatcher = CsrfWebFilter.DEFAULT_CSRF_MATCHER; ServerWebExchangeMatcher serverWebExchangeMatcher = CsrfWebFilter.DEFAULT_CSRF_MATCHER;
assertThat(serverWebExchangeMatcher.matches(nonStandardHttpRequest).map(MatchResult::isMatch).block()).isTrue(); assertThat(serverWebExchangeMatcher.matches(nonStandardHttpExchange).map(MatchResult::isMatch).block()).isTrue();
} }
@Test @Test