Files
openwaf/scripts/console-smoke.sh
T
Pavlo Ratushnyi 66df999cdf The country table got a shape, and the page caught me colliding with itself
The console's country view was a column of numbers. "Where is this traffic
coming from" is a comparison, so each row now carries a bar sized against the
busiest country, and the table says what it counted. No tiles, no CDN, no asset
file: the runtime image is distroless and the page has to work at the moment the
site in front of it is being attacked. A geographic map is still not here and
the README now says why plainly — the admin API exposes counts per ISO code, not
coordinates, and an outline drawn from memory would be decoration that misleads.

The first run after the change failed, for a real reason: the class I added was
`.bar`, and the page already had a `.bar` — the toolbar. The toolbar collapsed
to 0.55em tall, `div#summary` started intercepting pointer events, and every
assertion after the token click died on a click timeout. Renamed to
`.sharebar`.

The gate itself got the same treatment as the page. It used to leave a reviewer
with nothing but a stack trace; now it writes a screenshot both when the page
cannot be driven at all and when it is driven and wrong. That path was checked
by making it red on purpose: with seeds that do not match the stack it exits 1
naming 3 failed assertions and writes a 105078-byte picture.

Measured, not assumed, in the same pass:

- `ci-gates.sh` gained a `console` gate and the workflow calls it by that name
  instead of retyping the script: one definition, two callers. It is
  deliberately NOT in `all` — without a Chromium the gate exits 2 ("cannot
  run"), which is a different answer from 1 ("the page is wrong"), and folding
  it in would make the one-command entry point unrunnable off a CI runner.
- `ci-gates.sh all` no longer stops at the last gate for want of an admin
  token: it was dying at compose-smoke with `OPENWAF_ADMIN_TOKEN: set …` before
  it could print a verdict. The throwaway for the stack the gate starts and
  tears down itself is defaulted there; the standalone scripts still refuse to
  invent one, because run by hand they can be pointed at a real deployment.
- The console job publishes the desktop and phone screenshots as artifacts,
  with `if: always()` so the failure case is the one you can look at. The
  relative SCREENSHOT path and the `console-evidence*.png` glob were verified
  locally: 107935 and 86179 bytes written.
- DBIP_VERSION 2026-09 -> 2026-10. Not a cache hit: 8348509 bytes fetched,
  image 261 MB, compose smoke 27/27 afterwards.
- The trap that bump exposes, measured rather than reasoned about: the same
  rebuilt image reported `geoBuiltAt: 2026-09-01T01:32:45Z` against the
  existing `openwaf_openwaf-geoip` volume and `2026-10-01T01:36:12Z` after
  removing it. Docker seeds a named volume from the image only when the volume
  is first created, so a rebuild alone never replaces the geo database.

Gates on this commit: build 0 warnings / 0 errors, unit 54/54, integration
27/27, smoke 19/19, image 261 MB, compose-smoke 27/27, console 16/16 (desktop
bar 513 px inside a 529 px cell; phone pass at 375 px in dark mode: scrollWidth
375, status contrast 11.85:1, bars 67 px), actionlint 0, shellcheck 0. Still
true, and unchanged by any of the above: not one of these jobs has run on a
runner, because the repository has no remote.
2026-10-01 14:26:33 +02:00

60 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# The console gate: start the stack, seed the two things the page has to show
# (a source sitting at 2 of a threshold of 3, and an operator block with a
# reason), drive the page in a real Chromium, tear the stack down.
#
# Needs docker and playwright-core. Set PLAYWRIGHT_CORE=/path/to/playwright-core
# if it is not installed locally. The script does not skip when playwright is
# missing — it exits non-zero, because a gate that reports success having
# asserted nothing is worse than no gate.
#
# OPENWAF_ADMIN_TOKEN=… SCREENSHOT=/tmp/console.png ./scripts/console-smoke.sh
set -euo pipefail
cd "$(dirname "$0")/.."
export OPENWAF_ADMIN_TOKEN="${OPENWAF_ADMIN_TOKEN:?set OPENWAF_ADMIN_TOKEN before running, or run scripts/ci-gates.sh (it defaults a throwaway for the stack it starts itself)}"
EDGE=http://127.0.0.1:8080
SEED_SOURCE=203.0.113.55
SEED_BLOCK=203.0.113.77
export EDGE_URL="$EDGE" SEED_SOURCE SEED_BLOCK
admin() { curl -s -m 10 -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$@"; }
cleanup() {
admin -X PUT -H 'Content-Type: application/json' \
-d '{"mode":"Enforce","geo":"Off","streakThreshold":10,"trustProxyHeaders":false}' "$EDGE/admin-api/policy" >/dev/null 2>&1
admin -X DELETE "$EDGE/admin-api/blocks?source=operator" >/dev/null 2>&1
[ "${KEEP_UP:-0}" = 1 ] || docker compose down >/dev/null 2>&1
}
trap cleanup EXIT
echo '- starting the stack'
docker compose up -d --build >/dev/null 2>&1 || { echo 'compose up failed'; exit 1; }
for _ in $(seq 1 120); do
[ "$(docker compose ps -q edge | xargs docker inspect --format '{{.State.Health.Status}}')" = healthy ] && break
sleep 0.5
done
# Threshold 3 and trusted proxy headers, so two refusals from one address show
# as "2 / 3" without tripping the ban. The policy lives in the shared database
# and reaches the guard on the next snapshot refresh — hence the wait, which is
# the same TTL the multi-instance measurement is about.
admin -X PUT -H 'Content-Type: application/json' \
-d '{"mode":"Enforce","geo":"Off","streakThreshold":3,"trustProxyHeaders":true}' "$EDGE/admin-api/policy" >/dev/null
sleep 31
echo '- seeding what the page must show'
for _ in 1 2; do curl -s -o /dev/null -H "X-Forwarded-For: $SEED_SOURCE" "$EDGE/probe"; done
curl -s -o /dev/null -H 'X-Forwarded-For: 8.8.8.8' "$EDGE/no-such-page"
admin -X POST -H 'Content-Type: application/json' \
-d "{\"ip\":\"$SEED_BLOCK\",\"reason\":\"console gate: operator block\"}" "$EDGE/admin-api/blocks" >/dev/null
# Durable observations are written by a background loop (flush every 15 s, at
# most once per source per 30 s), so the observations table needs the same wait
# the policy write needed. Without it the page is correct and the gate is wrong.
sleep 35
echo '- driving the page'
node scripts/console-check.cjs