Validate our own tests work with JUnit5 and the vintage engine
Closes gh-14737 Co-authored-by: Stephane Nicoll <snicoll@pivotal.io>
This commit is contained in:
committed by
Stephane Nicoll
parent
d9f339a1b6
commit
1db1c8b03c
@@ -18,8 +18,7 @@ package sample.secure.webflux;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.security.reactive.EndpointRequest;
|
||||
@@ -33,7 +32,6 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.web.server.ServerHttpSecurity;
|
||||
import org.springframework.security.web.server.SecurityWebFilterChain;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -43,12 +41,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
properties = { "management.server.port=0" },
|
||||
classes = { ManagementPortSampleSecureWebFluxTests.SecurityConfiguration.class,
|
||||
SampleSecureWebFluxApplication.class })
|
||||
public class ManagementPortSampleSecureWebFluxTests {
|
||||
class ManagementPortSampleSecureWebFluxTests {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
@@ -60,14 +57,14 @@ public class ManagementPortSampleSecureWebFluxTests {
|
||||
private WebTestClient webClient;
|
||||
|
||||
@Test
|
||||
public void testHome() {
|
||||
void testHome() {
|
||||
this.webClient.get().uri("http://localhost:" + this.port, String.class)
|
||||
.header("Authorization", "basic " + getBasicAuth()).exchange()
|
||||
.expectStatus().isOk().expectBody(String.class).isEqualTo("Hello user");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void actuatorPathOnMainPortShouldNotMatch() {
|
||||
void actuatorPathOnMainPortShouldNotMatch() {
|
||||
this.webClient.get()
|
||||
.uri("http://localhost:" + this.port + "/actuator", String.class)
|
||||
.exchange().expectStatus().isUnauthorized();
|
||||
@@ -77,7 +74,7 @@ public class ManagementPortSampleSecureWebFluxTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecureActuator() {
|
||||
void testSecureActuator() {
|
||||
this.webClient.get()
|
||||
.uri("http://localhost:" + this.managementPort + "/actuator/env",
|
||||
String.class)
|
||||
@@ -85,7 +82,7 @@ public class ManagementPortSampleSecureWebFluxTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsecureActuator() {
|
||||
void testInsecureActuator() {
|
||||
String responseBody = this.webClient.get()
|
||||
.uri("http://localhost:" + this.managementPort + "/actuator/health",
|
||||
String.class)
|
||||
|
||||
@@ -18,14 +18,12 @@ package sample.secure.webflux;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
/**
|
||||
@@ -33,47 +31,46 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
properties = "management.endpoint.health.show-details=never")
|
||||
public class SampleSecureWebFluxApplicationTests {
|
||||
class SampleSecureWebFluxApplicationTests {
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webClient;
|
||||
|
||||
@Test
|
||||
public void userDefinedMappingsSecureByDefault() {
|
||||
void userDefinedMappingsSecureByDefault() {
|
||||
this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange()
|
||||
.expectStatus().isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthInsecureByDefault() {
|
||||
void healthInsecureByDefault() {
|
||||
this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void infoInsecureByDefault() {
|
||||
void infoInsecureByDefault() {
|
||||
this.webClient.get().uri("/actuator/info").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void otherActuatorsSecureByDefault() {
|
||||
void otherActuatorsSecureByDefault() {
|
||||
this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isUnauthorized();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userDefinedMappingsAccessibleOnLogin() {
|
||||
void userDefinedMappingsAccessibleOnLogin() {
|
||||
this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "basic " + getBasicAuth()).exchange()
|
||||
.expectBody(String.class).isEqualTo("Hello user");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void actuatorsAccessibleOnLogin() {
|
||||
void actuatorsAccessibleOnLogin() {
|
||||
this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "basic " + getBasicAuth()).exchange()
|
||||
.expectBody(String.class).isEqualTo("{\"status\":\"UP\"}");
|
||||
|
||||
@@ -18,8 +18,7 @@ package sample.secure.webflux;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.security.reactive.EndpointRequest;
|
||||
@@ -34,7 +33,6 @@ import org.springframework.security.config.web.server.ServerHttpSecurity;
|
||||
import org.springframework.security.core.userdetails.MapReactiveUserDetailsService;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.web.server.SecurityWebFilterChain;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
/**
|
||||
@@ -42,23 +40,22 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { SampleSecureWebFluxCustomSecurityTests.SecurityConfiguration.class,
|
||||
SampleSecureWebFluxApplication.class })
|
||||
public class SampleSecureWebFluxCustomSecurityTests {
|
||||
class SampleSecureWebFluxCustomSecurityTests {
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webClient;
|
||||
|
||||
@Test
|
||||
public void userDefinedMappingsSecure() {
|
||||
void userDefinedMappingsSecure() {
|
||||
this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange()
|
||||
.expectStatus().isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthAndInfoDoNotRequireAuthentication() {
|
||||
void healthAndInfoDoNotRequireAuthentication() {
|
||||
this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk();
|
||||
this.webClient.get().uri("/actuator/info").accept(MediaType.APPLICATION_JSON)
|
||||
@@ -66,34 +63,34 @@ public class SampleSecureWebFluxCustomSecurityTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void actuatorsSecuredByRole() {
|
||||
void actuatorsSecuredByRole() {
|
||||
this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "basic " + getBasicAuth()).exchange()
|
||||
.expectStatus().isForbidden();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void actuatorsAccessibleOnCorrectLogin() {
|
||||
void actuatorsAccessibleOnCorrectLogin() {
|
||||
this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "basic " + getBasicAuthForAdmin()).exchange()
|
||||
.expectStatus().isOk();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void actuatorExcludedFromEndpointRequestMatcher() {
|
||||
void actuatorExcludedFromEndpointRequestMatcher() {
|
||||
this.webClient.get().uri("/actuator/mappings").accept(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "basic " + getBasicAuth()).exchange()
|
||||
.expectStatus().isOk();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void staticResourceShouldBeAccessible() {
|
||||
void staticResourceShouldBeAccessible() {
|
||||
this.webClient.get().uri("/css/bootstrap.min.css")
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void actuatorLinksIsSecure() {
|
||||
void actuatorLinksIsSecure() {
|
||||
this.webClient.get().uri("/actuator").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isUnauthorized();
|
||||
this.webClient.get().uri("/actuator").accept(MediaType.APPLICATION_JSON)
|
||||
|
||||
Reference in New Issue
Block a user