Search in sources :

Example 26 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-security by spring-projects.

the class OidcClientInitiatedServerLogoutSuccessHandlerTests method logoutWhenUsingPostLogoutRedirectUriTemplateThenBuildsItForRedirect.

@Test
public void logoutWhenUsingPostLogoutRedirectUriTemplateThenBuildsItForRedirect() throws IOException, ServletException {
    OAuth2AuthenticationToken token = new OAuth2AuthenticationToken(TestOidcUsers.create(), AuthorityUtils.NO_AUTHORITIES, this.registration.getRegistrationId());
    given(this.exchange.getPrincipal()).willReturn(Mono.just(token));
    MockServerHttpRequest request = MockServerHttpRequest.get("https://rp.example.org/").build();
    given(this.exchange.getRequest()).willReturn(request);
    WebFilterExchange f = new WebFilterExchange(this.exchange, this.chain);
    this.handler.setPostLogoutRedirectUri("{baseUrl}");
    this.handler.onLogoutSuccess(f, token).block();
    assertThat(redirectedUrl(this.exchange)).isEqualTo("https://endpoint?" + "id_token_hint=id-token&" + "post_logout_redirect_uri=https://rp.example.org");
}
Also used : OAuth2AuthenticationToken(org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken) MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) WebFilterExchange(org.springframework.security.web.server.WebFilterExchange) Test(org.junit.jupiter.api.Test)

Example 27 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-boot by spring-projects.

the class DefaultErrorAttributesTests method getError.

@Test
void getError() {
    Error error = new OutOfMemoryError("Test error");
    MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();
    ServerRequest serverRequest = buildServerRequest(request, error);
    Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(serverRequest, ErrorAttributeOptions.of(Include.MESSAGE));
    assertThat(this.errorAttributes.getError(serverRequest)).isSameAs(error);
    assertThat(attributes.get("exception")).isNull();
    assertThat(attributes.get("message")).isEqualTo("Test error");
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) ObjectError(org.springframework.validation.ObjectError) ServerRequest(org.springframework.web.reactive.function.server.ServerRequest) Test(org.junit.jupiter.api.Test)

Example 28 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-boot by spring-projects.

the class DefaultErrorAttributesTests method includeTrace.

@Test
void includeTrace() {
    RuntimeException ex = new RuntimeException("Test");
    MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();
    Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(buildServerRequest(request, ex), ErrorAttributeOptions.of(Include.STACK_TRACE));
    assertThat(attributes.get("trace").toString()).startsWith("java.lang");
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) Test(org.junit.jupiter.api.Test)

Example 29 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-boot by spring-projects.

the class DefaultErrorAttributesTests method includeLogPrefix.

@Test
void includeLogPrefix() {
    MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();
    ServerRequest serverRequest = buildServerRequest(request, NOT_FOUND);
    Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(serverRequest, ErrorAttributeOptions.defaults());
    assertThat(attributes.get("requestId")).isEqualTo(serverRequest.exchange().getRequest().getId());
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) ServerRequest(org.springframework.web.reactive.function.server.ServerRequest) Test(org.junit.jupiter.api.Test)

Example 30 with MockServerHttpRequest

use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-boot by spring-projects.

the class DefaultErrorAttributesTests method includePath.

@Test
void includePath() {
    MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();
    Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(buildServerRequest(request, NOT_FOUND), ErrorAttributeOptions.defaults());
    assertThat(attributes.get("path")).isEqualTo("/test");
}
Also used : MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) Test(org.junit.jupiter.api.Test)

Aggregations

MockServerHttpRequest (org.springframework.mock.http.server.reactive.MockServerHttpRequest)75 Test (org.junit.jupiter.api.Test)40 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)35 Test (org.junit.Test)26 ServerWebExchange (org.springframework.web.server.ServerWebExchange)26 URI (java.net.URI)16 OAuth2AuthorizationRequest (org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest)11 HttpHeaders (org.springframework.http.HttpHeaders)9 BeforeEach (org.junit.jupiter.api.BeforeEach)7 ResponseStatusException (org.springframework.web.server.ResponseStatusException)7 AcceptHeaderLocaleContextResolver (org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver)6 Mono (reactor.core.publisher.Mono)6 InetSocketAddress (java.net.InetSocketAddress)5 Assertions.assertThatIllegalStateException (org.assertj.core.api.Assertions.assertThatIllegalStateException)5 Mockito.mock (org.mockito.Mockito.mock)5 ObjectError (org.springframework.validation.ObjectError)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)4 BDDMockito.given (org.mockito.BDDMockito.given)4