Search in sources :

Example 56 with WebTestClient

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

the class AbstractEndpointRequestIntegrationTests method toLinksShouldMatch.

@Test
void toLinksShouldMatch() {
    getContextRunner().run((context) -> {
        WebTestClient webTestClient = getWebTestClient(context);
        webTestClient.get().uri("/actuator").exchange().expectStatus().isOk();
        webTestClient.get().uri("/actuator/").exchange().expectStatus().isOk();
    });
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) Test(org.junit.jupiter.api.Test)

Example 57 with WebTestClient

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

the class AbstractEndpointRequestIntegrationTests method toAllEndpointsShouldMatch.

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

Example 58 with WebTestClient

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

the class MvcEndpointRequestIntegrationTests method toEndpointWhenServletPathSetShouldMatch.

@Test
void toEndpointWhenServletPathSetShouldMatch() {
    getContextRunner().withPropertyValues("spring.mvc.servlet.path=/admin").run((context) -> {
        WebTestClient webTestClient = getWebTestClient(context);
        webTestClient.get().uri("/admin/actuator/e1").exchange().expectStatus().isOk();
    });
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) Test(org.junit.jupiter.api.Test)

Example 59 with WebTestClient

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

the class MvcEndpointRequestIntegrationTests method toLinksWhenServletPathSetShouldMatch.

@Test
void toLinksWhenServletPathSetShouldMatch() {
    getContextRunner().withPropertyValues("spring.mvc.servlet.path=/admin").run((context) -> {
        WebTestClient webTestClient = getWebTestClient(context);
        webTestClient.get().uri("/admin/actuator/").exchange().expectStatus().isOk();
        webTestClient.get().uri("/admin/actuator").exchange().expectStatus().isOk();
    });
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) Test(org.junit.jupiter.api.Test)

Example 60 with WebTestClient

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

the class MvcEndpointRequestIntegrationTests method toAnyEndpointWhenServletPathSetShouldMatchServletEndpoint.

@Test
void toAnyEndpointWhenServletPathSetShouldMatchServletEndpoint() {
    getContextRunner().withPropertyValues("spring.mvc.servlet.path=/admin", "spring.security.user.password=password", "management.endpoints.web.exposure.include=se1").run((context) -> {
        WebTestClient webTestClient = getWebTestClient(context);
        webTestClient.get().uri("/admin/actuator/se1").exchange().expectStatus().isUnauthorized();
        webTestClient.get().uri("/admin/actuator/se1").header("Authorization", getBasicAuth()).exchange().expectStatus().isOk();
        webTestClient.get().uri("/admin/actuator/se1/list").exchange().expectStatus().isUnauthorized();
        webTestClient.get().uri("/admin/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)

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