Prepares the test site for the CMS host

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>
This commit is contained in:
2026-11-08 02:05:59 +01:00
co-authored by Claude Sonnet 5.5
parent 16b75af4d4
commit 41a6e7be5a
7 changed files with 216 additions and 24 deletions
@@ -1,15 +1,16 @@
# Gegenereerd door web/config/serverConfig.ts (pnpm server-config). Niet handmatig aanpassen.
# Reverse proxy voor de testsite naar de hosting-Pi. certbot past dit bestand
# aan voor HTTPS; kopieer het daarna dus niet opnieuw zonder certbot opnieuw te
# draaien.
# Reverse proxy voor de testsite naar de CMS-host op de hosting-Pi. certbot
# past dit bestand aan voor HTTPS; kopieer het daarna dus niet opnieuw zonder
# certbot opnieuw te draaien. Terugvallen op nginx van de hosting-Pi: haal
# :5200 weg achter proxy_pass.
server {
listen 80;
server_name test.andreaslop.nl;
location / {
proxy_pass http://192.168.1.103;
# Verplicht: de hosting-Pi kiest op basis van de hostname tussen het
# testblok en WordPress
proxy_pass http://192.168.1.103:5200;
# De CMS-host gebruikt Host niet om een site te kiezen, maar de
# terugvaloptie (nginx op de hosting-Pi) wel: daarom blijft hij staan
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+129 -9
View File
@@ -2,24 +2,40 @@
# 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]
# 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 3 ]; then
echo "Gebruik: $0 <basis-url> <dist-map> [--test]" >&2
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
if [ "$#" -eq 3 ]; then
if [ "$3" != "--test" ]; then
echo "Onbekende optie: $3" >&2
exit 2
fi
test_mode=1
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
@@ -72,6 +88,31 @@ check_security_headers() {
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
@@ -150,6 +191,85 @@ else
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