use of org.springframework.mock.web.server.MockServerWebExchange in project spring-security by spring-projects.
the class CookieServerCsrfTokenRepositoryTests method saveTokenWhenSslInfoPresentThenSecure.
@Test
public void saveTokenWhenSslInfoPresentThenSecure() {
this.request.sslInfo(new MockSslInfo());
MockServerWebExchange exchange = MockServerWebExchange.from(this.request);
this.csrfTokenRepository.saveToken(exchange, createToken()).block();
ResponseCookie cookie = exchange.getResponse().getCookies().getFirst(this.expectedCookieName);
assertThat(cookie).isNotNull();
assertThat(cookie.isSecure()).isTrue();
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-security by spring-projects.
the class CookieServerCsrfTokenRepositoryTests method saveTokenWhenNoSubscriptionThenNotWritten.
@Test
public void saveTokenWhenNoSubscriptionThenNotWritten() {
MockServerWebExchange exchange = MockServerWebExchange.from(this.request);
this.csrfTokenRepository.saveToken(exchange, createToken());
assertThat(exchange.getResponse().getCookies().getFirst(this.expectedCookieName)).isNull();
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-security by spring-projects.
the class CsrfWebFilterTests method matchesRequireCsrfProtectionWhenNonStandardHTTPMethodIsUsed.
@Test
public // gh-8452
void matchesRequireCsrfProtectionWhenNonStandardHTTPMethodIsUsed() {
MockServerWebExchange nonStandardHttpExchange = MockServerWebExchange.from(MockServerHttpRequest.method("non-standard-http-method", "/"));
ServerWebExchangeMatcher serverWebExchangeMatcher = CsrfWebFilter.DEFAULT_CSRF_MATCHER;
assertThat(serverWebExchangeMatcher.matches(nonStandardHttpExchange).map(MatchResult::isMatch).block()).isTrue();
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-security by spring-projects.
the class CsrfWebFilterTests method doFilterWhenSkipExchangeInvokedThenSkips.
@Test
public void doFilterWhenSkipExchangeInvokedThenSkips() {
PublisherProbe<Void> chainResult = PublisherProbe.empty();
given(this.chain.filter(any())).willReturn(chainResult.mono());
ServerWebExchangeMatcher matcher = mock(ServerWebExchangeMatcher.class);
this.csrfFilter.setRequireCsrfProtectionMatcher(matcher);
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/post").build());
CsrfWebFilter.skipExchange(exchange);
this.csrfFilter.filter(exchange, this.chain).block();
verifyZeroInteractions(matcher);
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-security by spring-projects.
the class LoginPageGeneratingWebFilterTests method filterWhenLoginWithNoContextPathThenActionDoesNotContainsContextPath.
@Test
public void filterWhenLoginWithNoContextPathThenActionDoesNotContainsContextPath() throws Exception {
LoginPageGeneratingWebFilter filter = new LoginPageGeneratingWebFilter();
filter.setFormLoginEnabled(true);
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/login"));
filter.filter(exchange, (e) -> Mono.empty()).block();
assertThat(exchange.getResponse().getBodyAsString().block()).contains("action=\"/login\"");
}
Aggregations