use of org.springframework.mock.web.server.MockServerWebExchange in project spring-security by spring-projects.
the class CookieServerRequestCacheTests method removeMatchingRequestThenRedirectUriCookieExpired.
@Test
public void removeMatchingRequestThenRedirectUriCookieExpired() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/secured/").accept(MediaType.TEXT_HTML).cookie(new HttpCookie("REDIRECT_URI", "/secured/")));
this.cache.removeMatchingRequest(exchange).block();
MultiValueMap<String, ResponseCookie> cookies = exchange.getResponse().getCookies();
ResponseCookie cookie = cookies.getFirst("REDIRECT_URI");
assertThat(cookie).isNotNull();
assertThat(cookie.toString()).isEqualTo("REDIRECT_URI=; Path=/; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; SameSite=Lax");
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-security by spring-projects.
the class CookieServerRequestCacheTests method saveRequestWhenGetRequestThenRequestUriInCookie.
@Test
public void saveRequestWhenGetRequestThenRequestUriInCookie() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/secured/").accept(MediaType.TEXT_HTML));
this.cache.saveRequest(exchange).block();
MultiValueMap<String, ResponseCookie> cookies = exchange.getResponse().getCookies();
assertThat(cookies.size()).isEqualTo(1);
ResponseCookie cookie = cookies.getFirst("REDIRECT_URI");
assertThat(cookie).isNotNull();
String encodedRedirectUrl = Base64.getEncoder().encodeToString("/secured/".getBytes());
assertThat(cookie.toString()).isEqualTo("REDIRECT_URI=" + encodedRedirectUrl + "; Path=/; HttpOnly; SameSite=Lax");
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-security by spring-projects.
the class CookieServerRequestCacheTests method saveRequestWhenPostRequestThenNoCookie.
@Test
public void saveRequestWhenPostRequestThenNoCookie() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/secured/"));
this.cache.saveRequest(exchange).block();
MultiValueMap<String, ResponseCookie> cookies = exchange.getResponse().getCookies();
assertThat(cookies).isEmpty();
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-security by spring-projects.
the class CookieServerRequestCacheTests method saveRequestWhenGetRequestFaviconThenNoCookie.
@Test
public void saveRequestWhenGetRequestFaviconThenNoCookie() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/favicon.png").accept(MediaType.TEXT_HTML));
this.cache.saveRequest(exchange).block();
MultiValueMap<String, ResponseCookie> cookies = exchange.getResponse().getCookies();
assertThat(cookies).isEmpty();
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-security by spring-projects.
the class WebSessionServerRequestCacheTests method saveRequestGetRequestWhenPostAndCustomMatcherThenFound.
@Test
public void saveRequestGetRequestWhenPostAndCustomMatcherThenFound() {
this.cache.setSaveRequestMatcher((e) -> ServerWebExchangeMatcher.MatchResult.match());
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/secured/"));
this.cache.saveRequest(exchange).block();
URI saved = this.cache.getRedirectUri(exchange).block();
assertThat(saved).isEqualTo(exchange.getRequest().getURI());
}
Aggregations