fix ArchitectureTest by moving HsadminNgApplicationIntegrationTest to WebSecurityConfigIntegrationTest

This commit is contained in:
Michael Hoennig 2024-12-03 09:17:59 +01:00
parent 15f97466f8
commit 593a3545d0
2 changed files with 16 additions and 3 deletions

View File

@ -16,6 +16,7 @@ public class WebSecurityConfig {
public SecurityFilterChain securityFilterChain(final HttpSecurity http) throws Exception {
return http
.authorizeHttpRequests(authorize -> authorize
.requestMatchers("/api/**").permitAll() // TODO.impl: implement authentication
.requestMatchers("/actuator/**").permitAll()
.anyRequest().authenticated()
)

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng;
package net.hostsharing.hsadminng.config;
import java.util.Map;
@ -14,8 +14,12 @@ import org.springframework.test.context.TestPropertySource;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = {"management.port=0"})
class HsadminNgApplicationIntegrationTest {
@TestPropertySource(properties = {"management.port=0", "server.port=0"})
// IMPORTANT: To test prod config, do not use test profile!
class WebSecurityConfigIntegrationTest {
@Value("${local.server.port}")
private int serverPort;
@Value("${local.management.port}")
private int managementPort;
@ -23,6 +27,14 @@ class HsadminNgApplicationIntegrationTest {
@Autowired
private TestRestTemplate restTemplate;
@Test
public void shouldSupportPingEndpoint() {
final var result = this.restTemplate.getForEntity(
"http://localhost:" + this.serverPort + "/api/ping", String.class);
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getBody()).startsWith("pong");
}
@Test
public void shouldSupportActuatorEndpoint() {
final var result = this.restTemplate.getForEntity(