#!/usr/bin/env bash # Smoke test of a deployed site: anonymous GET requests only, no secrets. # # Usage: scripts/smoke-site.sh # any URL of the host, for example its /health URL; only scheme and host are used # 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 }" | 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:-}')"; 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:-})"; 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" # The hero: 204 = no hero to show (the website keeps its own), 200 = there is one; the management routes are protected and # the media endpoint answers a plain 404 for something that is not stored. hero="$(status_of '/api/v1/hero')" if [ "$hero" = "200" ] || [ "$hero" = "204" ]; then pass "public hero (/api/v1/hero -> $hero)"; else fail "public hero (-> $hero, expected 200 or 204)"; fi expect_status /api/v1/hero/all 401 "the hero management read is protected" expect_status /media/hero/0123456789abcdef/wide-960.webp 404 "media that is not stored is a plain 404" # The admin page must have no inline script: the host only allows scripts from its own origin (script-src 'self'). admin_html="$(curl_get "$base/admin/" || true)" if printf '%s' "$admin_html" | grep -q 'id="root"'; then if printf '%s' "$admin_html" | grep -qiP ']*src=)[^>]*>'; then fail "the admin page has an inline script (blocked by the Content-Security-Policy)"; else pass "the admin page has no inline script"; fi expect_status /admin/theme-init.js 200 "the theme script is a file of its own" fi # 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 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 '