Search in sources :

Example 26 with MockServerWebExchange

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

the class WebSessionServerRequestCacheTests method saveRequestGetRequestWhenFaviconThenNotFound.

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

Example 27 with MockServerWebExchange

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

the class WebSessionServerRequestCacheTests method saveRequestGetRequestWithQueryParamsWhenGetThenFound.

@Test
public void saveRequestGetRequestWithQueryParamsWhenGetThenFound() {
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/secured/").queryParam("key", "value").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 28 with MockServerWebExchange

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

the class WebSessionServerRequestCacheTests method saveRequestRemoveRequestWhenThenFound.

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

Example 29 with MockServerWebExchange

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

the class WebSessionServerRequestCacheTests method removeRequestGetRequestWhenDefaultThenNotFound.

@Test
public void removeRequestGetRequestWhenDefaultThenNotFound() {
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/secured/"));
    this.cache.saveRequest(exchange).block();
    this.cache.removeMatchingRequest(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 30 with MockServerWebExchange

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

the class ReactiveCloudFoundrySecurityInterceptorTests method preHandleWhenAccessIsNotAllowedShouldReturnAccessDenied.

@Test
void preHandleWhenAccessIsNotAllowedShouldReturnAccessDenied() {
    given(this.securityService.getAccessLevel(mockAccessToken(), "my-app-id")).willReturn(Mono.just(AccessLevel.RESTRICTED));
    given(this.tokenValidator.validate(any())).willReturn(Mono.empty());
    MockServerWebExchange request = MockServerWebExchange.from(MockServerHttpRequest.get("/a").header(HttpHeaders.AUTHORIZATION, "bearer " + mockAccessToken()).build());
    StepVerifier.create(this.interceptor.preHandle(request, "/a")).consumeNextWith((response) -> assertThat(response.getStatus()).isEqualTo(Reason.ACCESS_DENIED.getStatus())).verifyComplete();
}
Also used : Base64Utils(org.springframework.util.Base64Utils) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) StepVerifier(reactor.test.StepVerifier) MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) Mock(org.mockito.Mock) HttpHeaders(org.springframework.http.HttpHeaders) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mono(reactor.core.publisher.Mono) Test(org.junit.jupiter.api.Test) HttpStatus(org.springframework.http.HttpStatus) AccessLevel(org.springframework.boot.actuate.autoconfigure.cloudfoundry.AccessLevel) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BDDMockito.given(org.mockito.BDDMockito.given) Reason(org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException.Reason) CloudFoundryAuthorizationException(org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException) 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