Search in sources :

Example 96 with WebTestClient

use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.

the class MvcEndpointRequestIntegrationTests method toAnyEndpointShouldMatchServletEndpoint.

@Test
void toAnyEndpointShouldMatchServletEndpoint() {
    getContextRunner().withPropertyValues("spring.security.user.password=password", "management.endpoints.web.exposure.include=se1").run((context) -> {
        WebTestClient webTestClient = getWebTestClient(context);
        webTestClient.get().uri("/actuator/se1").exchange().expectStatus().isUnauthorized();
        webTestClient.get().uri("/actuator/se1").header("Authorization", getBasicAuth()).exchange().expectStatus().isOk();
        webTestClient.get().uri("/actuator/se1/list").exchange().expectStatus().isUnauthorized();
        webTestClient.get().uri("/actuator/se1/list").header("Authorization", getBasicAuth()).exchange().expectStatus().isOk();
    });
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) Test(org.junit.jupiter.api.Test)

Example 97 with WebTestClient

use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.

the class DefaultErrorWebExceptionHandlerIntegrationTests method neverIncludeStackTrace.

@Test
void neverIncludeStackTrace() {
    this.contextRunner.withPropertyValues("server.error.include-exception=true", "server.error.include-stacktrace=never").run((context) -> {
        WebTestClient client = getWebClient(context);
        client.get().uri("/?trace=true").exchange().expectStatus().isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR).expectBody().jsonPath("status").isEqualTo("500").jsonPath("error").isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()).jsonPath("exception").isEqualTo(IllegalStateException.class.getName()).jsonPath("trace").doesNotExist().jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId());
    });
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) Test(org.junit.jupiter.api.Test)

Example 98 with WebTestClient

use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.

the class DefaultErrorWebExceptionHandlerIntegrationTests method defaultErrorAttributesSubclassUsingDelegation.

@Test
void defaultErrorAttributesSubclassUsingDelegation() {
    this.contextRunner.withUserConfiguration(CustomErrorAttributesWithDelegation.class).run((context) -> {
        WebTestClient client = getWebClient(context);
        client.get().uri("/badRequest").exchange().expectStatus().isBadRequest().expectBody().jsonPath("status").isEqualTo("400").jsonPath("error").isEqualTo("custom error").jsonPath("newAttribute").isEqualTo("value").jsonPath("path").doesNotExist();
    });
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) Test(org.junit.jupiter.api.Test)

Example 99 with WebTestClient

use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.

the class DefaultErrorWebExceptionHandlerIntegrationTests method responseCommitted.

@Test
void responseCommitted() {
    this.contextRunner.run((context) -> {
        WebTestClient client = getWebClient(context);
        assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> client.get().uri("/commit").exchange().expectStatus()).withCauseInstanceOf(FailureAfterResponseCompletedException.class).withMessageContaining("Error occurred after response was completed");
    });
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) FailureAfterResponseCompletedException(org.springframework.test.web.reactive.server.HttpHandlerConnector.FailureAfterResponseCompletedException) Test(org.junit.jupiter.api.Test)

Example 100 with WebTestClient

use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.

the class DefaultErrorWebExceptionHandlerIntegrationTests method seriesStatusTemplateErrorPage.

@Test
void seriesStatusTemplateErrorPage() {
    this.contextRunner.withPropertyValues("server.error.whitelabel.enabled=false", "spring.mustache.prefix=" + getErrorTemplatesLocation()).run((context) -> {
        WebTestClient client = getWebClient(context);
        String body = client.get().uri("/badRequest").accept(MediaType.TEXT_HTML).exchange().expectStatus().isBadRequest().expectBody(String.class).returnResult().getResponseBody();
        assertThat(body).contains("4xx page");
    });
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) Test(org.junit.jupiter.api.Test)

Aggregations

WebTestClient (org.springframework.test.web.reactive.server.WebTestClient)165 Test (org.junit.jupiter.api.Test)159 SecurityWebFilterChain (org.springframework.security.web.server.SecurityWebFilterChain)44 WebTestClientBuilder (org.springframework.security.test.web.reactive.server.WebTestClientBuilder)34 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)31 Authentication (org.springframework.security.core.Authentication)28 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)27 WebDriver (org.openqa.selenium.WebDriver)26 Mono (reactor.core.publisher.Mono)25 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)23 ServerSecurityContextRepository (org.springframework.security.web.server.context.ServerSecurityContextRepository)22 ReactiveAuthenticationManager (org.springframework.security.authentication.ReactiveAuthenticationManager)21 WebFilterChainProxy (org.springframework.security.web.server.WebFilterChainProxy)21 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)20 BDDMockito.given (org.mockito.BDDMockito.given)20 Mockito.verify (org.mockito.Mockito.verify)20 GetMapping (org.springframework.web.bind.annotation.GetMapping)19 WebFilter (org.springframework.web.server.WebFilter)18 SecurityContext (org.springframework.security.core.context.SecurityContext)17 RestController (org.springframework.web.bind.annotation.RestController)17