Skip to content

Commit fe9d596

Browse files
authored
Merge pull request #320 from italia/oidc-health-checks
fix: oidc healthcheck must correctly evaluate http response status code
2 parents 9519b72 + ae607af commit fe9d596

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

  • iam-proxy-italia-project-demo-examples/spid_cie_oidc_django

iam-proxy-italia-project-demo-examples/spid_cie_oidc_django/healthcheck.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ WGET_OPTS="--timeout=5 --tries=1 --no-check-certificate --spider --server-respon
77

88
function check_url {
99
local url=$1
10-
http_status=$(wget $WGET_OPTS "$url" 2>&1 | awk '/HTTP\// {print $2}' | tail -1)
11-
if [[ ! $http_status =~ ^[23] ]]; then
12-
echo "Error: wget failed for $url with status $http_status"
10+
local output http_status
11+
# wget exits non-zero on non-2xx; capture output anyway so we can enforce status == 200
12+
output=$(wget $WGET_OPTS "$url" 2>&1) || true
13+
http_status=$(echo "$output" | awk '/HTTP\// {code=$2} END {print code}')
14+
http_status=$(echo "$http_status" | tr -d '\r[:space:]')
15+
if [[ "$http_status" != "200" ]]; then
16+
echo "Error: expected HTTP 200 from $url, got '${http_status:-empty}'"
1317
exit 1
1418
fi
1519
}

0 commit comments

Comments
 (0)