- ASF appsettings: Website:AuthoredBaseUrl=https://andreaslop.nl, PublicBaseUrl leeg (env). - Api.Tests/AsfInjectionPipelineTests: pagina met markers, echte database; een CMS-wijziging is direct zichtbaar (ETag wijzigt), data-blok == publieke API, 304, sitemap-adres. - smoke-site.sh: onverwerkte CMS-markers op / falen; data-blok moet siteUrl van deze host hebben. - docs: asf-host-injection 'as built'. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
98 lines
4.5 KiB
Bash
98 lines
4.5 KiB
Bash
#!/usr/bin/env bash
|
|
# Smoke test of a deployed site: anonymous GET requests only, no secrets.
|
|
#
|
|
# Usage: scripts/smoke-site.sh <url-on-the-host> <profile>
|
|
# <url-on-the-host> any URL of the host, for example its /health URL; only scheme and host are used
|
|
# <profile> sls-test | asf-test
|
|
#
|
|
# A site project is a thin composition (modules + appsettings.json), so what can still go wrong at deploy time is
|
|
# the composition itself: a module missing, the wrong website mode, a missing setting. The CI builds and tests the
|
|
# master CMS only; this script is the check that the deployed composition of a site is the one that was intended.
|
|
# A failing check makes the CI run fail.
|
|
set -u
|
|
|
|
base="$(printf '%s' "${1:?usage: smoke-site.sh <url-on-the-host> <profile>}" | sed -E 's#^(https?://[^/]+).*#\1#')"
|
|
profile="${2:?profile (sls-test | asf-test) is required}"
|
|
failures=0
|
|
|
|
curl_get() { curl -sS --max-time 20 --retry 4 --retry-delay 3 --retry-all-errors "$@"; }
|
|
status_of() { curl_get -o /dev/null -w '%{http_code}' "$base$1"; }
|
|
|
|
pass() { echo "ok $1"; }
|
|
fail() { echo "FAIL $1"; failures=$((failures + 1)); }
|
|
|
|
expect_status() { # path expected description
|
|
local got; got="$(status_of "$1")"
|
|
if [ "$got" = "$2" ]; then pass "$3 ($1 -> $got)"; else fail "$3 ($1 -> $got, expected $2)"; fi
|
|
}
|
|
|
|
expect_header() { # path header-name expected-substring description
|
|
local got; got="$(curl_get -D - -o /dev/null "$base$1" | tr -d '\r' | grep -i "^$2:" | head -1)"
|
|
if printf '%s' "$got" | grep -qi "$3"; then pass "$4 ($1 $2)"; else fail "$4 ($1 $2: '${got:-<missing>}')"; fi
|
|
}
|
|
|
|
expect_body() { # path expected-substring description
|
|
if curl_get "$base$1" | grep -qF "$2"; then pass "$3 ($1)"; else fail "$3 ($1 does not contain '$2')"; fi
|
|
}
|
|
|
|
echo "Smoke test '$profile' on $base"
|
|
|
|
expect_status /health 200 "health"
|
|
|
|
caps="$(curl_get "$base/api/v1/System/capabilities" || true)"
|
|
module_listed() { printf '%s' "$caps" | grep -q "\"$1\""; }
|
|
expect_module() { if module_listed "$1"; then pass "module $1 is loaded"; else fail "module $1 is NOT loaded (capabilities: ${caps:-<empty>})"; fi; }
|
|
expect_no_module() { if module_listed "$1"; then fail "module $1 is loaded but must not be"; else pass "module $1 is not loaded"; fi; }
|
|
|
|
expect_status /api/v1/offerings 200 "public offerings"
|
|
# 204 = no active banner, 200 = there is one; both are a healthy answer.
|
|
banner="$(status_of '/api/v1/offerings/banner')"
|
|
if [ "$banner" = "200" ] || [ "$banner" = "204" ]; then pass "public banner (/api/v1/offerings/banner -> $banner)"; else fail "public banner (-> $banner, expected 200 or 204)"; fi
|
|
expect_status /api/v1/offerings/all 401 "the administrator list is protected"
|
|
|
|
# A test host is never indexed.
|
|
expect_header / X-Robots-Tag noindex "noindex on the website"
|
|
expect_body /robots.txt "Disallow: /" "robots.txt disallows everything"
|
|
|
|
# The home page is served by the host. When the website build left CMS markers in it, the host must have processed
|
|
# them: an unprocessed <!--CMS:DATA--> or JSON-LD marker means the page does not go through the injector (a proxy or
|
|
# IIS serving files itself, or a host without the injection), and a deployed data block must carry this host's address.
|
|
home="$(curl_get "$base/" || true)"
|
|
if printf '%s' "$home" | grep -qE '<!--CMS:(DATA|OFFER-JSON-LD)'; then
|
|
fail "CMS markers on the home page were NOT processed by the host"
|
|
else
|
|
pass "no unprocessed CMS markers on the home page"
|
|
fi
|
|
if printf '%s' "$home" | grep -q 'id="cms-data"'; then
|
|
if printf '%s' "$home" | grep -q "\"siteUrl\":\"$base\""; then
|
|
pass "the data block carries this host's address (siteUrl $base)"
|
|
else
|
|
fail "the data block's siteUrl is not $base (is Website__PublicBaseUrl set on this host?)"
|
|
fi
|
|
expect_header / ETag '"' "the injected home page has an ETag"
|
|
expect_header / Cache-Control no-cache "the injected home page is no-cache"
|
|
fi
|
|
|
|
case "$profile" in
|
|
sls-test)
|
|
for m in Identity Availability Offerings Contact Master; do expect_module "$m"; done
|
|
expect_status /sitemap.xml 404 "no sitemap on a test host"
|
|
;;
|
|
asf-test)
|
|
for m in Identity Availability Offerings Contact; do expect_module "$m"; done
|
|
expect_no_module Master
|
|
# Prerendered website: an unknown path is a real 404 (an SPA would answer 200).
|
|
expect_status /smoke-test-path-that-does-not-exist 404 "unknown website path is a 404"
|
|
;;
|
|
*)
|
|
echo "Unknown profile '$profile' (use sls-test or asf-test)"
|
|
exit 2
|
|
;;
|
|
esac
|
|
|
|
if [ "$failures" -gt 0 ]; then
|
|
echo "Smoke test FAILED: $failures check(s)."
|
|
exit 1
|
|
fi
|
|
echo "Smoke test passed."
|