Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔒 security allow actuator probes #35

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http)
.pathMatchers(LOGOUT_SUCCESS_URL).permitAll()
.pathMatchers("/api/*/info",
"/actuator/health",
"/actuator/health/liveness",
"/actuator/health/readiness",
simonhir marked this conversation as resolved.
Show resolved Hide resolved
"/actuator/info",
"/actuator/metrics")
.permitAll()
Expand Down
2 changes: 1 addition & 1 deletion refarch-gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ management:
enabled-by-default: false
web:
exposure:
include: health, info, prometheus, livenessstate, readinessstate
include: health, info, prometheus, livenessState, readinessState
path-mapping:
prometheus: metrics
endpoint:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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() {
// 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();
}
}