Skip to content

Commit

Permalink
✅ gateway add SecurityConfiguration test
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhir committed Jul 30, 2024
1 parent 6957c56 commit c705cef
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package de.muenchen.oss.refarch.gateway.configuration;

import static de.muenchen.oss.refarch.gateway.TestConstants.SPRING_TEST_PROFILE;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.reactive.server.WebTestClient;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWebTestClient
@AutoConfigureObservability
@ActiveProfiles(profiles = { SPRING_TEST_PROFILE })
public class SecurityConfigurationTest {
@Autowired
WebTestClient api;

@Test
void accessSecuredResourceRootThenUnauthorized() {
// api.get().uri("/").exchange().expectStatus().isUnauthorized();
// 302 is returned instead of 401 because auf cookie session
api.get().uri("/").exchange().expectStatus().isFound();
}

@Test
void accessSecuredResourceClientsThenUnauthorized() {
api.get().uri("/clients/test").exchange().expectStatus().isUnauthorized();
}

@Test
void accessUnsecuredResourceActuatorHealthThenOk() {
api.get().uri("/actuator/health").exchange().expectStatus().isOk();
}

@Test
void accessUnsecuredResourceActuatorHealthLivenessThenOk() {
api.get().uri("/actuator/health/liveness").exchange().expectStatus().isOk();
}

@Test
void accessUnsecuredResourceActuatorHealthReadinessThenOk() {
api.get().uri("/actuator/health/readiness").exchange().expectStatus().isOk();
}

@Test
void accessUnsecuredResourceActuatorInfoThenOk() {
api.get().uri("/actuator/info").exchange().expectStatus().isOk();
}

@Test
void accessUnsecuredResourceActuatorMetricsThenOk() {
api.get().uri("/actuator/metrics").exchange().expectStatus().isOk();
}
}

0 comments on commit c705cef

Please sign in to comment.