Search in sources :

Example 91 with MockServerWebExchange

use of org.springframework.mock.web.server.MockServerWebExchange in project spring-security by spring-projects.

the class CookieServerRequestCacheTests method getRedirectUriWhenNoCookieThenRedirectUriIsNull.

@Test
public void getRedirectUriWhenNoCookieThenRedirectUriIsNull() {
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/secured/").accept(MediaType.TEXT_HTML));
    URI redirectUri = this.cache.getRedirectUri(exchange).block();
    assertThat(redirectUri).isNull();
}
Also used : MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 92 with MockServerWebExchange

use of org.springframework.mock.web.server.MockServerWebExchange in project spring-security by spring-projects.

the class WebSessionServerRequestCacheTests method saveRequestGetRequestWhenPostThenNotFound.

@Test
public void saveRequestGetRequestWhenPostThenNotFound() {
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/secured/"));
    this.cache.saveRequest(exchange).block();
    assertThat(this.cache.getRedirectUri(exchange).block()).isNull();
}
Also used : MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 93 with MockServerWebExchange

use of org.springframework.mock.web.server.MockServerWebExchange in project spring-security by spring-projects.

the class WebSessionServerRequestCacheTests method saveRequestGetRequestWhenGetThenFound.

@Test
public void saveRequestGetRequestWhenGetThenFound() {
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/secured/").accept(MediaType.TEXT_HTML));
    this.cache.saveRequest(exchange).block();
    URI saved = this.cache.getRedirectUri(exchange).block();
    assertThat(saved).isEqualTo(exchange.getRequest().getURI());
}
Also used : MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 94 with MockServerWebExchange

use of org.springframework.mock.web.server.MockServerWebExchange in project spring-security by spring-projects.

the class LoginPageGeneratingWebFilterTests method filterWhenLoginWithContextPathThenActionContainsContextPath.

@Test
public void filterWhenLoginWithContextPathThenActionContainsContextPath() throws Exception {
    LoginPageGeneratingWebFilter filter = new LoginPageGeneratingWebFilter();
    filter.setFormLoginEnabled(true);
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/test/login").contextPath("/test"));
    filter.filter(exchange, (e) -> Mono.empty()).block();
    assertThat(exchange.getResponse().getBodyAsString().block()).contains("action=\"/test/login\"");
}
Also used : Test(org.junit.jupiter.api.Test) MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mono(reactor.core.publisher.Mono) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Aggregations

MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)94 Test (org.junit.jupiter.api.Test)81 MockServerHttpRequest (org.springframework.mock.http.server.reactive.MockServerHttpRequest)44 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)27 Mono (reactor.core.publisher.Mono)26 BeforeEach (org.junit.jupiter.api.BeforeEach)22 StepVerifier (reactor.test.StepVerifier)21 ServerWebExchange (org.springframework.web.server.ServerWebExchange)15 Duration (java.time.Duration)14 ErrorAttributes (org.springframework.boot.web.reactive.error.ErrorAttributes)13 HandlerMethod (org.springframework.web.method.HandlerMethod)13 Timed (io.micrometer.core.annotation.Timed)12 MockClock (io.micrometer.core.instrument.MockClock)12 Tag (io.micrometer.core.instrument.Tag)12 SimpleConfig (io.micrometer.core.instrument.simple.SimpleConfig)12 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)12 EOFException (java.io.EOFException)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 AutoTimer (org.springframework.boot.actuate.metrics.AutoTimer)12 ResponseCookie (org.springframework.http.ResponseCookie)12