compose-smoke.sh: the read-side redirect guard is proven on the shipped image at last — a good target is written through the API, the stored column is rewritten underneath a running edge through the sidecar, and the edge is asked what it sends once the snapshot rebuilds. javascript:alert(1) answers 301 to the policy default and never to the stored value; a CRLF-bearing row answers 301 rather than the 500 Kestrel used to produce, and injects nothing. A curl 000 now samples the container it was aimed at and prints what it reports, and the gate ends by making the dead case happen on purpose: compose stop, 000 beside exited/unhealthy, compose start, running/healthy again. console-check.cjs: the observation table is waited for rather than read at one instant (an act run saw X-Total-Count: 0 where the same head a minute earlier had 11 rows), and the page's own request paths are pinned — the 14 admin-api calls it issues, their query strings, no others, none answered 404. A wrong URL on a page never looks like a wrong URL; it looks like an empty table. ci-gates.sh gains readme-counts: each gate records the total it actually ran into GATE_TOTALS_DIR and the README's claimed number is compared with it. Its first verdict was that the README claimed 229 assertions for a gate printing 368 — a 139-assertion gap nothing could see. The README now says 368 and 168, both measured in this run, and the run-by-run table gains 2405. Verified locally: compose smoke 368/0, console 168/0, smoke 256/0, lint green at actionlint 1.7.12 and shellcheck 0.11.0.
221 lines
10 KiB
Bash
Executable File
221 lines
10 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# One file says what each gate *is*, so "what CI runs" and "what an operator ran
|
|
# before pushing" stop being two different claims. CI calls one gate per step, so
|
|
# the job log still names the gate that failed; `all` runs them in order and
|
|
# stops at the first failure.
|
|
#
|
|
# scripts/ci-gates.sh restore|build|unit|integration|smoke|image|compose-smoke|all
|
|
# scripts/ci-gates.sh console (needs a real Chromium; not part of `all`)
|
|
# scripts/ci-gates.sh readme-counts scripts/<gate> (compares the README's
|
|
# assertion count with what that gate printed
|
|
# in this run; needs GATE_TOTALS_DIR)
|
|
# scripts/ci-gates.sh lint (the workflow and shell lint CI runs. Not in
|
|
# `all` for the console gate's reason: a machine
|
|
# that has neither the pinned tools nor a
|
|
# supported platform exits 2 — "cannot run" —
|
|
# which is a different answer from "clean".)
|
|
#
|
|
# Not here on purpose: scripts/geo-db-freshness.sh. It asks the vendor what the
|
|
# newest geo database is, so it is the one gate that talks to the internet, and
|
|
# putting it behind `all` would make the offline claim below false. It has its own
|
|
# scheduled job (.github/workflows/geo-freshness.yml).
|
|
#
|
|
# OPENWAF_ADMIN_TOKEN defaults below to the same throwaway CI uses; set it to
|
|
# override. Nothing here talks to anything outside the run.
|
|
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
|
|
# The compose gate needs an admin token for the stack it starts. It is not a
|
|
# secret — that stack exists only inside this run and is torn down on exit — but
|
|
# requiring it meant `ci-gates.sh all` stopped at the last gate for anyone who
|
|
# forgot to export one, which made the one-command entry point a lie. Same value
|
|
# CI uses, overridable by the caller.
|
|
export OPENWAF_ADMIN_TOKEN="${OPENWAF_ADMIN_TOKEN:-ci-only-throwaway}"
|
|
|
|
banner() { printf '\n\033[1m=== gate: %s ===\033[0m\n' "$1"; }
|
|
|
|
restore() { banner restore; dotnet restore dotnet/OpenWaf.slnx; }
|
|
|
|
# TreatWarningsAsErrors is set in Directory.Build.props, so this is also the
|
|
# warning gate.
|
|
build() { banner build; dotnet build dotnet/OpenWaf.slnx -c Release --no-restore; }
|
|
|
|
unit() { banner unit; dotnet test dotnet/OpenWaf.Tests.Unit/OpenWaf.Tests.Unit.csproj -c Release --no-build; }
|
|
|
|
integration() { banner integration; dotnet test dotnet/OpenWaf.Tests.Integration/OpenWaf.Tests.Integration.csproj -c Release --no-build; }
|
|
|
|
smoke() { banner smoke; ./scripts/smoke.sh; }
|
|
|
|
# The plain build the README shows, plus its size: the compose path would hide a
|
|
# Dockerfile regression that this step catches.
|
|
image() { banner image; docker build -t openwaf:ci .; docker image ls openwaf:ci --format '{{.Repository}}:{{.Tag}} {{.Size}}'; }
|
|
|
|
compose_smoke() { banner compose-smoke; ./scripts/compose-smoke.sh; }
|
|
|
|
# The browser gate over the operator page. It is a gate, so it lives here too and
|
|
# CI calls it by the same name. It is NOT part of `all`: it needs a real
|
|
# Chromium, and a machine without one exits 2 ("cannot run"), which is a
|
|
# different answer from 1 ("the page is wrong") and would otherwise make the
|
|
# one-command entry point unrunnable. Run it explicitly before pushing a change
|
|
# to the console.
|
|
console() { banner console; ./scripts/console-smoke.sh; }
|
|
|
|
# Checksum helper: sha256sum on Linux, shasum on a macOS host, and a refusal to
|
|
# check nothing when neither is present.
|
|
sha256_verify() {
|
|
if command -v sha256sum >/dev/null 2>&1; then
|
|
printf '%s %s\n' "$2" "$1" | sha256sum -c -
|
|
elif command -v shasum >/dev/null 2>&1; then
|
|
printf '%s %s\n' "$2" "$1" | shasum -a 256 -c -
|
|
else
|
|
printf 'no sha256 tool on this host: refusing to download an unverified binary\n' >&2
|
|
return 2
|
|
fi
|
|
}
|
|
|
|
# The lint CI runs. It lives here because until this stage existed the workflow
|
|
# files and the smoke scripts were checked by exactly one caller — a CI job — and
|
|
# `ci-gates.sh all` could be green on a tree CI would refuse (OPEN-44). The
|
|
# versions and checksums are pinned here rather than in the workflow, and the CI
|
|
# job now calls this function, so the two callers cannot drift into linting
|
|
# different versions of the same gate.
|
|
#
|
|
# A tool already on PATH is used as it is, and the version it prints is the
|
|
# version that did the linting — that is the number the README quotes. Otherwise
|
|
# the pinned release is downloaded, which is supported on linux x86_64 and arm64.
|
|
# Anywhere else this says so and exits 2: a lint stage that silently passes on a
|
|
# machine where it never ran is the defect OPEN-44 is about.
|
|
lint() {
|
|
banner lint
|
|
local workdir; workdir=$(mktemp -d)
|
|
if command -v actionlint >/dev/null 2>&1; then
|
|
actionlint --version | head -1
|
|
actionlint -no-color .github/workflows/*.yml
|
|
elif [ "$(uname -s)" = Linux ]; then
|
|
local version=1.7.12
|
|
local sha=8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8
|
|
local arch
|
|
case "$(uname -m)" in
|
|
x86_64) arch=amd64 ;;
|
|
aarch64) arch=arm64 ;;
|
|
*) printf 'actionlint: unsupported architecture %s — cannot run (exit 2), not a pass\n' "$(uname -m)" >&2; return 2 ;;
|
|
esac
|
|
curl -fsSL -o "$workdir/actionlint.tar.gz" \
|
|
"https://github.com/rhysd/actionlint/releases/download/v${version}/actionlint_${version}_linux_${arch}.tar.gz"
|
|
sha256_verify "$workdir/actionlint.tar.gz" "$sha"
|
|
tar xzf "$workdir/actionlint.tar.gz" -C "$workdir" actionlint
|
|
"$workdir/actionlint" --version | head -1
|
|
"$workdir/actionlint" -no-color .github/workflows/*.yml
|
|
else
|
|
printf 'actionlint is not installed and this is not Linux: the lint gate cannot run (exit 2), which is not a pass\n' >&2
|
|
return 2
|
|
fi
|
|
|
|
if command -v shellcheck >/dev/null 2>&1; then
|
|
shellcheck --version | sed -n 's/^version: //p'
|
|
shellcheck -s bash scripts/*.sh
|
|
elif [ "$(uname -s)" = Linux ]; then
|
|
local sv=0.11.0
|
|
local sv_x86_64=8c3be12b05d5c177a04c29e3c78ce89ac86f1595681cab149b65b97c4e227198
|
|
local sv_aarch64=12b331c1d2db6b9eb13cfca64306b1b157a86eb69db83023e261eaa7e7c14588
|
|
local sarch ssha
|
|
case "$(uname -m)" in
|
|
x86_64) sarch=x86_64; ssha=$sv_x86_64 ;;
|
|
aarch64) sarch=aarch64; ssha=$sv_aarch64 ;;
|
|
*) printf 'shellcheck: unsupported architecture %s — cannot run (exit 2), not a pass\n' "$(uname -m)" >&2; return 2 ;;
|
|
esac
|
|
curl -fsSL -o "$workdir/shellcheck.tar.xz" \
|
|
"https://github.com/koalaman/shellcheck/releases/download/v${sv}/shellcheck-v${sv}.linux.${sarch}.tar.xz"
|
|
sha256_verify "$workdir/shellcheck.tar.xz" "$ssha"
|
|
tar xJf "$workdir/shellcheck.tar.xz" -C "$workdir"
|
|
"$workdir/shellcheck-v${sv}/shellcheck" --version | sed -n 's/^version: //p'
|
|
"$workdir/shellcheck-v${sv}/shellcheck" -s bash scripts/*.sh
|
|
else
|
|
printf 'shellcheck is not installed and this is not Linux: the lint gate cannot run (exit 2), which is not a pass\n' >&2
|
|
return 2
|
|
fi
|
|
}
|
|
|
|
# The README names an assertion count per gate. Those numbers were copied by
|
|
# hand out of a log, and they drift: OPEN-46 measured the README claiming
|
|
# scripts/compose-smoke.sh had 229 assertions while that gate was printing 356.
|
|
# A number nobody checks is not a measurement, so this gate compares what the
|
|
# README claims with what the gate recorded in this run. Each gate writes its own
|
|
# total into $GATE_TOTALS_DIR when that variable is set — CI sets it once per
|
|
# job, `all` sets it for a local run. With nothing to compare this gate exits 2
|
|
# ("cannot verify"), because a check that reports a pass because it had no input
|
|
# is the defect this is about.
|
|
readme_counts() {
|
|
local gate="${1:-}"
|
|
banner "readme-counts $gate"
|
|
if [ -z "$gate" ]; then
|
|
printf 'usage: %s readme-counts scripts/<gate>\n' "$0" >&2
|
|
return 2
|
|
fi
|
|
if [ ! -f README.md ]; then
|
|
printf 'no README.md to read: cannot verify (exit 2), not a pass\n' >&2
|
|
return 2
|
|
fi
|
|
local claimed
|
|
claimed=$(awk -v g="$gate" '$1==g && $3=="assertions" { print $2; exit }' README.md)
|
|
if [ -z "$claimed" ]; then
|
|
printf 'README.md names no assertion count for %s: nothing to verify (exit 2)\n' "$gate" >&2
|
|
return 2
|
|
fi
|
|
if [ -z "${GATE_TOTALS_DIR:-}" ]; then
|
|
printf 'GATE_TOTALS_DIR is not set, so %s recorded no total this run: cannot verify (exit 2)\n' "$gate" >&2
|
|
return 2
|
|
fi
|
|
local measured_name
|
|
measured_name=$(printf '%s' "$gate" | tr '/' '_')
|
|
local measured_file="$GATE_TOTALS_DIR/$measured_name.txt"
|
|
if [ ! -f "$measured_file" ]; then
|
|
printf '%s did not record a total in %s: cannot verify (exit 2)\n' "$gate" "$GATE_TOTALS_DIR" >&2
|
|
return 2
|
|
fi
|
|
local measured failed
|
|
read -r _ measured failed < "$measured_file"
|
|
printf 'README claims %s assertions for %s; the gate printed %s (%s failed)\n' \
|
|
"$claimed" "$gate" "$measured" "$failed"
|
|
if [ "$claimed" != "$measured" ]; then
|
|
printf 'the README is stale by %s assertions. Either the gate changed and the README did not, or the README was never measured.\n' \
|
|
"$((measured - claimed))" >&2
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
case "${1:-all}" in
|
|
restore) restore ;;
|
|
build) build ;;
|
|
unit) unit ;;
|
|
integration) integration ;;
|
|
smoke) smoke ;;
|
|
image) image ;;
|
|
compose-smoke) compose_smoke ;;
|
|
console) console ;;
|
|
lint) lint ;;
|
|
readme-counts) readme_counts "${2:-}" ;;
|
|
all)
|
|
# Set here rather than requiring the caller: the totals only mean something
|
|
# if the gates that produced them and the check that reads them ran in the
|
|
# same invocation.
|
|
export GATE_TOTALS_DIR="${GATE_TOTALS_DIR:-$(mktemp -d)}"
|
|
restore; build; unit; integration; smoke; image; compose_smoke
|
|
# The two gates `all` actually ran. console is not among them, so its README
|
|
# number is verified by the console job (or by an operator who ran it and
|
|
# then calls readme-counts with the same GATE_TOTALS_DIR).
|
|
readme_counts scripts/smoke.sh
|
|
readme_counts scripts/compose-smoke.sh
|
|
printf '\nall gates passed\n'
|
|
printf 'NOT included above: console (needs a real Chromium; exits 2 without one),\n'
|
|
printf 'and lint (needs actionlint and shellcheck; exits 2 without them).\n'
|
|
printf 'If the console changed, run: %s console\n' "$0"
|
|
printf 'If a workflow or script changed, run: %s lint\n' "$0"
|
|
;;
|
|
*)
|
|
printf 'usage: %s restore|build|unit|integration|smoke|image|compose-smoke|console|lint|readme-counts|all\n' "$0" >&2
|
|
exit 2
|
|
;;
|
|
esac
|