Skip to content

Commit dceba9d

Browse files
committed
fix: configure actuator health endpoint for smoke tests
1 parent 4ce88e5 commit dceba9d

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

scripts/smoke-test.sh

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,22 @@ echo "Starting smoke tests against $SERVICE_URL..."
1010
# Function to check health
1111
check_health() {
1212
local url="$1/actuator/health"
13-
local response=$(curl -s -o /dev/null -w "%{http_code}" "$url")
1413

15-
if [ "$response" == "200" ]; then
16-
return 0
14+
# Get HTTP response code and body
15+
local response=$(curl -s -w "\n%{http_code}" "$url")
16+
local body=$(echo "$response" | sed '$d')
17+
local http_code=$(echo "$response" | tail -n1)
18+
19+
if [ "$http_code" == "200" ]; then
20+
# Check if status is UP
21+
if echo "$body" | grep -q '"status":"UP"'; then
22+
return 0
23+
else
24+
echo "Health check returned 200 but status is not UP: $body"
25+
return 1
26+
fi
1727
else
28+
echo "Health check returned HTTP $http_code"
1829
return 1
1930
fi
2031
}
@@ -23,10 +34,12 @@ check_health() {
2334
echo "Waiting for service to be up..."
2435
for ((i=1; i<=MAX_RETRIES; i++)); do
2536
if check_health "$SERVICE_URL"; then
26-
echo "✅ Service is UP!"
37+
echo "✅ Service is UP and healthy!"
2738

28-
# Verify specific status in JSON response if needed (optional enhancement)
29-
# curl -s "$SERVICE_URL/actuator/health" | grep "UP"
39+
# Print health details
40+
echo "Health endpoint response:"
41+
curl -s "$SERVICE_URL/actuator/health" | head -c 500
42+
echo ""
3043

3144
exit 0
3245
fi
@@ -35,4 +48,6 @@ for ((i=1; i<=MAX_RETRIES; i++)); do
3548
done
3649

3750
echo "❌ Service failed to start within timeout."
51+
echo "Final health check attempt:"
52+
curl -s "$SERVICE_URL/actuator/health" || echo "Could not reach service"
3853
exit 1

src/main/java/com/CSO2/user_identity_service/config/SecurityConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
3838
http.csrf(csrf -> csrf.disable())
3939
.authorizeHttpRequests(auth -> auth
4040
.requestMatchers("/api/auth/**").permitAll()
41+
.requestMatchers("/actuator/**").permitAll()
4142
.requestMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html").permitAll()
4243
.anyRequest().authenticated())
4344
.sessionManagement(session -> session

src/main/resources/application.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ jwt.private-key=${JWT_PRIVATE_KEY:-----BEGIN PRIVATE KEY-----\nMIIJQgIBADANBgkqh
1212
jwt.public-key=${JWT_PUBLIC_KEY:-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAz/l1I3aP7xVJ0q+/C8Xx\nDBE2KzIOnd630THrmPgx6nmUX5AOPh6H46Oc9nBnGFXwQ2I5n+jPXUUz84RKxk+x\nBYJSiXpyNQLLnCB2pVIMIb5us++X59AFzSMpf7NfG0Nnr9kTiiGlbehQPjkiY+OK\nd5bTOd8JRya6yNZC/uxPrKWzvkEw5+hvvYY3xKeF11HffhTfD2ppayRaXsvOoH+P\na6K9iBumye32la1/HV2llXyU3nt7iX668it1m4T/Z4LrJMJ7RqZKBqFGb4HXG5wg\njGdthFXP1BoyhIzAkv4FjuZYztxa6RH/ErVpu+TsAeYO8ioVes0SN/+SiJQVSB4N\ntkzypwgj+Szf2BaC2xqG8pWDSWL9Homix1d7oV+JK44frLXpom2/MwCr1K0exJcS\nVraKPTvCDwobfs/Qa28Hs5KJ9MUOP8OfvdAkVVcCBgXPyl918UR8+DdGHcjFHmog\ndsLyCTdSynnWm60Bw/rVpnvIW+F1KfRNpgRKbPagiLsywXLt8IMuwdvKGbvXyu1H\nTQc6NZJjSMoUidJqzkHDBXckoRjRbbP1FU2PYE01eI2mfSgriiBcCMFqIYEfADRm\nxCrlEWuBRQ3ZGqX4tQVmS9EvhTBqWc7PY90lbyfRQyY7QJjcD0+MXwIQRhYh2xRR\n/t2w0p2Fm5nMz5rnE/ZONy0CAwEAAQ==\n-----END PUBLIC KEY-----}
1313
jwt.expiration=${JWT_EXPIRATION:86400000}
1414
jwt.refresh-expiration=${JWT_REFRESH_EXPIRATION:604800000}
15+
16+
# Actuator Configuration
17+
management.endpoints.web.exposure.include=health,info
18+
management.endpoint.health.show-details=always

0 commit comments

Comments
 (0)