Skip to content

Commit

Permalink
Mock request with non-standard HTTP method in test
Browse files Browse the repository at this point in the history
Fixes gh-8594
  • Loading branch information
eleftherias committed May 26, 2020
1 parent 5bcfaaf commit 2ebbb6f
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.mock.web.server.MockServerWebExchange;
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher;
Expand Down Expand Up @@ -190,11 +190,12 @@ public void filterWhenPostAndEstablishedCsrfTokenAndHeaderValidTokenThenContinue
@Test
// gh-8452
public void matchesRequireCsrfProtectionWhenNonStandardHTTPMethodIsUsed() {
HttpMethod customHttpMethod = HttpMethod.resolve("non-standard-http-method");
MockServerWebExchange nonStandardHttpRequest = from(MockServerHttpRequest.method(customHttpMethod, "/"));
ServerHttpRequest nonStandardHttpRequest = mock(ServerHttpRequest.class);
ServerWebExchange nonStandardHttpExchange = mock(ServerWebExchange.class);
when(nonStandardHttpExchange.getRequest()).thenReturn(nonStandardHttpRequest);

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
Expand Down

0 comments on commit 2ebbb6f

Please sign in to comment.