The test route on the proxy Pi now points at the CMS host on port 5200. verify-deployment.sh gets a --cms mode that checks the exact security headers, caching, gzip only, a percent-encoded redirect, the 405 for POST, and the CMS routes. The deploy-test job uses it once the Gitea variable ASF_TEST_SERVED_BY_CMS is true. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
278 lines
9.8 KiB
Bash
278 lines
9.8 KiB
Bash
#!/usr/bin/env bash
|
|
# Controle na een deploy (BR-HST-18): wat de server teruggeeft moet gelijk zijn
|
|
# aan wat in dist staat. Een oude nginx-config die voor elk pad de homepage
|
|
# geeft (SPA-fallback) valt hier door de mand.
|
|
# Gebruik: verify-deployment.sh <basis-url> <dist-map> [--test] [--cms]
|
|
# --test: ook X-Robots-Tag, en gzip op de JavaScript is verplicht
|
|
# (zonder --test geeft ontbrekende gzip alleen een waarschuwing)
|
|
# --cms: de site wordt geserveerd door de CMS-host (Api.AndreaSlopFotografie)
|
|
# in plaats van nginx. Dan geldt ook: de CSP is exact gelijk aan
|
|
# $EXPECTED_CSP (verplicht, zie config/printCsp.ts), alle security
|
|
# headers staan met de exacte waarde op elk antwoord (pagina, asset,
|
|
# 301, 404, robots.txt), cachebeleid, alleen gzip (nooit br), een
|
|
# procentgecodeerd pad blijft gecodeerd, en /admin, /health en
|
|
# /api/v1/System/capabilities (zonder Offerings) antwoorden.
|
|
set -euo pipefail
|
|
|
|
if [ "$#" -lt 2 ] || [ "$#" -gt 4 ]; then
|
|
echo "Gebruik: $0 <basis-url> <dist-map> [--test] [--cms]" >&2
|
|
exit 2
|
|
fi
|
|
base="$1"
|
|
dist="$2"
|
|
test_mode=0
|
|
cms_mode=0
|
|
shift 2
|
|
for option in "$@"; do
|
|
case "$option" in
|
|
--test) test_mode=1 ;;
|
|
--cms) cms_mode=1 ;;
|
|
*)
|
|
echo "Onbekende optie: $option" >&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
done
|
|
if [ "$cms_mode" -eq 1 ] && [ -z "${EXPECTED_CSP:-}" ]; then
|
|
echo "--cms vraagt om EXPECTED_CSP (node config/printCsp.ts)" >&2
|
|
exit 2
|
|
fi
|
|
|
|
if ! [[ "$base" =~ ^https?://[^[:space:]]+$ ]]; then
|
|
echo "Ongeldige URL: '$base'" >&2
|
|
exit 2
|
|
fi
|
|
while [[ "$base" == */ ]]; do base="${base%/}"; done
|
|
if [ ! -d "$dist" ]; then
|
|
echo "Geen map: $dist" >&2
|
|
exit 2
|
|
fi
|
|
|
|
work="$(mktemp -d)"
|
|
trap 'rm -rf "$work"' EXIT
|
|
|
|
failures=0
|
|
fail() {
|
|
echo "FOUT: $1" >&2
|
|
failures=$((failures + 1))
|
|
}
|
|
|
|
# Haalt $base$1 op zonder redirects te volgen en zonder Accept-Encoding
|
|
# (curl stuurt er zelf geen). Bewaart status, headers en body in $work.
|
|
# Meer argumenten: extra curl-opties (bijvoorbeeld een header).
|
|
fetch() {
|
|
local path="$1"
|
|
shift
|
|
: > "$work/headers"
|
|
: > "$work/body"
|
|
# Geen verbinding of antwoord telt als fout; het script loopt door tot de
|
|
# samenvatting in plaats van af te breken
|
|
if ! status="$(curl -sS --max-time 30 -o "$work/body" -D "$work/headers" \
|
|
-w '%{http_code}' "$@" "$base$path")"; then
|
|
status="000"
|
|
fail "$path: geen antwoord van de server (curl faalde)"
|
|
fi
|
|
}
|
|
|
|
# Waarde van een header uit de laatst opgehaalde respons (hoofdletterongevoelig)
|
|
header() {
|
|
tr -d '\r' < "$work/headers" | grep -i "^$1:" | head -n 1 | cut -d: -f2- | sed 's/^[[:space:]]*//' || true
|
|
}
|
|
|
|
check_security_headers() {
|
|
local label="$1" name
|
|
local names=(Content-Security-Policy Strict-Transport-Security X-Content-Type-Options X-Frame-Options Referrer-Policy)
|
|
if [ "$test_mode" -eq 1 ]; then names+=(X-Robots-Tag); fi
|
|
for name in "${names[@]}"; do
|
|
if [ -z "$(header "$name")" ]; then
|
|
fail "$label: header $name ontbreekt"
|
|
fi
|
|
done
|
|
if [ "$cms_mode" -eq 1 ]; then check_exact_headers "$label"; fi
|
|
}
|
|
|
|
# Alleen met --cms: de CMS-host moet exact de waarden van de site sturen
|
|
# (geen drift tussen config/securityHeaders.ts en de host)
|
|
check_exact_headers() {
|
|
local label="$1"
|
|
local -A expected=(
|
|
[Content-Security-Policy]="$EXPECTED_CSP"
|
|
[Strict-Transport-Security]="max-age=31536000; includeSubDomains"
|
|
[X-Content-Type-Options]="nosniff"
|
|
[X-Frame-Options]="DENY"
|
|
[Referrer-Policy]="strict-origin-when-cross-origin"
|
|
)
|
|
local name actual
|
|
for name in "${!expected[@]}"; do
|
|
actual="$(header "$name")"
|
|
# Ontbrekend is hierboven al gemeld
|
|
if [ -n "$actual" ] && [ "$actual" != "${expected[$name]}" ]; then
|
|
fail "$label: header $name is '$actual', verwacht '${expected[$name]}'"
|
|
fi
|
|
done
|
|
if [ "$test_mode" -eq 1 ] && [ -n "$(header X-Robots-Tag)" ] && [ "$(header X-Robots-Tag)" != "noindex, nofollow" ]; then
|
|
fail "$label: header X-Robots-Tag is '$(header X-Robots-Tag)', verwacht 'noindex, nofollow'"
|
|
fi
|
|
}
|
|
|
|
# Een 200 met de bytes van het verwachte bestand uit dist
|
|
expect_file() {
|
|
local path="$1" file="$2"
|
|
fetch "$path"
|
|
if [ "$status" != "200" ]; then
|
|
fail "$path: status $status, verwacht 200"
|
|
elif ! cmp -s "$work/body" "$dist/$file"; then
|
|
fail "$path: antwoord is niet gelijk aan $file uit dist (oude serverconfig of oude build?)"
|
|
fi
|
|
check_security_headers "$path"
|
|
}
|
|
|
|
# Een 301 naar een pad (Location mag absoluut of relatief zijn)
|
|
expect_redirect() {
|
|
local path="$1" target="$2" location
|
|
fetch "$path"
|
|
if [ "$status" != "301" ]; then
|
|
fail "$path: status $status, verwacht 301"
|
|
else
|
|
location="$(header Location)"
|
|
location="${location#http://*/}"
|
|
location="${location#https://*/}"
|
|
if [[ "$location" != /* ]]; then location="/$location"; fi
|
|
if [ "$location" != "$target" ]; then
|
|
fail "$path: Location '$(header Location)', verwacht pad $target"
|
|
fi
|
|
fi
|
|
check_security_headers "$path"
|
|
}
|
|
|
|
for file in index.html over-mij.html soorten-fotoshoots/newborn.html 404.html; do
|
|
if [ ! -f "$dist/$file" ]; then
|
|
echo "Geen $file in $dist" >&2
|
|
exit 2
|
|
fi
|
|
done
|
|
|
|
# De server moet bereikbaar zijn; kort herhalen zoals de oude controle
|
|
if ! curl -sS --retry 5 --retry-delay 3 --retry-connrefused --max-time 30 \
|
|
-o /dev/null "$base/"; then
|
|
echo "Niet bereikbaar: $base/" >&2
|
|
exit 1
|
|
fi
|
|
|
|
expect_file / index.html
|
|
expect_file /over-mij over-mij.html
|
|
expect_file /soorten-fotoshoots/newborn soorten-fotoshoots/newborn.html
|
|
|
|
fetch /onbekend-pad-voor-controle
|
|
if [ "$status" != "404" ]; then
|
|
fail "/onbekend-pad-voor-controle: status $status, verwacht 404"
|
|
elif ! cmp -s "$work/body" "$dist/404.html"; then
|
|
fail "/onbekend-pad-voor-controle: antwoord is niet gelijk aan 404.html uit dist"
|
|
fi
|
|
check_security_headers /onbekend-pad-voor-controle
|
|
|
|
expect_redirect /over-mij/ /over-mij
|
|
expect_redirect /Over-Mij /over-mij
|
|
|
|
# Compressie van de JavaScript uit index.html
|
|
script="$(grep -o '/assets/[A-Za-z0-9_./-]*\.js' "$dist/index.html" | head -n 1 || true)"
|
|
if [ -z "$script" ]; then
|
|
fail "geen /assets/*.js gevonden in index.html om de compressie te controleren"
|
|
else
|
|
fetch "$script" -H 'Accept-Encoding: gzip'
|
|
if [ "$status" != "200" ]; then
|
|
fail "$script: status $status, verwacht 200"
|
|
elif [ "$(header Content-Encoding)" != "gzip" ]; then
|
|
if [ "$test_mode" -eq 1 ]; then
|
|
fail "$script: geen Content-Encoding: gzip"
|
|
else
|
|
echo "WAARSCHUWING: $script wordt niet gecomprimeerd (de webhost beslist)" >&2
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
# Alleen met --cms: gedrag van de CMS-host zelf
|
|
if [ "$cms_mode" -eq 1 ]; then
|
|
# Cachebeleid: pagina's no-cache, assets onveranderlijk
|
|
fetch /
|
|
case "$(header Cache-Control)" in
|
|
*no-cache*) ;;
|
|
*) fail "/: Cache-Control '$(header Cache-Control)', verwacht no-cache" ;;
|
|
esac
|
|
if [ -n "$script" ]; then
|
|
fetch "$script"
|
|
check_security_headers "$script"
|
|
case "$(header Cache-Control)" in
|
|
*immutable*) ;;
|
|
*) fail "$script: Cache-Control '$(header Cache-Control)', verwacht immutable" ;;
|
|
esac
|
|
fi
|
|
|
|
# Alleen gzip: nooit brotli, ook niet als de client erom vraagt
|
|
fetch / -H 'Accept-Encoding: br, gzip'
|
|
if [ "$(header Content-Encoding)" = "br" ]; then
|
|
fail "/: Content-Encoding br, de CMS-host spreekt alleen gzip"
|
|
fi
|
|
|
|
# robots.txt: volledige headerset, en op test alles uitsluiten
|
|
fetch /robots.txt
|
|
if [ "$status" != "200" ]; then
|
|
fail "/robots.txt: status $status, verwacht 200"
|
|
elif [ "$test_mode" -eq 1 ] && ! grep -q '^Disallow: /$' "$work/body"; then
|
|
fail "/robots.txt: 'Disallow: /' ontbreekt op test"
|
|
fi
|
|
check_security_headers /robots.txt
|
|
|
|
# 404.html zelf geeft ook status 404 en de 404-pagina
|
|
fetch /404.html
|
|
if [ "$status" != "404" ]; then
|
|
fail "/404.html: status $status, verwacht 404"
|
|
fi
|
|
check_security_headers /404.html
|
|
|
|
# Een procentgecodeerd pad met slash blijft gecodeerd (zou anders een
|
|
# andere resource worden: /a?b)
|
|
fetch '/a%3Fb/'
|
|
if [ "$status" != "301" ]; then
|
|
fail "/a%3Fb/: status $status, verwacht 301"
|
|
elif [ "$(header Location)" != "/a%3Fb" ]; then
|
|
fail "/a%3Fb/: Location '$(header Location)', verwacht /a%3Fb"
|
|
fi
|
|
|
|
# Niet-GET op een websitepad. Met een lege body (-d ''): een POST zonder
|
|
# body en zonder Content-Length via de HTTP/1.0-proxy weigert Kestrel met
|
|
# 400 voordat de middleware het ziet
|
|
fetch / -X POST -d ''
|
|
if [ "$status" != "405" ]; then
|
|
fail "POST /: status $status, verwacht 405"
|
|
fi
|
|
|
|
# De CMS-routes: health, admin, API (zonder Offerings), onbekend API-pad
|
|
fetch /health
|
|
if [ "$status" != "200" ]; then fail "/health: status $status, verwacht 200"; fi
|
|
|
|
fetch /admin/
|
|
if [ "$status" != "200" ]; then fail "/admin/: status $status, verwacht 200"; fi
|
|
|
|
fetch /api/v1/System/capabilities
|
|
if [ "$status" != "200" ]; then
|
|
fail "/api/v1/System/capabilities: status $status, verwacht 200"
|
|
elif grep -qi 'offerings' "$work/body"; then
|
|
fail "/api/v1/System/capabilities noemt Offerings; die module hoort voor ASF uit te staan"
|
|
fi
|
|
|
|
# Een onbekend API-pad is een API-404, nooit de website
|
|
fetch /api/v1/onbekend-pad-voor-controle
|
|
if [ "$status" != "404" ]; then
|
|
fail "/api/v1/onbekend-pad-voor-controle: status $status, verwacht 404"
|
|
elif grep -qi '<html' "$work/body"; then
|
|
fail "/api/v1/onbekend-pad-voor-controle: antwoordt met HTML (SPA-fallback?)"
|
|
fi
|
|
fi
|
|
|
|
if [ "$failures" -gt 0 ]; then
|
|
echo "Controle mislukt ($failures fout(en)) voor $base" >&2
|
|
exit 1
|
|
fi
|
|
echo "Controle geslaagd voor $base"
|