Owner decision 2026-11-11: on the trial stack one verified factor suffices for owner as for admin, a second one optional. The count before the typed confirmation and the recount inside the grant transaction stay; SQL, aal2 and the rule for every other stack are unchanged.
1637 lines
129 KiB
Bash
Executable File
1637 lines
129 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# shellcheck disable=SC2016
|
|
# (file-wide: the `bash -c '…'` snippets of the checks expand their own positional parameters)
|
|
#
|
|
# `bash scripts/db-trial-check.sh`, run by hand (never a check:all stage): environment-free checks
|
|
# of scripts/db-trial.sh and of the state-folder guard of scripts/db-sandbox.sh (TRIAL_STACK.md,
|
|
# SUPABASE.md §5.2). Each case runs a script from a throwaway copy of the files it reads, under a
|
|
# temporary HOME, with docker, curl, the Supabase CLI, Vite and the Rust tools replaced by stubs
|
|
# that log their arguments and keep one file per pretend resource; ss, node and env pass through
|
|
# wrappers that log their arguments, so no secret can hide in any argv. DOCKER_HOST names a socket
|
|
# that does not exist, so no daemon is reachable even past a stub. The script reads the host's
|
|
# real listening ports (ss) and memory: the preflight refuses to run (exit 2, never a FAIL) while
|
|
# a trial port is in use or memory is short. Nothing is created, started, stopped or removed
|
|
# outside the temporary folder, except that hold_port opens real loopback listeners on 58801, 5194
|
|
# and 58300 (python3, one at a time, up to 30 s each), closed after their case and at cleanup.
|
|
# Prints "db-trial-check: ALL PASS" only when every check passed.
|
|
set -uo pipefail
|
|
|
|
preflight() {
|
|
local port out mib
|
|
for port in 58432 58999 58300 58500 58025 58801 5194; do
|
|
out="$(ss -Hltn "sport = :$port")" || { echo "db-trial-check: cannot run while ss cannot list the ports: stop the trial stack/app first" >&2; exit 2; }
|
|
if [ -n "$out" ]; then
|
|
echo "db-trial-check: cannot run while port $port is in use: stop the trial stack/app first" >&2
|
|
exit 2
|
|
fi
|
|
done
|
|
mib="$(awk '/^MemAvailable:/ { print int($2 / 1024) }' /proc/meminfo)"
|
|
if [ "$mib" -lt 2048 ]; then
|
|
echo "db-trial-check: cannot run while only $mib MiB of memory are available (create needs 2048): stop the trial stack/app first" >&2
|
|
exit 2
|
|
fi
|
|
}
|
|
preflight
|
|
|
|
REPO="$(cd "$(dirname "$0")/.." && pwd -P)"
|
|
TMP_ROOT="${TMPDIR:-/tmp}"
|
|
WORK="$(mktemp -d "$TMP_ROOT/db-trial-check.XXXXXX")" || exit 1
|
|
# Every later path hangs off WORK: it must be the fresh folder mktemp just made, nothing else.
|
|
case "$WORK" in
|
|
"$TMP_ROOT"/db-trial-check.?*) [ -d "$WORK" ] || exit 1 ;;
|
|
*) echo "db-trial-check: unexpected temporary folder '$WORK': nothing was run" >&2; exit 1 ;;
|
|
esac
|
|
cleanup() { [ -z "${LISTENER:-}" ] || kill "$LISTENER" 2>/dev/null; ( cd "$WORK" && rm -rf -- ./repo ./bin ./bin-no-ss ./bin-mvfail ./bin-mvterm ./path-no-ss ./cases ./docker-config ); rmdir -- "$WORK" 2>/dev/null || true; }
|
|
trap cleanup EXIT
|
|
PASS=0 FAIL=0
|
|
pass() { echo "PASS $1"; PASS=$((PASS + 1)); }
|
|
fail() { echo "FAIL $1"; FAIL=$((FAIL + 1)); }
|
|
check() { local name="$1"; shift; if "$@" </dev/null; then pass "$name"; else fail "$name"; fi; }
|
|
|
|
SEED_REL=supabase/seed/anatomical-sheets/equine/draft
|
|
mkdir -p "$WORK/repo/scripts" "$WORK/repo/$SEED_REL/assets" "$WORK/repo/node_modules/.bin" \
|
|
"$WORK/repo/apps/app/node_modules/.bin" "$WORK/bin" "$WORK/cases" "$WORK/docker-config"
|
|
cp "$REPO/scripts/db-trial.sh" "$REPO/scripts/db-sandbox.sh" "$REPO/scripts/dev-env.sh" "$WORK/repo/scripts/"
|
|
cp "$REPO/supabase/config.toml" "$REPO/supabase/seed.sql" "$WORK/repo/supabase/"
|
|
cp -R "$REPO/supabase/migrations" "$WORK/repo/supabase/migrations"
|
|
for f in equine_draft.sql document.json sheet-ref.json assets.json; do cp "$REPO/$SEED_REL/$f" "$WORK/repo/$SEED_REL/"; done
|
|
cp "$REPO/$SEED_REL/assets/"*.svg "$WORK/repo/$SEED_REL/assets/"
|
|
|
|
# SIGTERM for the outermost process running db-trial.sh: the stub that calls this walks its own parent
|
|
# chain, so nothing outside its ancestry is ever signalled.
|
|
cat > "$WORK/term-trial.sh" <<'STUB'
|
|
#!/usr/bin/env bash
|
|
target='' p=$PPID
|
|
while [ "$p" -gt 1 ]; do
|
|
if tr '\0' ' ' < "/proc/$p/cmdline" | grep -q '^bash scripts/db-trial\.sh '; then target=$p; fi
|
|
p="$(sed 's/^.*) [A-Za-z] \([0-9]*\) .*/\1/' "/proc/$p/stat")"
|
|
done
|
|
[ -z "$target" ] || kill -TERM "$target"
|
|
sleep 0.5
|
|
STUB
|
|
|
|
# The same with SIGINT (Ctrl+C reaches the script, not only its children).
|
|
sed 's/kill -TERM/kill -INT/' "$WORK/term-trial.sh" > "$WORK/int-trial.sh"
|
|
|
|
cat > "$WORK/bin/docker" <<'STUB'
|
|
#!/usr/bin/env bash
|
|
# docker stand-in: one log line per call (newlines shown as \n), one file per pretend resource.
|
|
# Files under $STUB_STATE/fail/ make one answer fail: daemon (every call but `context`, with the real dial error),
|
|
# daemon-lost (docker info answers, every inspect gets that dial error; daemon-lost-volume / -network / -container
|
|
# for one kind), inspect-after-stop (container inspects fail once a docker stop ran), stop-noop (docker stop leaves
|
|
# the container running), networks-create, networks-create-after
|
|
# (the network is made, then the call fails), inspect-error (every inspect fails with an answer other
|
|
# than "no such" or "not found"), helper, archive, extract (the restore's tar -x), image-nondb (every
|
|
# image but the database's is absent), <sql tag>. Other hooks: term-in-archive (the script gets a
|
|
# SIGTERM while it archives), append-on-rm (the file named inside gets a byte when a container is
|
|
# removed), term-on (an ERE: the first call whose argv line, or tag:<sql tag> for an exec, matches it
|
|
# sends the script a SIGTERM), answers/measure-kib (the volumes' measured size), answers/<tag>.seq (one line per call).
|
|
# answers/volume-ls (what `ls -A /volume` prints: a non-empty volume; volume-ls-storage: for that volume only).
|
|
# lost-after-archive: with fail/archive, the daemon is lost once the archive failed (as lost-now below).
|
|
# Every failing `inspect -f` (an absent resource of any of the four kinds, a lost daemon) writes a
|
|
# bare newline to stdout and the sentence to stderr, rc 1, as Docker 29.9.3 does (measured): the
|
|
# script must judge stderr alone. Docker's own wording per kind:
|
|
# "Error response from daemon: No such container: <name>", "... get <name>: no such volume",
|
|
# "... network <name> not found", "... No such image: <name>".
|
|
# daemon-lost-after-create: once a network or volume was created, every later call but `context`
|
|
# and `info` gets the dial error (the daemon is lost part-way through a create).
|
|
set -uo pipefail
|
|
st="$STUB_STATE"
|
|
dial_error() {
|
|
echo
|
|
echo "failed to connect to the docker API at unix:///stub/docker.sock; check if the path is correct and if the daemon is running: dial unix /stub/docker.sock: connect: no such file or directory" >&2
|
|
exit 1
|
|
}
|
|
{ printf 'docker'; for a in "$@"; do printf ' %s' "${a//$'\n'/\\n}"; done; printf '\n'; } >> "$STUB_LOG"
|
|
save_stdin() { local f; f="$st/stdin/$(date +%s%N)"; cat > "$f"; printf '%s' "$f"; }
|
|
term_if() { # text: once, when it matches the term-on pattern
|
|
[ -f "$st/term-on" ] && grep -qEf "$st/term-on" <<<"$1" || return 0
|
|
rm -f "$st/term-on"; bash "$STUB_TERM"
|
|
}
|
|
term_if "docker $*"
|
|
sub="${1:-}"
|
|
[ $# -eq 0 ] || shift
|
|
if [ -f "$st/fail/daemon" ] && [ "$sub" != context ]; then dial_error; fi
|
|
absent_error() { echo; echo "$1" >&2; exit 1; } # the failing inspect's two streams
|
|
if [ -f "$st/lost-now" ] && [ "$sub" != context ] && [ "$sub" != info ]; then dial_error; fi
|
|
lost() { [ -f "$st/fail/daemon-lost" ] || [ -f "$st/fail/daemon-lost-$1" ]; } # kind: its inspects hit the dial error
|
|
case "$sub" in
|
|
info) echo /stub/docker-root ;;
|
|
context)
|
|
[ "${1:-}" = inspect ] || exit 97
|
|
[ ! -f "$st/fail/context" ] || exit 1
|
|
if [ -f "$st/answers/context" ]; then cat "$st/answers/context"; else echo unix:///stub/docker.sock; fi ;;
|
|
ps) exit 0 ;;
|
|
image)
|
|
[ "${1:-}" = inspect ] || exit 97
|
|
img="${*: -1}"
|
|
if lost image; then dial_error; fi
|
|
[ ! -f "$st/fail/image" ] || absent_error "Error response from daemon: No such image: $img"
|
|
if [ -f "$st/fail/image-nondb" ]; then
|
|
case "$img" in *supabase/postgres*) ;; *) absent_error "Error response from daemon: No such image: $img" ;; esac
|
|
fi ;;
|
|
network | volume)
|
|
kind="${sub}s" op="${1:-}"
|
|
shift
|
|
case "$op" in
|
|
inspect)
|
|
if [ "${1:-}" = -f ]; then shift 2; fi
|
|
if lost "$sub"; then dial_error; fi
|
|
if [ -f "$st/fail/inspect-error" ]; then absent_error "Error response from daemon: permission denied"; fi
|
|
# Docker's real wordings: they differ by kind.
|
|
if [ ! -f "$st/$kind/$1" ]; then
|
|
case "$sub" in
|
|
volume) absent_error "Error response from daemon: get $1: no such volume" ;;
|
|
*) absent_error "Error response from daemon: network $1 not found" ;;
|
|
esac
|
|
fi ;;
|
|
create)
|
|
[ ! -f "$st/fail/$kind-create" ] || exit 1
|
|
name="${*: -1}"
|
|
# Like Docker: a volume create on an existing name succeeds and prints the name.
|
|
if [ -f "$st/$kind/$name" ]; then if [ "$sub" = volume ]; then echo "$name"; exit 0; fi; exit 1; fi
|
|
: > "$st/$kind/$name"
|
|
if [ -f "$st/fail/daemon-lost-after-create" ]; then : > "$st/lost-now"; fi
|
|
[ ! -f "$st/fail/$kind-create-after" ] || exit 1
|
|
echo "$name" ;;
|
|
rm) for n in "$@"; do [ -f "$st/$kind/$n" ] || exit 1; rm -f "$st/$kind/$n"; done ;;
|
|
*) exit 97 ;;
|
|
esac ;;
|
|
container)
|
|
[ "${1:-}" = inspect ] || exit 97
|
|
shift
|
|
fmt=''
|
|
if [ "${1:-}" = -f ]; then fmt="$2"; shift 2; fi
|
|
if lost container; then dial_error; fi
|
|
if [ -f "$st/fail/inspect-error" ]; then absent_error "Error response from daemon: permission denied"; fi
|
|
if [ -f "$st/fail/inspect-after-stop" ] && [ -f "$st/stopped" ]; then absent_error "Error response from daemon: permission denied"; fi
|
|
[ -f "$st/containers/$1" ] || absent_error "Error response from daemon: No such container: $1"
|
|
case "$fmt" in
|
|
'{{.State.Running}}') if [ "$(cat "$st/containers/$1")" = running ]; then echo true; else echo false; fi ;;
|
|
'{{.Name}}') echo "/$1" ;;
|
|
'') echo "stub: a bare inspect would print the env files" >&2; exit 98 ;;
|
|
*) echo "$(cat "$st/containers/$1") stub-image" ;;
|
|
esac ;;
|
|
run)
|
|
name='' port='' remove=0 input=0 args=("$@") i=0
|
|
while [ "$i" -lt "${#args[@]}" ]; do
|
|
case "${args[$i]}" in
|
|
--name) name="${args[$((i + 1))]}"; i=$((i + 1)) ;;
|
|
-p) port="${args[$((i + 1))]}"; i=$((i + 1)) ;;
|
|
--rm) remove=1 ;;
|
|
-i) input=1 ;;
|
|
esac
|
|
i=$((i + 1))
|
|
done
|
|
if [ "$remove" -eq 1 ]; then
|
|
if [ "$name" = faunosteo_trial_helper ] && [ -f "$st/fail/helper" ]; then exit 1; fi
|
|
if [ "$input" -eq 1 ]; then [ ! -f "$st/fail/extract" ] || exit 1; save_stdin >/dev/null; fi
|
|
# Measure: 100 KiB and 2 entries ("." and "./content"), what the archive below lists.
|
|
if printf '%s\n' "$@" | grep -qx -- 'ls -A /volume'; then
|
|
vf="$st/answers/volume-ls"
|
|
if [[ "$*" == *faunosteo_trial_storage:* && -f "$vf-storage" ]]; then vf="$vf-storage"; fi
|
|
cat "$vf" 2>/dev/null || true
|
|
fi
|
|
if printf '%s\n' "$@" | grep -q -- 'du -sk /volume'; then
|
|
printf '%s\n2\n' "$(cat "$st/answers/measure-kib" 2>/dev/null || echo 100)"
|
|
fi
|
|
if printf '%s\n' "$@" | grep -qx -- -cf; then
|
|
if [ -f "$st/fail/archive" ]; then
|
|
if [ -f "$st/fail/lost-after-archive" ]; then : > "$st/lost-now"; fi
|
|
exit 3
|
|
fi
|
|
if [ -f "$st/term-in-archive" ]; then bash "$STUB_TERM"; fi
|
|
# A real (tiny) tar, so that the script's read-back has something to list. short-archive:
|
|
# the root entry only, exit 0 (an archive cut at a member boundary).
|
|
mkdir -p "$st/archive"; printf '%s\n' "$*" > "$st/archive/content"
|
|
if [ -f "$st/short-archive" ]; then tar -cf - -C "$st/archive" --no-recursion .
|
|
else tar -cf - -C "$st/archive" .; fi
|
|
fi
|
|
exit 0
|
|
fi
|
|
[ -n "$name" ] && [ ! -f "$st/containers/$name" ] || exit 1
|
|
echo running > "$st/containers/$name"
|
|
if [ -n "$port" ]; then
|
|
IFS=: read -r ip host inner <<<"$port"
|
|
# publish-wide-<name>: Docker publishes that container on 0.0.0.0 whatever -p said.
|
|
if [ -f "$st/publish-wide-$name" ]; then ip=0.0.0.0; fi
|
|
echo "$inner/tcp -> $ip:$host" > "$st/ports/$name"
|
|
fi
|
|
echo "stub-id-$name" ;;
|
|
start) for n in "$@"; do [ -f "$st/containers/$n" ] || exit 1; echo running > "$st/containers/$n"; done ;;
|
|
restart)
|
|
while [ "${1:-}" = -t ]; do shift 2; done
|
|
for n in "$@"; do [ -f "$st/containers/$n" ] || exit 1; echo running > "$st/containers/$n"; done ;;
|
|
stop)
|
|
while [ "${1:-}" = -t ]; do shift 2; done
|
|
: > "$st/stopped"
|
|
for n in "$@"; do
|
|
[ -f "$st/containers/$n" ] || exit 1
|
|
[ -f "$st/fail/stop-noop" ] || echo exited > "$st/containers/$n"
|
|
done ;;
|
|
rm)
|
|
if [ "${1:-}" = -f ]; then shift; fi
|
|
if [ -f "$st/append-on-rm" ]; then printf x >> "$(cat "$st/append-on-rm")"; fi
|
|
for n in "$@"; do [ -f "$st/containers/$n" ] || exit 1; rm -f "$st/containers/$n" "$st/ports/$n"; done ;;
|
|
port)
|
|
[ -f "$st/ports/$1" ] || exit 1
|
|
if [ $# -ge 2 ]; then sed 's/^.* -> //' "$st/ports/$1"; else cat "$st/ports/$1"; fi ;;
|
|
exec)
|
|
input=0
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in -i) input=1; shift ;; -e | -u) shift 2 ;; *) break ;; esac
|
|
done
|
|
[ "$(cat "$st/containers/$1" 2>/dev/null)" = running ] || exit 1
|
|
shift
|
|
# psql reads -c when given (stdin untouched, as the real psql does), else its stdin.
|
|
query='' prev='' has_c=0
|
|
for a in "$@"; do if [ "$prev" = -c ]; then query="$a"; has_c=1; fi; prev="$a"; done
|
|
if [ "$input" -eq 1 ] && [ "$has_c" -eq 0 ]; then query="$(head -c 65536 "$(save_stdin)")"; fi
|
|
tag="$(printf '%s\n' "$query" | sed -n 's/^-- db-trial:\([a-z-]*\)$/\1/p' | head -n 1)"
|
|
term_if "tag:$tag"
|
|
# commit-then-fail: the rotation commits (its marker becomes the digest), then the exec stream
|
|
# is lost. Without it, fail/rotate leaves the marker empty: not committed.
|
|
if [ "$tag" = rotate ] && [ -f "$st/commit-then-fail" ]; then
|
|
printf '%s\n' "${ROT_DIGEST:-}" > "$st/answers/rotation-marker"; echo "stub: stream lost" >&2; exit 3
|
|
fi
|
|
if [ -n "$tag" ] && [ -f "$st/fail/$tag" ]; then echo "stub: $tag refused" >&2; exit 3; fi
|
|
# txn-factors: what the grant transaction finds when it counts the factors again. Like psql with
|
|
# ON_ERROR_STOP, the session fails (\gset finds no row) when the SQL holds that count and the
|
|
# number is below the :need it was given; an SQL without the count goes through.
|
|
if [ "$tag" = grant-role ] && [ -f "$st/answers/txn-factors" ] && grep -q mfa_factors <<<"$query"; then
|
|
need='' prev=''
|
|
for a in "$@"; do case "$prev:$a" in -v:need=*) need="${a#need=}" ;; esac; prev="$a"; done
|
|
if [ "$(cat "$st/answers/txn-factors")" -lt "$need" ]; then echo "stub: no rows returned for \\gset" >&2; exit 3; fi
|
|
fi
|
|
if [ -n "$tag" ] && [ -s "$st/answers/$tag.seq" ]; then
|
|
head -n 1 "$st/answers/$tag.seq"; sed -i 1d "$st/answers/$tag.seq"
|
|
elif [ -n "$tag" ] && [ -f "$st/answers/$tag" ]; then cat "$st/answers/$tag"; fi
|
|
exit 0 ;;
|
|
*) echo "stub docker: unsupported $sub" >&2; exit 97 ;;
|
|
esac
|
|
STUB
|
|
cat > "$WORK/bin/curl" <<'STUB'
|
|
#!/usr/bin/env bash
|
|
# curl stand-in. The trial gateway's identity endpoint answers faunosteo_trial, or
|
|
# answers/identity, or fails (fail/identity, curl -f's exit 22). fail/admin-users: GoTrue's admin
|
|
# API refuses the account (exit 22).
|
|
{ printf 'curl'; for a in "$@"; do printf ' %s' "$a"; done; printf '\n'; } >> "$STUB_LOG"
|
|
for a in "$@"; do
|
|
case "$a" in
|
|
@-) cat > "$STUB_STATE/stdin/curl-$(date +%s%N)" ;;
|
|
# A header file (a process substitution): only a digest of what was sent is kept.
|
|
@/dev/fd/*) sha256sum < "${a#@}" | cut -c1-16 > "$STUB_STATE/curl-header-sha" ;;
|
|
esac
|
|
done
|
|
case "$*" in */admin/users*) [ ! -f "$STUB_STATE/fail/admin-users" ] || exit 22 ;; esac
|
|
case "${*: -1}" in
|
|
*/__faunosteo_stack)
|
|
[ ! -f "$STUB_STATE/fail/identity" ] || exit 22
|
|
if [ -f "$STUB_STATE/answers/identity" ]; then cat "$STUB_STATE/answers/identity"; else echo faunosteo_trial; fi ;;
|
|
esac
|
|
exit 0
|
|
STUB
|
|
# ss runs for real unless the case asks it to fail (it must then never read as "port free").
|
|
cat > "$WORK/bin/ss" <<'STUB'
|
|
#!/usr/bin/env bash
|
|
if [ -f "$STUB_STATE/fail/ss" ]; then echo "ss: cannot open netlink socket" >&2; exit 1; fi
|
|
exec "$(cat "$(dirname "$0")/real-ss")" "$@"
|
|
STUB
|
|
command -v ss > "$WORK/bin/real-ss"
|
|
# node and env run for real behind a wrapper that logs their argv (newlines as \n).
|
|
cat > "$WORK/bin/passthrough" <<'STUB'
|
|
#!/usr/bin/env bash
|
|
tool="$(basename "$0")"
|
|
{ printf '%s' "$tool"; for a in "$@"; do printf ' %s' "${a//$'\n'/\\n}"; done; printf '\n'; } >> "$STUB_LOG"
|
|
exec "$(cat "$(dirname "$0")/real-$tool")" "$@"
|
|
STUB
|
|
for tool in node env; do
|
|
command -v "$tool" > "$WORK/bin/real-$tool"
|
|
cp "$WORK/bin/passthrough" "$WORK/bin/$tool"
|
|
done
|
|
cat > "$WORK/repo/node_modules/.bin/supabase" <<'STUB'
|
|
#!/usr/bin/env bash
|
|
{ printf 'supabase'; for a in "$@"; do printf ' %s' "$a"; done; printf ' PGPASSWORD=%s\n' "${PGPASSWORD:+set}"; } >> "$STUB_LOG"
|
|
if [ "$*" = "--workdir . migration up --db-url postgresql://postgres@127.0.0.1:58432/postgres?sslmode=disable" ]; then
|
|
if [ -f "$STUB_STATE/term-in-migrate" ]; then bash "$STUB_TERM"; fi
|
|
for f in supabase/migrations/*.sql; do basename "$f" | cut -d_ -f1; done > "$STUB_STATE/answers/applied"
|
|
if [ -f "$STUB_STATE/fail/migrate" ]; then echo "stub: a migration failed after the others applied" >&2; exit 3; fi
|
|
exit 0
|
|
fi
|
|
exit 97
|
|
STUB
|
|
cat > "$WORK/repo/apps/app/node_modules/.bin/vite" <<'STUB'
|
|
#!/usr/bin/env bash
|
|
{ printf 'vite'; for a in "$@"; do printf ' %s' "$a"; done; printf '\n'
|
|
printf 'vite-env anon-sha=%s pgpassword=%s node-options=%s gateway=%s host=%s url=%s proxies=%s\n' \
|
|
"$(printf '%s' "${VITE_SUPABASE_ANON_KEY:-}" | sha256sum | cut -c1-16)" "${PGPASSWORD:+set}" \
|
|
"${NODE_OPTIONS:-}" "${FAUNOSTEO_TRIAL_GATEWAY:-}" "${FAUNOSTEO_TRIAL_HOST:-}" "${VITE_SUPABASE_URL:-}" \
|
|
"${http_proxy:-}${HTTP_PROXY:-}${https_proxy:-}${HTTPS_PROXY:-}${all_proxy:-}${ALL_PROXY:-}${NODE_USE_ENV_PROXY:-}"; } >> "$STUB_LOG"
|
|
# term-in-vite: the app is running when the script gets a SIGTERM.
|
|
if [ -f "$STUB_STATE/term-in-vite" ]; then bash "$STUB_TERM"; fi
|
|
# vite-hold: a long-running server on 5194 that writes its pid and takes a second to die on SIGTERM
|
|
# (the launcher resets SIGINT to default: that is about the harness's own backgrounded shell, the real
|
|
# Vite dies on a terminal Ctrl+C as node resets dispositions at startup). vite-hold-sig: the signaller script to
|
|
# run once it listens (term-trial.sh or int-trial.sh), the pid file written before.
|
|
if [ -f "$STUB_STATE/vite-hold" ]; then
|
|
exec python3 -c 'import os, signal, socket, sys, time
|
|
s = socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
s.bind(("127.0.0.1", 5194)); s.listen(1)
|
|
open(sys.argv[1], "w").write(str(os.getpid()))
|
|
def term(*_):
|
|
time.sleep(1); sys.exit(0)
|
|
signal.signal(signal.SIGTERM, term)
|
|
if os.path.exists(sys.argv[2]): os.system("bash " + open(sys.argv[2]).read().strip())
|
|
time.sleep(30)' "$STUB_STATE/vite.pid" "$STUB_STATE/vite-hold-sig"
|
|
fi
|
|
STUB
|
|
cat > "$WORK/repo/scripts/upload-sheet-assets.sh" <<'STUB'
|
|
#!/usr/bin/env bash
|
|
{ printf 'upload'; for a in "$@"; do printf ' %s' "$a"; done; printf '\n'
|
|
printf 'upload-env url=%s key-sha=%s dev-host=%s init-cwd=%s\n' "${SUPABASE_URL:-}" \
|
|
"$(printf '%s' "${SUPABASE_SERVICE_ROLE_KEY:-}" | sha256sum | cut -c1-16)" \
|
|
"${FAUNOSTEO_DEV_HOST:+set}" "${INIT_CWD:+set}"; } >> "$STUB_LOG"
|
|
if [ "${1:-}" = --check ]; then
|
|
echo "horse.svg 0ea5202fa3b95bac167b87c12ee969ab0272e085b60c2d34dbca6202c5f08541.svg: would object verified, row confirmed, nothing to do"
|
|
else
|
|
echo "horse.svg done"
|
|
fi
|
|
echo ok
|
|
STUB
|
|
cat > "$WORK/repo/scripts/import-equine.sh" <<'STUB'
|
|
#!/usr/bin/env bash
|
|
{ printf 'import-equine'; for a in "$@"; do printf ' %s' "$a"; done; printf '\n'; } >> "$STUB_LOG"
|
|
STUB
|
|
chmod +x "$WORK/bin/docker" "$WORK/bin/curl" "$WORK/bin/ss" "$WORK/bin/node" "$WORK/bin/env" \
|
|
"$WORK/repo/node_modules/.bin/supabase" "$WORK/repo/apps/app/node_modules/.bin/vite"
|
|
BASE_PATH="$PATH"
|
|
# Run by every case, with that case's own PATH: docker, curl, node and env must resolve to the stub
|
|
# folder (the first PATH entry), ss to the stub there or, when it has none, to nothing.
|
|
verify_stub_shadow() {
|
|
local stub_dir="${CASE_PATH%%:*}" tool found
|
|
for tool in docker curl node env ss; do
|
|
found="$(PATH="$CASE_PATH" command -v "$tool" || true)"
|
|
if [ "$tool" = ss ] && [ ! -e "$stub_dir/ss" ]; then
|
|
[ -z "$found" ] && continue
|
|
elif [ "$found" = "$stub_dir/$tool" ]; then
|
|
continue
|
|
fi
|
|
echo "db-trial-check: with the case's PATH, $tool resolves to '${found:-nothing}', not the stub in $stub_dir: nothing was run" >&2
|
|
exit 1
|
|
done
|
|
}
|
|
# A PATH with every tool but ss: the stubs (no ss wrapper), then a link to each executable of the
|
|
# real PATH except ss. Used by the "ss is not installed" case only.
|
|
mkdir -p "$WORK/bin-no-ss" "$WORK/path-no-ss"
|
|
cp -p "$WORK/bin/docker" "$WORK/bin/curl" "$WORK/bin/node" "$WORK/bin/env" "$WORK/bin/real-node" "$WORK/bin/real-env" "$WORK/bin-no-ss/"
|
|
IFS=: read -ra PATH_DIRS <<<"$BASE_PATH"
|
|
for dir in "${PATH_DIRS[@]}"; do
|
|
for exe in "$dir"/*; do
|
|
name="${exe##*/}"
|
|
if [ "$name" != ss ] && [ -x "$exe" ] && [ ! -e "$WORK/path-no-ss/$name" ]; then ln -s "$exe" "$WORK/path-no-ss/$name"; fi
|
|
done
|
|
done
|
|
|
|
# A PATH whose first folder holds a copy of the stubs and an `mv` that refuses the one rename of
|
|
# rotate-secrets (secrets.next.env over secrets.env): the window between the commit and the rename.
|
|
mkdir -p "$WORK/bin-mvfail"
|
|
cp -p "$WORK/bin/"* "$WORK/bin-mvfail/"
|
|
cat > "$WORK/bin-mvfail/mv" <<STUB
|
|
#!/usr/bin/env bash
|
|
case "\$*" in *secrets.next.env*secrets.env) echo "stub mv: refused" >&2; exit 1 ;; esac
|
|
exec $(command -v mv) "\$@"
|
|
STUB
|
|
chmod +x "$WORK/bin-mvfail/mv"
|
|
# The same, for a SIGTERM that falls on a rename: rotate-keys' (secrets.env.new, never moved) and
|
|
# rotate-secrets' (secrets.next.env, moved, then the signal: before ROTATION_COMMITTED is set).
|
|
mkdir -p "$WORK/bin-mvterm"
|
|
cp -p "$WORK/bin/"* "$WORK/bin-mvterm/"
|
|
cat > "$WORK/bin-mvterm/mv" <<STUB
|
|
#!/usr/bin/env bash
|
|
case "\$*" in
|
|
*secrets.env.new*) bash "\$STUB_TERM"; exit 0 ;;
|
|
*secrets.next.env*secrets.env) $(command -v mv) "\$@"; bash "\$STUB_TERM"; exit 0 ;;
|
|
esac
|
|
exec $(command -v mv) "\$@"
|
|
STUB
|
|
chmod +x "$WORK/bin-mvterm/mv"
|
|
|
|
ASSET_LINE="$(node -e 'for (const a of require(process.argv[1])) console.log(a.sha256 + " " + a.byte_size)' "$WORK/repo/$SEED_REL/assets.json")"
|
|
new_case() { # name
|
|
CASE="$WORK/cases/$1"
|
|
mkdir -p "$CASE/home" "$CASE/stub/containers" "$CASE/stub/ports" "$CASE/stub/volumes" "$CASE/stub/networks" \
|
|
"$CASE/stub/answers" "$CASE/stub/fail" "$CASE/stub/stdin"
|
|
: > "$CASE/log"
|
|
STATE_DIR="$CASE/home/.cache/faunosteo-trial"
|
|
echo 'official=1 historical=1 versions=1 draft_equal=true accounts=0' > "$CASE/stub/answers/equine"
|
|
printf '%s\n' "$ASSET_LINE" > "$CASE/stub/answers/asset-rows"
|
|
echo 1 > "$CASE/stub/answers/assets-uploaded"
|
|
echo 0 > "$CASE/stub/answers/rotation-active"
|
|
echo ok > "$CASE/stub/answers/grant-catalog"
|
|
echo 0 > "$CASE/stub/answers/grant-factor-count"
|
|
EXTRA=()
|
|
CASE_PATH="$WORK/bin:$BASE_PATH"
|
|
# The no-daemon barrier: a unix socket that does not exist (so the script's local-daemon guard
|
|
# accepts it and a real docker, were a stub missing, would still reach nothing), and a context
|
|
# that does not exist for the cases that clear DOCKER_HOST.
|
|
CASE_DOCKER_HOST="unix://$WORK/no-daemon.sock"
|
|
}
|
|
# Gives a script a terminal (a pty), types its stdin there, copies the output, returns the exit code.
|
|
PTY_DRIVER='
|
|
import os, pty, sys
|
|
pid, fd = pty.fork()
|
|
if pid == 0:
|
|
os.execvp(sys.argv[1], sys.argv[1:])
|
|
try:
|
|
os.write(fd, sys.stdin.buffer.read())
|
|
except OSError:
|
|
pass
|
|
while True:
|
|
try:
|
|
chunk = os.read(fd, 4096)
|
|
except OSError:
|
|
break
|
|
if not chunk:
|
|
break
|
|
sys.stdout.buffer.write(chunk)
|
|
sys.stdout.flush()
|
|
_, status = os.waitpid(pid, 0)
|
|
sys.exit(os.waitstatus_to_exitcode(status))
|
|
'
|
|
# The same for a hidden prompt: each line is typed once the previous prompt (text ending in ": ") has
|
|
# been printed and the script had time to switch the terminal echo off, so a password is never echoed
|
|
# into the captured output.
|
|
PTY_PROMPT_DRIVER='
|
|
import os, pty, sys, time
|
|
pid, fd = pty.fork()
|
|
if pid == 0:
|
|
os.execvp(sys.argv[1], sys.argv[1:])
|
|
lines = sys.stdin.buffer.read().split(b"\n")
|
|
if lines and lines[-1] == b"":
|
|
lines.pop()
|
|
def pump(stop_at_prompt):
|
|
seen = b""
|
|
while True:
|
|
try:
|
|
chunk = os.read(fd, 4096)
|
|
except OSError:
|
|
return False
|
|
if not chunk:
|
|
return False
|
|
sys.stdout.buffer.write(chunk)
|
|
seen += chunk
|
|
if stop_at_prompt and seen.endswith(b": "):
|
|
return True
|
|
alive = True
|
|
for line in lines:
|
|
alive = pump(True)
|
|
if not alive:
|
|
break
|
|
time.sleep(0.3)
|
|
os.write(fd, line + b"\n")
|
|
if alive:
|
|
pump(False)
|
|
sys.stdout.flush()
|
|
_, status = os.waitpid(pid, 0)
|
|
sys.exit(os.waitstatus_to_exitcode(status))
|
|
'
|
|
LAUNCH=()
|
|
run_script() { # script args... → RC, output in $CASE/out; stdin as the caller set it
|
|
local script="$1" entry
|
|
shift
|
|
# PATH comes after EXTRA below, so a case cannot override it; a PATH in EXTRA is refused outright.
|
|
for entry in "${EXTRA[@]}"; do
|
|
case "$entry" in PATH=*) echo "db-trial-check: EXTRA carries a PATH: nothing was run" >&2; exit 1 ;; esac
|
|
done
|
|
verify_stub_shadow
|
|
( cd "$WORK/repo" && env -i HOME="$CASE/home" LANG=C.UTF-8 \
|
|
DOCKER_HOST="$CASE_DOCKER_HOST" DOCKER_CONTEXT=faunosteo-check-no-such-context DOCKER_CONFIG="$WORK/docker-config" \
|
|
STUB_LOG="$CASE/log" STUB_STATE="$CASE/stub" STUB_TERM="$WORK/term-trial.sh" FAUNOSTEO_TRIAL_HOST=127.0.0.1 "${EXTRA[@]}" PATH="$CASE_PATH" \
|
|
"${LAUNCH[@]}" bash "scripts/$script" "$@" ) > "$CASE/out" 2>&1
|
|
RC=$?
|
|
}
|
|
trial() { LAUNCH=(); run_script db-trial.sh "$@" < /dev/null; }
|
|
trial_input() { LAUNCH=(); run_script db-trial.sh "$@"; } # stdin from the caller (a pipe: no terminal)
|
|
trial_tty() { # input args...: the input typed at the script's terminal
|
|
local input="$1"
|
|
shift
|
|
LAUNCH=(python3 -c "$PTY_DRIVER")
|
|
run_script db-trial.sh "$@" <<<"$input"
|
|
LAUNCH=()
|
|
}
|
|
trial_typed() { # lines args...: lines typed one per prompt at the script's terminal, never echoed
|
|
local input="$1"
|
|
shift
|
|
LAUNCH=(python3 -c "$PTY_PROMPT_DRIVER")
|
|
run_script db-trial.sh "$@" <<<"$input"
|
|
LAUNCH=()
|
|
}
|
|
sandbox() { LAUNCH=(); run_script db-sandbox.sh "$@" < /dev/null; }
|
|
fresh_log() { : > "$CASE/log"; }
|
|
|
|
docker_calls() { grep '^docker ' "$CASE/log" || true; }
|
|
# Calls that change something: Docker writes, the CLI, the upload tool, Vite.
|
|
changes() {
|
|
grep -E '^(docker (run|start|restart|stop|rm|volume (create|rm)|network (create|rm))|supabase |upload |vite )' "$CASE/log" || true
|
|
}
|
|
out_has() { grep -qF -- "$1" "$CASE/out"; }
|
|
log_has() { grep -qF -- "$1" "$CASE/log"; }
|
|
refused() { [ "$RC" -ne 0 ] && [ -z "$(changes)" ] && out_has "$1"; }
|
|
refused_no_docker() { refused "$1" && [ -z "$(docker_calls)" ]; }
|
|
refused_early() { [ "$RC" -ne 0 ] && [ ! -s "$CASE/log" ] && out_has "$1"; }
|
|
mode_is() { [ "$(stat -c %a "$1")" = "$2" ]; }
|
|
values_absent_from() { # secrets file, files...
|
|
local value file
|
|
[ -f "$1" ] || return 1
|
|
while IFS='=' read -r _ value; do
|
|
[ -n "$value" ] || continue
|
|
for file in "${@:2}"; do
|
|
if [ -f "$file" ] && grep -qF -- "$value" "$file"; then return 1; fi
|
|
done
|
|
done < "$1"
|
|
}
|
|
# The log holds every argv of docker, curl, node, env, the CLI, Vite and the tools.
|
|
secrets_absent() { values_absent_from "$1" "$CASE/log" "$CASE/out"; }
|
|
stdin_files() { find "$CASE/stub/stdin" -type f; }
|
|
stdin_has() { stdin_files | xargs -r grep -lF -- "$1" | grep -q .; }
|
|
stdin_lacks() { ! stdin_has "$1"; }
|
|
run_line() { docker_calls | grep -E "^docker run -d --name $1 " || true; }
|
|
expect_run() { # name port inner memory pids [volume]
|
|
local line
|
|
line="$(run_line "$1")"
|
|
[ "$(grep -c . <<<"$line")" -eq 1 ] || return 1
|
|
grep -qF -- "--network faunosteo_trial_net --restart no --memory $4 --cpus 1 --pids-limit $5 -p 127.0.0.1:$2:$3 " <<<"$line" || return 1
|
|
[ "$(grep -oE -- ' -p [^ ]+' <<<"$line" | wc -l)" -eq 1 ] || return 1
|
|
if [ -n "${6:-}" ]; then grep -qF -- " -v $6 " <<<"$line"; else ! grep -qE -- ' -v ' <<<"$line"; fi
|
|
}
|
|
# Resource names plus the Supabase roles and the migrations schema that SQL text in argv may name.
|
|
# faunosteo_stack and faunosteo_trial: the gateway identity path and body (/__faunosteo_stack answers faunosteo_trial), not resource names.
|
|
ALLOWED_NAMES='faunosteo_trial_(db|mail|auth|storage|rest|gateway|helper|net)|supabase_(admin|auth_admin|storage_admin|migrations)|faunosteo_stack|faunosteo_trial'
|
|
only_trial_names() { ! docker_calls | grep -oE '(faunosteo|supabase)_[A-Za-z0-9_]+' | grep -vxE "$ALLOWED_NAMES" | grep -q .; }
|
|
no_volume_removal() { ! log_has 'docker volume rm'; }
|
|
# Each whole line of the text comes before its first line matching the ERE, in the order given.
|
|
lines_before_first() { # text pattern line...
|
|
local text="$1" pattern="$2" first n line previous=0
|
|
first="$(grep -nE -- "$pattern" <<<"$text" | head -n 1 | cut -d: -f1)"
|
|
[ -n "$first" ] || return 1
|
|
shift 2
|
|
for line in "$@"; do
|
|
n="$(grep -nxF -- "$line" <<<"$text" | head -n 1 | cut -d: -f1)"
|
|
[ -n "$n" ] && [ "$n" -lt "$first" ] && [ "$n" -gt "$previous" ] || return 1
|
|
previous="$n"
|
|
done
|
|
}
|
|
line_of() { grep -nF -- "$1" "$CASE/log" | head -n 1 | cut -d: -f1; }
|
|
before() { local a b; a="$(line_of "$1")"; b="$(line_of "$2")"; [ -n "$a" ] && [ -n "$b" ] && [ "$a" -lt "$b" ]; }
|
|
hold_port() { # port → LISTENER pid, or returns 1 when the port cannot be held
|
|
python3 -c 'import socket, sys, time
|
|
s = socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
s.bind(("127.0.0.1", int(sys.argv[1]))); s.listen(1); print("up", flush=True); time.sleep(30)' "$1" > "$CASE/listener" 2>&1 &
|
|
LISTENER=$!
|
|
for _ in $(seq 1 50); do if grep -q up "$CASE/listener"; then return 0; fi; sleep 0.1; done
|
|
kill "$LISTENER" 2>/dev/null
|
|
return 1
|
|
}
|
|
release_port() { kill "$LISTENER" 2>/dev/null; wait "$LISTENER" 2>/dev/null; }
|
|
# Every logged curl starts with -q (no ~/.curlrc) and --noproxy '*' (no proxy variable).
|
|
curls_pinned() { grep -q '^curl ' "$CASE/log" && ! grep '^curl ' "$CASE/log" | grep -v "^curl -q --noproxy \* " | grep -q .; }
|
|
backup_count() { find "$STATE_DIR/backups" -mindepth 1 -maxdepth 1 -type d | wc -l; }
|
|
# Rewrites one key line of a secrets file (default the case's secrets.env) with a key of the given
|
|
# issuer and role, signed with that file's own secret or a random one, expiring in <offset> s.
|
|
forge() { # var issuer own|other role [offset] [file]
|
|
FORGE_FILE="${6:-$STATE_DIR/secrets.env}" node -e '
|
|
const fs = require("fs"), c = require("crypto");
|
|
const [name, iss, source, role, offset] = process.argv.slice(1);
|
|
const file = process.env.FORGE_FILE;
|
|
const lines = fs.readFileSync(file, "utf8").trim().split("\n");
|
|
const own = lines.find((l) => l.startsWith("TR_JWT_SECRET=")).slice(14);
|
|
const secret = source === "own" ? own : c.randomBytes(32).toString("hex");
|
|
const b64 = (o) => Buffer.from(JSON.stringify(o)).toString("base64url");
|
|
const h = b64({ alg: "HS256", typ: "JWT" }), now = Math.floor(Date.now() / 1000);
|
|
const b = b64({ role, iss, iat: now - 7200, exp: now + Number(offset) });
|
|
const jwt = h + "." + b + "." + c.createHmac("sha256", secret).update(h + "." + b).digest("base64url");
|
|
fs.writeFileSync(file, lines.map((l) => l.startsWith(name + "=") ? name + "=" + jwt : l).join("\n") + "\n", { mode: 0o600 });
|
|
' "$1" "$2" "$3" "$4" "${5:-3600}"
|
|
}
|
|
env_file_state() { # file → digest and mtime, to prove a refusal wrote nothing
|
|
printf '%s %s\n' "$(sha256sum < "$1" | cut -d' ' -f1)" "$(stat -c %Y "$1")"
|
|
}
|
|
|
|
echo "-- static"
|
|
if command -v shellcheck >/dev/null; then
|
|
check "shellcheck: db-trial.sh and this harness" bash -c 'cd "$1" && shellcheck -x scripts/db-trial.sh scripts/db-trial-check.sh' _ "$REPO"
|
|
check "shellcheck: db-sandbox.sh (pre-existing SC1090, SC1091, SC2016 excluded)" shellcheck -e SC1090,SC1091,SC2016 "$REPO/scripts/db-sandbox.sh"
|
|
else
|
|
fail "shellcheck is not installed"
|
|
fi
|
|
check "db-sandbox.sh: additions only since b215b89 (its commands unchanged)" bash -c 'cd "$1" && [ "$(git diff --numstat b215b89 -- scripts/db-sandbox.sh | cut -f2)" = 0 ]' _ "$REPO"
|
|
TRIAL_PORTS="$(grep -oE 'PORT_[A-Z_]+=[0-9]+' "$REPO/scripts/db-trial.sh" | cut -d= -f2 | sort -u)"
|
|
SANDBOX_PORTS="$(grep -oE 'PORT_[A-Z_]+=[0-9]+' "$REPO/scripts/db-sandbox.sh" | cut -d= -f2 | sort -u)"
|
|
DEV_PORTS="$(printf '%s\n' 5173 5191 5192 54321 54322 54323 54324 54325 | sort -u)"
|
|
check "trial ports are the ratified ones" [ "$TRIAL_PORTS" = "$(printf '%s\n' 5194 58025 58300 58432 58500 58801 58999 | sort -u)" ]
|
|
check "no trial port is a sandbox or DEV port" [ -z "$(comm -12 <(printf '%s\n' "$TRIAL_PORTS") <(printf '%s\n%s\n' "$SANDBOX_PORTS" "$DEV_PORTS" | sort -u))" ]
|
|
check "db-trial.sh never runs a bare inspect" bash -c '! grep -nE "docker (container |volume |network |image )?inspect [^-]" "$1"' _ "$REPO/scripts/db-trial.sh"
|
|
|
|
echo "-- refusals before anything"
|
|
new_case sandbox-env; EXTRA=(SANDBOX_AUTH_URL=http://127.0.0.1:57999); trial plan
|
|
check "a SANDBOX_* variable stops every command before any call" refused_early "SANDBOX_AUTH_URL is set"
|
|
new_case state-in-repo; EXTRA=(FAUNOSTEO_TRIAL_DIR="$WORK/repo/trial-state"); trial create
|
|
check "a state folder inside the repository is refused" refused_early "outside the repository"
|
|
new_case state-in-git; git init -q "$CASE/gitrepo"; EXTRA=(FAUNOSTEO_TRIAL_DIR="$CASE/gitrepo/state"); trial create
|
|
check "a state folder inside any git work tree is refused" refused_early "outside every git work tree"
|
|
new_case state-git-file; mkdir -p "$CASE/outer"; : > "$CASE/outer/.git"; EXTRA=(FAUNOSTEO_TRIAL_DIR="$CASE/outer/state"); trial create
|
|
check "a state folder under an ancestor holding a .git FILE is refused" refused_early "outside every git work tree"
|
|
new_case state-in-git-env; git init -q "$CASE/gitrepo"; EXTRA=(FAUNOSTEO_TRIAL_DIR="$CASE/gitrepo/state" GIT_DIR="$CASE/no-such-git-dir" GIT_WORK_TREE="$CASE/home"); trial create
|
|
check "a stray GIT_DIR / GIT_WORK_TREE does not hide a git work tree: still refused" refused_early "outside every git work tree"
|
|
new_case state-symlink-repo; ln -s "$WORK/repo/trial-state" "$CASE/link"; EXTRA=(FAUNOSTEO_TRIAL_DIR="$CASE/link"); trial create
|
|
check "a state folder that is a symlink into the repository is refused (canonical path)" refused_early "outside the repository"
|
|
new_case state-symlink-sandbox; mkdir -p "$CASE/sbstate"; ln -s "$CASE/sbstate" "$CASE/link"
|
|
EXTRA=(FAUNOSTEO_TRIAL_DIR="$CASE/link" FAUNOSTEO_SANDBOX_DIR="$CASE/sbstate"); trial create
|
|
check "a state folder that is a symlink to the sandbox's state is refused" refused_early "sandbox's state folder"
|
|
new_case ss-fails; : > "$CASE/stub/fail/ss"; trial create
|
|
check "ss failing: create refuses, a port is never read as free" refused "ss cannot list the listening ports"
|
|
new_case ss-absent; CASE_PATH="$WORK/bin-no-ss:$WORK/path-no-ss"; trial create
|
|
check "ss absent from PATH: every command refuses before any call" refused_early "ss (iproute2) is not installed"
|
|
new_case state-symlink-ok; mkdir -p "$CASE/real"; ln -s "$CASE/real" "$CASE/link"; EXTRA=(FAUNOSTEO_TRIAL_DIR="$CASE/link")
|
|
trial create; RC_CREATE=$RC; trial status; RC_STATUS=$RC; trial stop
|
|
check "a state folder reached through a symlink works: create, status, stop on the real folder (700)" bash -c '[ "$1" -eq 0 ] && [ "$2" -eq 0 ] && [ "$3" -eq 0 ] && [ "$(stat -c %a "$4")" = 700 ] && [ -f "$4/secrets.env" ]' _ "$RC_CREATE" "$RC_STATUS" "$RC" "$CASE/real"
|
|
new_case create-db-wide; : > "$CASE/stub/publish-wide-faunosteo_trial_db"; trial create
|
|
check "create: Postgres published beyond 127.0.0.1 stops it before any migration" bash -c '[ "$1" -ne 0 ] && grep -qF "faunosteo_trial_db is not published on 127.0.0.1:58432 only" "$2" && ! grep -q "^supabase " "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
new_case foreign-state; mkdir -p "$CASE/foreign"; : > "$CASE/foreign/secrets.sh"; EXTRA=(FAUNOSTEO_TRIAL_DIR="$CASE/foreign"); trial create
|
|
check "a non-empty folder without the trial marker is refused" refused_early "holds no db:trial state"
|
|
new_case sandbox-state; EXTRA=(FAUNOSTEO_TRIAL_DIR="$CASE/shared" FAUNOSTEO_SANDBOX_DIR="$CASE/shared"); trial create
|
|
check "the sandbox's state folder is refused" refused_early "sandbox's state folder"
|
|
new_case usage; trial
|
|
check "no command prints the usage and runs nothing" refused_early "pnpm db:trial create"
|
|
new_case remote-docker-host; CASE_DOCKER_HOST=tcp://10.0.0.1:2375; trial status
|
|
check "a DOCKER_HOST that is not a unix socket is refused before any call" refused_early "is not a local unix socket"
|
|
new_case remote-context; CASE_DOCKER_HOST=''; echo tcp://10.0.0.1:2376 > "$CASE/stub/answers/context"; trial status
|
|
check "a current context that is not a unix socket is refused before any change" refused "is not a local unix socket"
|
|
new_case remote-docker-host-credentials; CASE_DOCKER_HOST=tcp://deploy:s3cretpw@10.0.0.1:2375; trial status
|
|
check "a refused endpoint never echoes its credentials" bash -c '[ "$1" -ne 0 ] && grep -qF "10.0.0.1:2375" "$2" && ! grep -qF -e s3cretpw -e deploy "$2" && [ ! -s "$3" ]' _ "$RC" "$CASE/out" "$CASE/log"
|
|
new_case local-context; CASE_DOCKER_HOST=''; trial plan
|
|
check "no DOCKER_HOST and a unix context: plan answers and prints that endpoint" bash -c '[ "$1" -eq 0 ] && grep -qF "Docker endpoint: unix:///stub/docker.sock" "$2"' _ "$RC" "$CASE/out"
|
|
new_case unreadable-context; CASE_DOCKER_HOST=''; : > "$CASE/stub/fail/context"; trial status
|
|
check "a current context that cannot be read is refused before any change" refused "cannot be read"
|
|
new_case daemon-down; : > "$CASE/stub/fail/daemon"; trial create
|
|
check "Docker daemon down: create refuses, no state written" bash -c '[ "$1" -ne 0 ] && grep -qF "Docker daemon unreachable" "$2" && [ ! -e "$3" ]' _ "$RC" "$CASE/out" "$STATE_DIR"
|
|
trial plan
|
|
check "Docker daemon down: plan still answers and names it" bash -c '[ "$1" -eq 0 ] && grep -qF "Docker daemon is unreachable" "$2" && grep -qF "create would refuse" "$2"' _ "$RC" "$CASE/out"
|
|
mkdir -p "$CASE/stub/volumes"; : > "$CASE/stub/volumes/faunosteo_trial_db"; trial plan
|
|
check "Docker daemon down: plan lists no existing resource (one exists in the stub) and says so" bash -c '[ "$1" -eq 0 ] && grep -qF "existing containers, network and volumes are not listed" "$2" && ! grep -qF "already exists" "$2"' _ "$RC" "$CASE/out"
|
|
new_case inspect-error; : > "$CASE/stub/fail/inspect-error"; trial create
|
|
check "an inspect error other than 'No such' is never read as absent: create refuses before any change" bash -c '[ "$1" -ne 0 ] && grep -qF "docker container inspect faunosteo_trial_db failed" "$2" && [ -z "$3" ] && [ ! -e "$4" ]' _ "$RC" "$CASE/out" "$(changes)" "$STATE_DIR"
|
|
new_case helper-fails; : > "$CASE/stub/fail/helper"; trial create
|
|
check "create: a failing helper check names its causes and stops before any resource" bash -c '[ "$1" -ne 0 ] && grep -qF "helper check failed: the image lacks tar or du, or a faunosteo_trial_helper container is left over (docker rm faunosteo_trial_helper)" "$2" && ! grep -qE "^docker (network|volume) create" "$3" && [ ! -e "$4" ]' _ "$RC" "$CASE/out" "$CASE/log" "$STATE_DIR"
|
|
new_case existing-volume; : > "$CASE/stub/volumes/faunosteo_trial_db"; trial create
|
|
check "an existing faunosteo_trial_ volume: create refuses, nothing changed" refused "already exist"
|
|
new_case port-taken
|
|
if hold_port 58801; then trial create; check "a taken port: create refuses, nothing changed" refused "58801 is taken"; release_port
|
|
else fail "could not hold 127.0.0.1:58801 for the port case"; fi
|
|
|
|
echo "-- plan"
|
|
new_case plan; trial plan
|
|
check "plan: read-only, proceeds on a clean host" bash -c '[ "$1" -eq 0 ]' _ "$RC"
|
|
check "plan: names the Docker endpoint" out_has "Docker endpoint: unix://"
|
|
check "plan: no change" [ -z "$(changes)" ]
|
|
check "plan: names every container, limit and volume place" bash -c 'grep -qF "faunosteo_trial_db" "$1" && grep -qF -- "--memory 1g" "$1" && grep -qF "/stub/docker-root/volumes/faunosteo_trial_storage/_data" "$1" && grep -qF "create would proceed" "$1"' _ "$CASE/out"
|
|
|
|
echo "-- create"
|
|
new_case create-fails-early; : > "$CASE/stub/fail/networks-create"; trial create
|
|
check "create dying before its first resource removes the state files it wrote" bash -c '[ "$1" -ne 0 ] && grep -qF "state files it wrote are removed" "$2" && [ ! -e "$3/secrets.env" ] && [ ! -e "$3/db.env" ] && [ ! -e "$3/stack.conf" ]' _ "$RC" "$CASE/out" "$STATE_DIR"
|
|
check "create dying early: nothing to undo in Docker" bash -c '! grep -qE "^docker (volume create|run -d)" "$1"' _ "$CASE/log"
|
|
new_case create-network-half; : > "$CASE/stub/fail/networks-create-after"; trial create
|
|
check "create: a network made then reported failed keeps the state files and names the network" bash -c '[ "$1" -ne 0 ] && grep -qF "nothing was removed" "$2" && grep -qF "network faunosteo_trial_net" "$2" && [ -f "$3/secrets.env" ]' _ "$RC" "$CASE/out" "$STATE_DIR"
|
|
new_case equine-mismatch; echo 'official=2 historical=1 versions=1 draft_equal=true accounts=0' > "$CASE/stub/answers/equine"; trial create
|
|
check "create: an equine sheet that is not the seed's stops it, resources named" bash -c '[ "$1" -ne 0 ] && grep -qF "is not the seed" "$2" && grep -qF "nothing was removed" "$2" && ! grep -q "^docker run -d --name faunosteo_trial_rest " "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
new_case asset-rows-mismatch; printf '%s\n' "0000 1" > "$CASE/stub/answers/asset-rows"; trial create
|
|
check "create: drawing rows that differ from assets.json stop it" bash -c '[ "$1" -ne 0 ] && grep -qF "drawing rows differ" "$2"' _ "$RC" "$CASE/out"
|
|
new_case create; trial create
|
|
check "create succeeds on an empty host" [ "$RC" -eq 0 ]
|
|
check "create: the Rust pipeline check runs before any change" before 'import-equine --check' 'docker network create'
|
|
check "create: the helper image holds tar and du, checked before any resource" before 'docker run --rm --name faunosteo_trial_helper --network none --entrypoint sh public.ecr.aws/supabase/postgres:17.11.0.004 -c command -v tar && command -v du' 'docker network create'
|
|
check "create: network and volumes under literal trial names" bash -c 'grep -qx "docker network create --label faunosteo.stack=trial faunosteo_trial_net" "$1" && grep -qx "docker volume create --label faunosteo.stack=trial faunosteo_trial_db" "$1" && grep -qx "docker volume create --label faunosteo.stack=trial faunosteo_trial_storage" "$1"' _ "$CASE/log"
|
|
check "create: db name, loopback port, caps, volume" expect_run faunosteo_trial_db 58432 5432 1g 512 faunosteo_trial_db:/var/lib/postgresql/data
|
|
check "create: mail" expect_run faunosteo_trial_mail 58025 8025 64m 64
|
|
check "create: auth" expect_run faunosteo_trial_auth 58999 9999 128m 256
|
|
check "create: storage with its volume" expect_run faunosteo_trial_storage 58500 5000 256m 256 faunosteo_trial_storage:/mnt
|
|
check "create: rest" expect_run faunosteo_trial_rest 58300 3000 384m 256
|
|
check "create: gateway" expect_run faunosteo_trial_gateway 58801 8000 64m 64
|
|
check "create: GoTrue sign-up closed" bash -c 'grep -E "^docker run -d --name faunosteo_trial_auth " "$1" | grep -qF GOTRUE_DISABLE_SIGNUP=true' _ "$CASE/log"
|
|
check "create: GoTrue mail links on the trial host's app origin" bash -c 'grep -E "^docker run -d --name faunosteo_trial_auth " "$1" | grep -qF "GOTRUE_SITE_URL=http://127.0.0.1:5194"' _ "$CASE/log"
|
|
check "create: gateway refuses GoTrue's admin API" log_has 'location /auth/v1/admin/ { return 403; }'
|
|
check "create: gateway names itself on /__faunosteo_stack" log_has 'location = /__faunosteo_stack { default_type text/plain; return 200 "faunosteo_trial\n"; }'
|
|
check "create: the database init turns statement logging on errors off first" log_has 'set log_min_error_statement = panic;'
|
|
check "create: the database init silences statement logging and verbose errors, in order, before the first ALTER" lines_before_first "$(run_line faunosteo_trial_db | sed 's/\\n/\n/g')" '^ALTER ' '\set VERBOSITY terse' "set log_statement = 'none';" 'set log_min_duration_statement = -1;' 'set log_min_error_statement = panic;' "set pgaudit.log = 'none';" 'set pg_stat_statements.track_utility = off;'
|
|
check "create: statement logging off on the server command line, so the image's init server (its migrate.sh ALTER USER ... PASSWORD) logs no statement" grep -qE 'exec docker-entrypoint\.sh postgres( [^ ]+)* -c log_statement=none( |$)' <(run_line faunosteo_trial_db | sed 's/\\n/\n/g')
|
|
check "create: migrations through the CLI on the trial URL only" log_has 'supabase --workdir . migration up --db-url postgresql://postgres@127.0.0.1:58432/postgres?sslmode=disable PGPASSWORD=set'
|
|
check "create: equine_draft.sql loaded" stdin_has "-- Official equine anatomical sheet"
|
|
check "create: seed.sql never loaded" stdin_lacks faunosteo.local
|
|
check "create: the seeded draft is compared with document.json" stdin_has '$faunosteo_trial_doc$'
|
|
check "create: only trial names (and Supabase roles) in docker calls" only_trial_names
|
|
check "create: no volume removal" no_volume_removal
|
|
check "create: every curl pinned to its destination (-q, --noproxy)" curls_pinned
|
|
check "create: every container checked on 127.0.0.1 only" log_has 'docker port faunosteo_trial_gateway'
|
|
check "create: node ran behind the argv logger" log_has 'node -e '
|
|
check "create: state folder 700, backups 700, files 600" bash -c 'for f in "$1" "$1/backups"; do [ "$(stat -c %a "$f")" = 700 ] || exit 1; done; for f in secrets.env db.env auth.env storage.env rest.env stack.conf migrations.sha256 .faunosteo-trial-state; do [ "$(stat -c %a "$1/$f")" = 600 ] || exit 1; done; ! ls "$1"/*.new >/dev/null 2>&1' _ "$STATE_DIR"
|
|
check "create: the lock file is 600" mode_is "$STATE_DIR/.lock" 600
|
|
check "create: keys for the issuer faunosteo-trial, one year" node -e '
|
|
const lines = Object.fromEntries(require("fs").readFileSync(process.argv[1], "utf8").trim().split("\n").map((l) => [l.slice(0, l.indexOf("=")), l.slice(l.indexOf("=") + 1)]));
|
|
for (const [name, role] of [["TR_ANON_KEY", "anon"], ["TR_SERVICE_KEY", "service_role"]]) {
|
|
const p = JSON.parse(Buffer.from(lines[name].split(".")[1], "base64url"));
|
|
if (p.iss !== "faunosteo-trial" || p.role !== role || p.exp - p.iat !== 31536000) process.exit(1);
|
|
}' "$STATE_DIR/secrets.env"
|
|
check "create: stack.conf records the six images, no host" bash -c '! grep -q "^TRIAL_HOST=" "$1" && [ "$(grep -c "^IMAGE_" "$1")" -eq 6 ]' _ "$STATE_DIR/stack.conf"
|
|
check "create: one manifest line per migration file" [ "$(wc -l < "$STATE_DIR/migrations.sha256")" -eq "$(find "$WORK/repo/supabase/migrations" -name '*.sql' | wc -l)" ]
|
|
check "create: no secret in any argv (docker, curl, node, env, tools) or output" secrets_absent "$STATE_DIR/secrets.env"
|
|
fresh_log; trial create
|
|
check "a second create refuses, nothing changed" refused "already holds a trial stack"
|
|
|
|
echo "-- stop, start, status"
|
|
if hold_port 5194; then fresh_log; trial stop; check "stop while port 5194 is in use (the app): refused, nothing stopped" refused "5194 is in use"; release_port
|
|
else fail "could not hold 127.0.0.1:5194 for the stop case"; fi
|
|
fresh_log; trial stop
|
|
check "stop: each container stopped, reverse order, nothing else" bash -c '[ "$1" -eq 0 ] && [ "$2" = "$(printf "docker stop -t 60 %s\n" faunosteo_trial_gateway faunosteo_trial_rest faunosteo_trial_storage faunosteo_trial_auth faunosteo_trial_mail faunosteo_trial_db)" ]' _ "$RC" "$(changes)"
|
|
if hold_port 58300; then fresh_log; trial start; check "start: a taken port refuses before any container starts" refused "58300 is taken"; release_port
|
|
else fail "could not hold 127.0.0.1:58300 for the start case"; fi
|
|
cp -p "$CASE/stub/ports/faunosteo_trial_rest" "$CASE/rest.port"
|
|
echo '3000/tcp -> 0.0.0.0:58300' > "$CASE/stub/ports/faunosteo_trial_rest"
|
|
fresh_log; trial start
|
|
check "start: a container published on 0.0.0.0 is refused" bash -c '[ "$1" -ne 0 ] && grep -qF "faunosteo_trial_rest is not published on 127.0.0.1:58300 only" "$2"' _ "$RC" "$CASE/out"
|
|
cp -p "$CASE/rest.port" "$CASE/stub/ports/faunosteo_trial_rest"
|
|
fresh_log; trial stop; fresh_log; trial start
|
|
check "start: same containers in order, nothing created" bash -c '[ "$1" -eq 0 ] && [ "$2" = "$(printf "docker start %s\n" faunosteo_trial_db faunosteo_trial_mail faunosteo_trial_auth faunosteo_trial_storage faunosteo_trial_rest faunosteo_trial_gateway)" ]' _ "$RC" "$(changes)"
|
|
rm -f "$CASE/stub/containers/faunosteo_trial_rest" "$CASE/stub/ports/faunosteo_trial_rest"
|
|
fresh_log; trial start
|
|
check "start: a missing container is recreated, then the running gateway restarted" bash -c '[ "$1" -eq 0 ] && [ "$(printf "%s\n" "$2" | grep -c .)" -eq 2 ] && printf "%s\n" "$2" | head -n 1 | grep -q "^docker run -d --name faunosteo_trial_rest " && printf "%s\n" "$2" | tail -n 1 | grep -qx "docker restart -t 10 faunosteo_trial_gateway"' _ "$RC" "$(changes)"
|
|
check "start: the recreation leaves no secret in argv" secrets_absent "$STATE_DIR/secrets.env"
|
|
fresh_log; trial status
|
|
check "status: read-only, keys' expiry, no secret" bash -c '[ "$1" -eq 0 ] && [ -z "$2" ] && grep -qF "keys valid until" "$3"' _ "$RC" "$(changes)" "$CASE/out"
|
|
check "status: no secret in its output" secrets_absent "$STATE_DIR/secrets.env"
|
|
|
|
echo "-- half-written state"
|
|
cp -p "$STATE_DIR/secrets.env" "$CASE/secrets.good"
|
|
printf 'TR_PW=short\n' > "$STATE_DIR/secrets.env"
|
|
for action in start stop status; do
|
|
fresh_log; trial "$action"
|
|
check "malformed secrets: $action refuses, nothing changed" refused "malformed"
|
|
done
|
|
cp -p "$CASE/secrets.good" "$STATE_DIR/secrets.env"
|
|
chmod 644 "$STATE_DIR/secrets.env"; fresh_log; trial status
|
|
check "secrets readable by others: refused" refused "mode 600"
|
|
chmod 600 "$STATE_DIR/secrets.env"
|
|
|
|
echo "-- backup"
|
|
new_case backups; trial create
|
|
check "backups: create" [ "$RC" -eq 0 ]
|
|
fresh_log; trial backup
|
|
BK="$(find "$STATE_DIR/backups" -mindepth 1 -maxdepth 1 -type d -name '*-manual' | head -n 1)"
|
|
check "backup: folder 700, files 600, checksums valid, both archives listed" bash -c '[ -n "$1" ] && [ "$(stat -c %a "$1")" = 700 ] && for f in db.tar storage.tar secrets.env stack.conf migrations.sha256 SHA256SUMS; do [ "$(stat -c %a "$1/$f")" = 600 ] || exit 1; done && cd "$1" && sha256sum --quiet -c SHA256SUMS && grep -q " db.tar$" SHA256SUMS && grep -q " storage.tar$" SHA256SUMS && [ ! -e SHA256SUMS.new ]' _ "$BK"
|
|
check "backup: both volumes measured by the helper, read-only, no network" bash -c 'grep -qF "docker run --rm --name faunosteo_trial_helper --network none -v faunosteo_trial_db:/volume:ro --entrypoint sh public.ecr.aws/supabase/postgres:17.11.0.004 -c du -sk /volume" "$1" && grep -qF "docker run --rm --name faunosteo_trial_helper --network none -v faunosteo_trial_storage:/volume:ro --entrypoint sh public.ecr.aws/supabase/postgres:17.11.0.004 -c du -sk /volume" "$1"' _ "$CASE/log"
|
|
check "backup: both volumes archived read-only by the helper, no network" bash -c 'grep -qF "docker run --rm --name faunosteo_trial_helper --network none -v faunosteo_trial_db:/volume:ro --entrypoint tar" "$1" && grep -qF "docker run --rm --name faunosteo_trial_helper --network none -v faunosteo_trial_storage:/volume:ro --entrypoint tar" "$1"' _ "$CASE/log"
|
|
check "backup: the stack stops before the copy and restarts after" bash -c 'stop=$(grep -n "^docker stop" "$1" | tail -n 1 | cut -d: -f1); helper=$(grep -n "^docker run --rm --name faunosteo_trial_helper" "$1" | head -n 1 | cut -d: -f1); start=$(grep -n "^docker start" "$1" | head -n 1 | cut -d: -f1); [ -n "$stop" ] && [ -n "$helper" ] && [ -n "$start" ] && [ "$stop" -lt "$helper" ] && [ "$helper" -lt "$start" ]' _ "$CASE/log"
|
|
check "backup: no volume removal" no_volume_removal
|
|
check "backup: no secret in calls or output" secrets_absent "$STATE_DIR/secrets.env"
|
|
COUNT="$(backup_count)"; : > "$CASE/stub/fail/archive"; fresh_log; trial backup
|
|
check "a failed archive: no folder kept, the stack left stopped, the way out named" bash -c '[ "$1" -ne 0 ] && [ "$2" -eq "$3" ] && grep -qF "backup failed" "$4" && grep -qF "pnpm db:trial start" "$4"' _ "$RC" "$COUNT" "$(backup_count)" "$CASE/out"
|
|
rm -f "$CASE/stub/fail/archive"; fresh_log; trial start
|
|
check "after a failed backup, start brings the stack back" [ "$RC" -eq 0 ]
|
|
COUNT="$(backup_count)"; : > "$CASE/stub/short-archive"; fresh_log; trial backup
|
|
check "an archive that lists fewer entries than its volume (exit 0): refused, no folder kept" bash -c '[ "$1" -ne 0 ] && [ "$2" -eq "$3" ] && grep -qF "unreadable or incomplete" "$4"' _ "$RC" "$COUNT" "$(backup_count)" "$CASE/out"
|
|
rm -f "$CASE/stub/short-archive"; fresh_log; trial start
|
|
mkdir -m 700 "$STATE_DIR/backups/20000101T000000Z-partial"
|
|
fresh_log; trial status
|
|
check "status marks a folder without SHA256SUMS incomplete" bash -c 'grep -F "20000101T000000Z-partial" "$1" | grep -qF incomplete' _ "$CASE/out"
|
|
fresh_log; trial_tty x restore 20000101T000000Z-partial
|
|
check "restore refuses an incomplete backup before any change" refused "is incomplete"
|
|
rmdir "$STATE_DIR/backups/20000101T000000Z-partial"
|
|
|
|
echo "-- migrate"
|
|
cp -p "$CASE/stub/ports/faunosteo_trial_db" "$CASE/db.port"
|
|
echo '5432/tcp -> 0.0.0.0:58432' > "$CASE/stub/ports/faunosteo_trial_db"
|
|
fresh_log; trial migrate
|
|
check "migrate: Postgres published beyond 127.0.0.1 is refused before any backup" bash -c '[ "$1" -ne 0 ] && grep -qF "faunosteo_trial_db is not published on 127.0.0.1:58432 only" "$2" && ! grep -qF faunosteo_trial_helper "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
cp -p "$CASE/db.port" "$CASE/stub/ports/faunosteo_trial_db"
|
|
fresh_log; trial migrate
|
|
check "migrate with nothing new: no backup, no change" bash -c '[ "$1" -eq 0 ] && grep -qF "no new migration" "$2" && ! grep -qF faunosteo_trial_helper "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
FIRST="$(find "$WORK/repo/supabase/migrations" -name '*.sql' | sort | head -n 1)"
|
|
cp -p "$FIRST" "$CASE/first.sql"; printf -- '-- edited\n' >> "$FIRST"
|
|
fresh_log; trial migrate
|
|
check "an applied migration edited in place: refused before any backup" refused "was edited after it was applied"
|
|
cp -p "$CASE/first.sql" "$FIRST"
|
|
printf -- '-- harness\n' > "$WORK/repo/supabase/migrations/20000101000000_harness_old.sql"
|
|
fresh_log; trial migrate
|
|
check "a new migration older than the last applied: refused before any backup" refused "older than the last applied migration"
|
|
rm -f "$WORK/repo/supabase/migrations/20000101000000_harness_old.sql"
|
|
printf -- '-- harness\n' > "$WORK/repo/supabase/migrations/29991231000000_harness_new.sql"
|
|
fresh_log; trial migrate
|
|
check "migrate: succeeds" [ "$RC" -eq 0 ]
|
|
check "migrate: the backup precedes the migration" before 'faunosteo_trial_helper' 'supabase --workdir . migration up'
|
|
check "migrate: the new file joins migrations.sha256" grep -q '^29991231000000 ' "$STATE_DIR/migrations.sha256"
|
|
check "migrate: PostgREST schema reloaded" log_has "notify pgrst, 'reload schema'"
|
|
printf -- '-- harness\n' > "$WORK/repo/supabase/migrations/29991231000001_harness_newer.sql"
|
|
: > "$CASE/stub/fail/migrate"; fresh_log; trial migrate
|
|
check "a migrate that stops part-way names its pre-migrate backup" bash -c '[ "$1" -ne 0 ] && grep -qE "restore [0-9]{8}T[0-9]{6}Z-pre-migrate" "$2"' _ "$RC" "$CASE/out"
|
|
fresh_log; trial status
|
|
check "after it, status names the remedy" out_has "pre-migrate backup"
|
|
rm -f "$CASE/stub/fail/migrate" "$WORK/repo/supabase/migrations/29991231000001_harness_newer.sql"
|
|
( cd "$WORK/repo" && for f in supabase/migrations/*.sql; do basename "$f" | cut -d_ -f1; done ) > "$CASE/stub/answers/applied"
|
|
rm -f "$WORK/repo/supabase/migrations/29991231000000_harness_new.sql"
|
|
|
|
echo "-- rotate-keys"
|
|
if hold_port 5194; then fresh_log; trial rotate-keys; check "rotate-keys while port 5194 is in use (the app): refused, nothing changed" refused "5194 is in use"; release_port
|
|
else fail "could not hold 127.0.0.1:5194 for the app case"; fi
|
|
cp -p "$STATE_DIR/secrets.env" "$CASE/secrets.before-keys"
|
|
fresh_log; trial rotate-keys
|
|
check "rotate-keys: password and JWT secret kept, keys renewed" bash -c '[ "$1" -eq 0 ] && [ "$(grep -E "^TR_(PW|JWT_SECRET)=" "$2")" = "$(grep -E "^TR_(PW|JWT_SECRET)=" "$3")" ] && [ "$(grep "^TR_ANON_KEY=" "$2")" != "$(grep "^TR_ANON_KEY=" "$3")" ] && [ "$(stat -c %a "$2")" = 600 ]' _ "$RC" "$STATE_DIR/secrets.env" "$CASE/secrets.before-keys"
|
|
check "rotate-keys: a backup first, then storage recreated and the gateway restarted, nothing else" bash -c 'last=$(printf "%s\n" "$1" | tail -n 4); printf "%s\n" "$last" | head -n 1 | grep -qx "docker stop -t 30 faunosteo_trial_storage" && printf "%s\n" "$last" | grep -qx "docker rm faunosteo_trial_storage" && printf "%s\n" "$last" | grep -q "^docker run -d --name faunosteo_trial_storage " && printf "%s\n" "$last" | tail -n 1 | grep -qx "docker restart -t 10 faunosteo_trial_gateway" && printf "%s\n" "$1" | head -n 1 | grep -q "^docker stop -t 60 "' _ "$(changes)"
|
|
check "rotate-keys: its backup is restorable and protected (700, 600, checksums)" bash -c 'd=$(ls -d "$1"/*-pre-keys* | head -n 1); [ -n "$d" ] && [ "$(stat -c %a "$d")" = 700 ] && for f in db.tar storage.tar secrets.env stack.conf migrations.sha256 SHA256SUMS; do [ "$(stat -c %a "$d/$f")" = 600 ] || exit 1; done && cd "$d" && sha256sum --quiet -c SHA256SUMS && cmp -s secrets.env "$2"' _ "$STATE_DIR/backups" "$CASE/secrets.before-keys"
|
|
check "rotate-keys: no secret in calls or output" secrets_absent "$STATE_DIR/secrets.env"
|
|
|
|
echo "-- rotate-secrets"
|
|
cp -p "$STATE_DIR/secrets.env" "$CASE/secrets.before-refusal"
|
|
: > "$CASE/stub/fail/rotate"; fresh_log; trial rotate-secrets
|
|
check "rotation refused by the database: secrets unchanged, no container removed" bash -c '[ "$1" -ne 0 ] && cmp -s "$2" "$3" && ! grep -q "^docker rm " "$4" && [ ! -e "$5" ] && grep -qF "nothing was changed" "$6"' _ "$RC" "$STATE_DIR/secrets.env" "$CASE/secrets.before-refusal" "$CASE/log" "$STATE_DIR/secrets.next.env" "$CASE/out"
|
|
: > "$CASE/stub/fail/rotation-marker"; fresh_log; trial rotate-secrets
|
|
check "rotation failed and the database does not answer: both files kept, the backup named" bash -c '[ "$1" -ne 0 ] && cmp -s "$2" "$3" && [ -f "$4" ] && grep -qF "secrets.next.env (new) are both kept" "$5" && grep -qE "restore [0-9]{8}T[0-9]{6}Z-pre-rotate" "$5"' _ "$RC" "$STATE_DIR/secrets.env" "$CASE/secrets.before-refusal" "$STATE_DIR/secrets.next.env" "$CASE/out"
|
|
rm -f "$CASE/stub/fail/rotate" "$CASE/stub/fail/rotation-marker" "$STATE_DIR/secrets.next.env"
|
|
cp -p "$STATE_DIR/secrets.env" "$CASE/secrets.before-lost"
|
|
: > "$CASE/stub/commit-then-fail"; fresh_log; trial rotate-secrets
|
|
check "psql lost after the commit: the database's answer decides, the rotation completes" bash -c '[ "$1" -eq 0 ] && ! cmp -s "$2" "$3" && grep -qF "took the new secrets although psql failed" "$4" && grep -qx "docker rm faunosteo_trial_db" "$5" && [ ! -e "$6" ]' _ "$RC" "$STATE_DIR/secrets.env" "$CASE/secrets.before-lost" "$CASE/out" "$CASE/log" "$STATE_DIR/secrets.next.env"
|
|
rm -f "$CASE/stub/commit-then-fail" "$CASE/stub/answers/rotation-marker"
|
|
cp -p "$STATE_DIR/secrets.env" "$CASE/secrets.before-rotation"
|
|
fresh_log; trial rotate-secrets
|
|
check "rotate-secrets: succeeds" [ "$RC" -eq 0 ]
|
|
check "rotate-secrets: the final message does not claim sessions end" bash -c 'grep -qF "access tokens signed with the old secret are refused; refresh tokens and sessions stay valid" "$1" && grep -qF "account passwords and TOTP factors unchanged" "$1" && ! grep -qF "sign in again" "$1"' _ "$CASE/out"
|
|
check "rotate-secrets: every value renewed" bash -c 'for k in TR_PW TR_JWT_SECRET TR_ANON_KEY TR_SERVICE_KEY; do [ "$(grep "^$k=" "$1")" != "$(grep "^$k=" "$2")" ] || exit 1; done' _ "$STATE_DIR/secrets.env" "$CASE/secrets.before-rotation"
|
|
check "rotate-secrets: a restorable, protected backup holding the previous secrets (no secrets.prev needed)" bash -c 'd=$(ls -d "$1"/*-pre-rotate* | tail -n 1); [ -n "$d" ] && [ "$(stat -c %a "$d")" = 700 ] && for f in db.tar storage.tar secrets.env stack.conf migrations.sha256 SHA256SUMS; do [ "$(stat -c %a "$d/$f")" = 600 ] || exit 1; done && cd "$d" && sha256sum --quiet -c SHA256SUMS && cmp -s secrets.env "$2"' _ "$STATE_DIR/backups" "$CASE/secrets.before-rotation"
|
|
check "rotate-secrets: values reach psql by environment names only" log_has 'docker exec -i -e PGPASSWORD -e PGAPPNAME -e NEW_PW -e NEW_JWT -e ROT_DIGEST faunosteo_trial_db psql -X -q -h 127.0.0.1 -U supabase_admin'
|
|
check "rotate-secrets: no rotation SQL text holds a secret, old or new" bash -c 'files=$(grep -lF -- "-- db-trial:rotate" /dev/null $(find "$1" -type f)); [ -n "$files" ] && for f in $files; do grep -qF "set local log_min_error_statement = panic;" "$f" && grep -qF "app.trial_rotation" "$f" || exit 1; for s in "${@:2}"; do while IFS="=" read -r _ v; do [ -z "$v" ] || ! grep -qF -- "$v" "$f" || exit 1; done < "$s"; done; done' _ "$CASE/stub/stdin" "$STATE_DIR/secrets.env" "$CASE/secrets.before-rotation" "$CASE/secrets.before-lost" "$CASE/secrets.before-refusal"
|
|
check "rotate-secrets: six containers recreated, volumes kept" bash -c 'for n in db mail auth storage rest gateway; do grep -qx "docker rm faunosteo_trial_$n" "$1" && grep -q "^docker run -d --name faunosteo_trial_$n " "$1" || exit 1; done; ! grep -qF "docker volume rm" "$1"' _ "$CASE/log"
|
|
check "rotate-secrets: no leftover secrets.next.env, no secrets.prev.env" bash -c '[ ! -e "$1/secrets.prev.env" ] && [ ! -e "$1/secrets.next.env" ]' _ "$STATE_DIR"
|
|
check "rotate-secrets: new secrets absent from calls and output" secrets_absent "$STATE_DIR/secrets.env"
|
|
check "rotate-secrets: old secrets absent from calls and output" secrets_absent "$CASE/secrets.before-rotation"
|
|
|
|
echo "-- rotations refuse keys that are not this stack's"
|
|
cp -p "$STATE_DIR/secrets.env" "$CASE/secrets.unforged"
|
|
forge TR_SERVICE_KEY faunosteo-trial other service_role
|
|
cp -p "$STATE_DIR/secrets.env" "$CASE/secrets.forged"
|
|
for action in rotate-keys rotate-secrets; do
|
|
COUNT="$(backup_count)"; fresh_log; trial "$action"
|
|
check "$action: keys that are not this stack's are refused before any stop, no backup taken" bash -c '[ "$1" -ne 0 ] && grep -qF "service_role key in secrets.env is not this stack" "$2" && grep -qF "pnpm db:trial restore <backup>" "$2" && cmp -s "$3" "$4" && [ -z "$5" ] && [ "$6" -eq "$7" ] && [ ! -e "$8" ]' _ "$RC" "$CASE/out" "$STATE_DIR/secrets.env" "$CASE/secrets.forged" "$(changes)" "$COUNT" "$(backup_count)" "$STATE_DIR/secrets.next.env"
|
|
done
|
|
cp -p "$CASE/secrets.unforged" "$STATE_DIR/secrets.env"
|
|
|
|
echo "-- restore"
|
|
NAME="$(basename "$BK")"
|
|
fresh_log; trial restore ../etc
|
|
check "restore: a name that is not a backup folder is refused, before any Docker call" refused_no_docker "restore <backup>"
|
|
cp -rp "$BK" "$STATE_DIR/backups/20000101T000000Z-tampered"; printf 'x' >> "$STATE_DIR/backups/20000101T000000Z-tampered/db.tar"
|
|
fresh_log; trial_tty 'restore 20000101T000000Z-tampered' restore 20000101T000000Z-tampered
|
|
check "restore: a tampered backup is refused before any change" refused "fails its checksums"
|
|
FORGED=20000101T000000Z-forged-key
|
|
cp -rp "$BK" "$STATE_DIR/backups/$FORGED"
|
|
forge TR_SERVICE_KEY faunosteo-trial other service_role 3600 "$STATE_DIR/backups/$FORGED/secrets.env"
|
|
( cd "$STATE_DIR/backups/$FORGED" && sha256sum -- db.tar storage.tar secrets.env stack.conf migrations.sha256 > SHA256SUMS )
|
|
fresh_log; trial_tty "restore $FORGED" restore "$FORGED"
|
|
check "restore: a backup whose key is not signed with its own secret is refused before any change" refused "holds keys that are not signed with its own secret"
|
|
: > "$CASE/stub/fail/image"; fresh_log; trial_tty "restore $NAME" restore "$NAME"
|
|
check "restore: the recorded database image is absent: refused before any change" refused "is not present locally"
|
|
rm -f "$CASE/stub/fail/image"
|
|
fresh_log; trial_tty nope restore "$NAME"
|
|
check "restore: a wrong phrase changes nothing" refused "not confirmed"
|
|
fresh_log; trial_input restore "$NAME" <<<"restore $NAME"
|
|
check "restore: the phrase piped without a terminal is refused before any call (B2, moved by fix 10)" refused_early "needs a terminal"
|
|
fresh_log; trial_tty "restore $NAME" restore "$NAME"
|
|
check "restore: succeeds" [ "$RC" -eq 0 ]
|
|
check "restore: says the backup brings back older secrets" out_has "holds other secrets than the current ones"
|
|
check "restore: a backup of the current state first" before 'faunosteo_trial_db:/volume:ro --entrypoint tar' 'docker volume rm faunosteo_trial_db'
|
|
check "restore: volumes replaced then filled by the helper" before 'docker volume create --label faunosteo.stack=trial faunosteo_trial_db' 'docker run --rm -i --name faunosteo_trial_helper --network none -v faunosteo_trial_db:/volume --entrypoint tar'
|
|
check "restore: each fresh volume is checked empty by the helper before the extraction" before 'ls -A /volume' 'docker run --rm -i --name faunosteo_trial_helper'
|
|
check "restore: the backup's secrets are back" cmp -s "$STATE_DIR/secrets.env" "$BK/secrets.env"
|
|
check "restore: six containers recreated" bash -c 'for n in db mail auth storage rest gateway; do grep -q "^docker run -d --name faunosteo_trial_$n " "$1" || exit 1; done' _ "$CASE/log"
|
|
check "restore: only trial names" only_trial_names
|
|
|
|
echo "-- destroy"
|
|
fresh_log; trial_tty '' destroy
|
|
check "destroy with an empty answer: nothing changed" refused "not confirmed"
|
|
fresh_log; trial_input destroy <<<"faunosteo_trial"
|
|
check "destroy with the phrase piped without a terminal: refused before any call (B2, moved by fix 10)" refused_early "needs a terminal"
|
|
fresh_log; trial_tty faunosteo_trial destroy
|
|
check "destroy: succeeds" [ "$RC" -eq 0 ]
|
|
check "destroy: a backup before any removal" before 'faunosteo_trial_db:/volume:ro --entrypoint tar' 'docker rm faunosteo_trial_db'
|
|
check "destroy: every removal names a trial resource" bash -c 'grep -E "^docker (rm|volume rm|network rm) " "$1" | grep -qvE " faunosteo_trial_(db|mail|auth|storage|rest|gateway|net)$" && exit 1; grep -qx "docker volume rm faunosteo_trial_db" "$1" && grep -qx "docker volume rm faunosteo_trial_storage" "$1" && grep -qx "docker network rm faunosteo_trial_net" "$1"' _ "$CASE/log"
|
|
check "destroy: live state removed, marker and backups kept" bash -c 'for f in secrets.env secrets.next.env db.env auth.env storage.env rest.env stack.conf migrations.sha256; do [ ! -e "$1/$f" ] || exit 1; done; [ -e "$1/.faunosteo-trial-state" ] && ls -d "$1"/backups/*-pre-destroy* >/dev/null 2>&1 && [ -d "$2" ]' _ "$STATE_DIR" "$BK"
|
|
fresh_log; trial_tty "restore $NAME" restore "$NAME"
|
|
check "restore after destroy rebuilds the stack from the backup" bash -c '[ "$1" -eq 0 ] && grep -qF "no trial volume" "$2" && grep -qx "docker network create --label faunosteo.stack=trial faunosteo_trial_net" "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
|
|
echo "-- destroy with nothing left in Docker"
|
|
new_case leftover; trial create
|
|
rm -f "$CASE/stub/containers/"* "$CASE/stub/ports/"* "$CASE/stub/volumes/"* "$CASE/stub/networks/"*
|
|
fresh_log; trial_tty faunosteo_trial destroy
|
|
check "destroy with no resource: after the phrase, the live files go, backups and marker kept, no Docker removal" bash -c '[ "$1" -eq 0 ] && [ ! -e "$2/secrets.env" ] && [ ! -e "$2/db.env" ] && [ -d "$2/backups" ] && [ -e "$2/.faunosteo-trial-state" ] && ! grep -qE "^docker (rm|volume rm|network rm) " "$3"' _ "$RC" "$STATE_DIR" "$CASE/log"
|
|
|
|
echo "-- B2 review fixes"
|
|
# A created stack with one manual backup: RB is its folder, RN its name.
|
|
b2_stack() { # case name
|
|
new_case "$1"; trial create; trial backup
|
|
RB="$(find "$STATE_DIR/backups" -mindepth 1 -maxdepth 1 -type d -name '*-manual' | head -n 1)"
|
|
RN="$(basename "$RB")"
|
|
}
|
|
restore_refused() { # backup name, message: refused at the check, nothing removed
|
|
fresh_log; trial_tty "restore $1" restore "$1"
|
|
refused "$2" && no_volume_removal
|
|
}
|
|
stopped_part_way() { [ "$RC" -ne 0 ] && out_has "restore stopped part-way" && out_has "$1"; }
|
|
polls() { grep -c 'db-trial:rotation-active' "$CASE/log" || true; }
|
|
rotation_sql() { stdin_files | xargs -r grep -lx -- '-- db-trial:rotate' | head -n 1; }
|
|
sql_is_one_explicit_transaction() { # file: begin before every alter, commit last
|
|
local first_alter begin
|
|
begin="$(grep -n '^begin;$' "$1" | head -n 1 | cut -d: -f1)"
|
|
first_alter="$(grep -n '^alter ' "$1" | head -n 1 | cut -d: -f1)"
|
|
[ -n "$begin" ] && [ -n "$first_alter" ] && [ "$begin" -lt "$first_alter" ] && [ "$(grep -c '^begin;$' "$1")" -eq 1 ] \
|
|
&& [ "$(tail -n 1 "$1")" = 'commit;' ]
|
|
}
|
|
no_single_transaction_rotation() { ! docker_calls | grep -F 'supabase_admin' | grep -qF -- --single-transaction; }
|
|
|
|
# -- the backup is proven before anything is removed
|
|
b2_stack b2-proof
|
|
OLD=20000101T000000Z
|
|
cp -rp "$RB" "$STATE_DIR/backups/$OLD-nolist"
|
|
( cd "$STATE_DIR/backups/$OLD-nolist" && grep -v ' secrets.env$' SHA256SUMS > S.new && cat S.new > SHA256SUMS && rm S.new )
|
|
check "restore: a SHA256SUMS missing a required entry is refused, nothing changed" restore_refused "$OLD-nolist" "does not list exactly"
|
|
cp -rp "$RB" "$STATE_DIR/backups/$OLD-extra"; printf 'x' > "$STATE_DIR/backups/$OLD-extra/extra.txt"
|
|
check "restore: a file the SHA256SUMS does not list is refused, nothing changed" restore_refused "$OLD-extra" "does not list exactly"
|
|
ln -s "$RB" "$STATE_DIR/backups/$OLD-linked"
|
|
check "restore: a backup folder that is a symbolic link is refused, nothing changed" restore_refused "$OLD-linked" "symbolic link"
|
|
cp -rp "$RB" "$STATE_DIR/backups/$OLD-filelink"
|
|
mv "$STATE_DIR/backups/$OLD-filelink/storage.tar" "$CASE/storage.real"; ln -s "$CASE/storage.real" "$STATE_DIR/backups/$OLD-filelink/storage.tar"
|
|
check "restore: a symbolic link inside a backup (checksums still valid) is refused, nothing changed" restore_refused "$OLD-filelink" "symbolic link"
|
|
mv "$STATE_DIR/backups" "$CASE/backups.real"; ln -s "$CASE/backups.real" "$STATE_DIR/backups"
|
|
check "restore: a backups/ that is a symbolic link is refused, nothing changed" restore_refused "$RN" "symbolic link"
|
|
fresh_log; trial backup
|
|
check "backup: a backups/ that is a symbolic link is refused before any stop" refused "symbolic link"
|
|
rm -- "$STATE_DIR/backups"; mv "$CASE/backups.real" "$STATE_DIR/backups"
|
|
|
|
# -- the folder is checked again right before the extraction
|
|
b2_stack b2-toctou
|
|
printf '%s' "$RB/db.tar" > "$CASE/stub/append-on-rm"
|
|
fresh_log; trial_tty "restore $RN" restore "$RN"
|
|
check "restore: a backup changed after the first check is refused before any volume removal" bash -c '[ "$1" -ne 0 ] && grep -qF "fails its checksums" "$2" && ! grep -qF "docker volume rm" "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
check "restore: that refusal names the pre-restore backup and the rerun" bash -c 'grep -qE "restore [0-9]{8}T[0-9]{6}Z-pre-restore" "$1" && grep -qF "pnpm db:trial restore $2" "$1"' _ "$CASE/out" "$RN"
|
|
|
|
# -- check_backup after each backup of a command that goes on to change something
|
|
b2_stack b2-after
|
|
cp -p "$STATE_DIR/secrets.env" "$CASE/secrets.kept"
|
|
printf -- '-- harness\n' > "$WORK/repo/supabase/migrations/29991231000002_harness_b2.sql"
|
|
: > "$CASE/stub/fail/image-nondb"
|
|
stops_after_backup() {
|
|
[ "$RC" -ne 0 ] && out_has "is not present locally" && ! out_has "nothing was changed" && ! log_has 'docker rm ' \
|
|
&& ! log_has 'migration up' && cmp -s "$STATE_DIR/secrets.env" "$CASE/secrets.kept"
|
|
}
|
|
for action in rotate-keys rotate-secrets migrate; do
|
|
fresh_log; trial "$action"
|
|
check "$action: a backup whose recorded image is absent stops the command before any change" stops_after_backup
|
|
done
|
|
rm -f "$WORK/repo/supabase/migrations/29991231000002_harness_b2.sql"
|
|
fresh_log; trial_tty faunosteo_trial destroy
|
|
check "destroy: a backup that fails its check stops before any removal, the stack stays stopped, the backup is named" bash -c '[ "$1" -ne 0 ] && grep -qF "is not present locally" "$2" && grep -qF "stack stays stopped (pnpm db:trial start)" "$2" && grep -qE "pre-destroy" "$2" && ! grep -qE "^docker (rm|volume rm|network rm) " "$3" && [ -f "$4/secrets.env" ]' _ "$RC" "$CASE/out" "$CASE/log" "$STATE_DIR"
|
|
|
|
# -- a restore that stops part-way says where the way back is
|
|
b2_stack b2-extract
|
|
: > "$CASE/stub/fail/extract"
|
|
fresh_log; trial_tty "restore $RN" restore "$RN"
|
|
check "restore whose extraction fails: names the pre-restore backup and the rerun" bash -c '[ "$1" -ne 0 ] && grep -qF "restore stopped part-way" "$2" && grep -qE "pnpm db:trial restore [0-9]{8}T[0-9]{6}Z-pre-restore" "$2" && grep -qF "pnpm db:trial restore $3" "$2"' _ "$RC" "$CASE/out" "$RN"
|
|
rm -f "$CASE/stub/volumes/"* "$CASE/stub/containers/"* "$CASE/stub/ports/"*
|
|
fresh_log; trial_tty "restore $RN" restore "$RN"
|
|
check "restore with no trial volume that stops part-way says no backup was taken" stopped_part_way "No backup of the state before it"
|
|
|
|
# -- restore: a restored state file is written 600, whatever the backup's mode; the note on a pre-restore backup
|
|
b2_stack b2-mode
|
|
cp -rp "$RB" "$STATE_DIR/backups/$OLD-mode644"
|
|
chmod 644 "$STATE_DIR/backups/$OLD-mode644/secrets.env" "$STATE_DIR/backups/$OLD-mode644/stack.conf" "$STATE_DIR/backups/$OLD-mode644/migrations.sha256"
|
|
fresh_log; trial_tty "restore $OLD-mode644" restore "$OLD-mode644"
|
|
check "restore from a backup holding 644 files: the restored state files are 600" bash -c '[ "$1" -eq 0 ] && for f in secrets.env stack.conf migrations.sha256; do [ "$(stat -c %a "$2/$f")" = 600 ] || exit 1; done' _ "$RC" "$STATE_DIR"
|
|
forge TR_SERVICE_KEY faunosteo-trial other service_role
|
|
fresh_log; trial_tty "restore $RN" restore "$RN"
|
|
check "restore: a pre-restore backup that restore itself would refuse is kept and noted, the restore goes on" bash -c '[ "$1" -eq 0 ] && grep -qF "restore will refuse it as it is" "$2" && grep -qF "not signed with its own secret" "$2"' _ "$RC" "$CASE/out"
|
|
|
|
# -- the app is running: nothing changes
|
|
b2_stack b2-app
|
|
if hold_port 5194; then
|
|
fresh_log; trial_tty "restore $RN" restore "$RN"; check "restore while port 5194 is in use: refused, nothing changed" refused "5194 is in use"
|
|
fresh_log; trial_tty faunosteo_trial destroy; check "destroy while port 5194 is in use: refused, nothing changed" refused "5194 is in use"
|
|
fresh_log; trial rotate-secrets; check "rotate-secrets while port 5194 is in use: refused, nothing changed" refused "5194 is in use"
|
|
release_port
|
|
else fail "could not hold 127.0.0.1:5194 for the app cases"; fi
|
|
|
|
# -- restore: a trial port taken by another process, found before any volume removal
|
|
b2_stack b2-ports
|
|
if hold_port 58432; then
|
|
fresh_log; trial_tty "restore $RN" restore "$RN"
|
|
check "restore with a trial port taken: refused before any removal, no half-filled message" bash -c '[ "$1" -ne 0 ] && grep -qF "127.0.0.1:58432 is taken" "$2" && ! grep -qE "^docker (rm|volume rm) " "$3" && ! grep -qF "half-filled" "$2"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
release_port
|
|
else fail "could not hold 127.0.0.1:58432 for the port case"; fi
|
|
|
|
# -- backup: free space, a helper left over, an interruption
|
|
new_case b2-backup; trial create
|
|
echo 999999999999 > "$CASE/stub/answers/measure-kib"; COUNT="$(backup_count)"; fresh_log; trial backup
|
|
check "backup: not enough free space is refused, no folder kept, the stack stays stopped" bash -c '[ "$1" -ne 0 ] && grep -qF "less free space" "$2" && grep -qF "the stack stays stopped" "$2" && grep -q "^docker stop" "$3" && [ "$4" -eq "$5" ]' _ "$RC" "$CASE/out" "$CASE/log" "$COUNT" "$(backup_count)"
|
|
rm -f "$CASE/stub/answers/measure-kib"; trial start
|
|
: > "$CASE/stub/containers/faunosteo_trial_helper"; COUNT="$(backup_count)"; fresh_log; trial backup
|
|
check "backup: a leftover helper container is refused before any stop, the hint named, no folder" bash -c '[ "$1" -ne 0 ] && grep -qF "docker rm faunosteo_trial_helper" "$2" && ! grep -q "^docker stop" "$3" && [ "$4" -eq "$5" ]' _ "$RC" "$CASE/out" "$CASE/log" "$COUNT" "$(backup_count)"
|
|
rm -f "$CASE/stub/containers/faunosteo_trial_helper"
|
|
: > "$CASE/stub/fail/archive"; fresh_log; trial backup
|
|
check "backup: a failed archive prints one message (backup failed), not the interruption one" bash -c 'grep -qF "backup failed" "$1" && ! grep -qF "is incomplete" "$1"' _ "$CASE/out"
|
|
rm -f "$CASE/stub/fail/archive"; trial start
|
|
: > "$CASE/stub/term-in-archive"; COUNT="$(backup_count)"; fresh_log; trial backup
|
|
check "backup interrupted by SIGTERM: one message, the folder named incomplete, the stack stays stopped" bash -c '[ "$1" -ne 0 ] && [ "$(grep -c "is incomplete" "$2")" -eq 1 ] && grep -qF "the stack may be stopped (pnpm db:trial start)" "$2" && [ "$3" -eq $(( $4 + 1 )) ]' _ "$RC" "$CASE/out" "$(backup_count)" "$COUNT"
|
|
rm -f "$CASE/stub/term-in-archive"; fresh_log; trial status
|
|
check "status lists the interrupted backup as incomplete" bash -c 'grep -F "backups in" -A9 "$1" | grep -qF incomplete' _ "$CASE/out"
|
|
|
|
# -- the lock comes before the state checks
|
|
new_case b2-lock; trial create
|
|
rm -f "$CASE/stub/volumes/faunosteo_trial_db"
|
|
flock "$STATE_DIR/.lock" sleep 6 & LOCK_HOLDER=$!
|
|
sleep 0.5
|
|
for action in backup migrate rotate-keys rotate-secrets start stop; do
|
|
fresh_log; trial "$action"
|
|
check "$action: the lock is taken before the stack is checked" bash -c '[ "$1" -ne 0 ] && grep -qF "another pnpm db:trial command is running" "$2"' _ "$RC" "$CASE/out"
|
|
done
|
|
wait "$LOCK_HOLDER"
|
|
|
|
# -- a rotation that stopped part-way leaves secrets.next.env: never overwritten
|
|
b2_stack b2-next
|
|
printf 'SENTINEL-NEXT\n' > "$STATE_DIR/secrets.next.env"; chmod 600 "$STATE_DIR/secrets.next.env"
|
|
fresh_log; trial status
|
|
check "status mentions a leftover secrets.next.env, never its content" bash -c 'grep -qF "secrets.next.env exists" "$1" && ! grep -qF SENTINEL-NEXT "$1"' _ "$CASE/out"
|
|
cp -p "$STATE_DIR/secrets.env" "$CASE/secrets.unforged"
|
|
forge TR_SERVICE_KEY faunosteo-trial other service_role
|
|
COUNT="$(backup_count)"; fresh_log; trial rotate-secrets
|
|
check "rotate-secrets with a leftover secrets.next.env: refused before the key check and any backup, the file untouched" bash -c '[ "$1" -ne 0 ] && grep -qF "secrets.next.env exists" "$2" && ! grep -qF "is not this stack" "$2" && grep -qF "pnpm db:trial restore <pre-rotate backup>" "$2" && [ "$3" -eq "$4" ] && ! grep -q "^docker stop" "$5" && [ "$(cat "$6")" = SENTINEL-NEXT ]' _ "$RC" "$CASE/out" "$COUNT" "$(backup_count)" "$CASE/log" "$STATE_DIR/secrets.next.env"
|
|
cp -p "$CASE/secrets.unforged" "$STATE_DIR/secrets.env"
|
|
fresh_log; trial_tty "restore $RN" restore "$RN"
|
|
check "restore removes a leftover secrets.next.env once it succeeded" bash -c '[ "$1" -eq 0 ] && [ ! -e "$2/secrets.next.env" ]' _ "$RC" "$STATE_DIR"
|
|
printf 'SENTINEL-NEXT\n' > "$STATE_DIR/secrets.next.env"
|
|
fresh_log; trial_tty faunosteo_trial destroy
|
|
check "destroy removes a leftover secrets.next.env once it succeeded" bash -c '[ "$1" -eq 0 ] && [ ! -e "$2/secrets.next.env" ]' _ "$RC" "$STATE_DIR"
|
|
|
|
# -- destroy on a damaged database
|
|
new_case b2-inventory; trial create
|
|
: > "$CASE/stub/fail/inventory"; fresh_log; trial_tty faunosteo_trial destroy
|
|
check "destroy whose inventory query fails still reaches the confirmation and works" bash -c '[ "$1" -eq 0 ] && grep -qF "(content unreadable)" "$2" && grep -qx "docker volume rm faunosteo_trial_db" "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
|
|
# -- rotate-secrets: the transaction, the commit window, the rename
|
|
new_case b2-rotation; trial create
|
|
cp -p "$STATE_DIR/secrets.env" "$CASE/secrets.before"
|
|
CASE_PATH="$WORK/bin-mvfail:$BASE_PATH"; fresh_log; trial rotate-secrets
|
|
check "rotate-secrets: a rename that fails after the commit still says both files are kept" bash -c '[ "$1" -ne 0 ] && grep -qF "secrets.env (previous) and secrets.next.env (new) are both kept" "$2" && ! grep -qF "secrets.env holds them" "$2" && [ -f "$3/secrets.next.env" ] && cmp -s "$3/secrets.env" "$4"' _ "$RC" "$CASE/out" "$STATE_DIR" "$CASE/secrets.before"
|
|
CASE_PATH="$WORK/bin:$BASE_PATH"; rm -f "$STATE_DIR/secrets.next.env"
|
|
: > "$CASE/stub/fail/rotate"; echo 1 > "$CASE/stub/answers/rotation-active"; fresh_log; trial rotate-secrets
|
|
check "a rotation session still active after the limit: unknown, both files kept, nothing removed, the marker unread" bash -c '[ "$1" -ne 0 ] && grep -qF "whether the rotation committed is unknown" "$2" && grep -qF "secrets.env (previous) and secrets.next.env (new) are both kept" "$2" && grep -qE "restore [0-9]{8}T[0-9]{6}Z-pre-rotate" "$2" && [ -f "$3/secrets.next.env" ] && cmp -s "$3/secrets.env" "$4" && ! grep -q "^docker rm " "$5" && ! grep -qF "db-trial:rotation-marker" "$5" && [ "$6" -eq 10 ]' _ "$RC" "$CASE/out" "$STATE_DIR" "$CASE/secrets.before" "$CASE/log" "$(polls)"
|
|
rm -f "$STATE_DIR/secrets.next.env"; echo 0 > "$CASE/stub/answers/rotation-active"; : > "$CASE/stub/fail/rotation-active"; fresh_log; trial rotate-secrets
|
|
check "a failing session query: unknown, both files kept, the marker unread" bash -c '[ "$1" -ne 0 ] && grep -qF "whether the rotation committed is unknown" "$2" && [ -f "$3/secrets.next.env" ] && ! grep -qF "db-trial:rotation-marker" "$4"' _ "$RC" "$CASE/out" "$STATE_DIR" "$CASE/log"
|
|
rm -f "$STATE_DIR/secrets.next.env" "$CASE/stub/fail/rotation-active"; printf '1\n1\n0\n' > "$CASE/stub/answers/rotation-active.seq"; fresh_log; trial rotate-secrets
|
|
check "a rotation session active for two polls then gone, marker absent: not committed, the new file removed" bash -c '[ "$1" -ne 0 ] && grep -qF "did not take the new secrets" "$2" && [ ! -e "$3/secrets.next.env" ] && cmp -s "$3/secrets.env" "$4" && [ "$5" -eq 3 ]' _ "$RC" "$CASE/out" "$STATE_DIR" "$CASE/secrets.before" "$(polls)"
|
|
rm -f "$CASE/stub/fail/rotate"; : > "$CASE/stub/commit-then-fail"; printf '1\n0\n' > "$CASE/stub/answers/rotation-active.seq"; fresh_log; trial rotate-secrets
|
|
check "a rotation session active once then gone, marker equal: the rotation goes on" bash -c '[ "$1" -eq 0 ] && grep -qF "took the new secrets although psql failed" "$2" && [ "$3" -eq 2 ]' _ "$RC" "$CASE/out" "$(polls)"
|
|
rm -f "$CASE/stub/commit-then-fail" "$CASE/stub/answers/rotation-marker"; fresh_log; trial rotate-secrets
|
|
check "rotate-secrets: the SQL is one explicit transaction (begin before every alter, commit last)" sql_is_one_explicit_transaction "$(rotation_sql)"
|
|
check "rotate-secrets: the rotation SQL silences every logging channel, in order, before any alter" lines_before_first "$(cat "$(rotation_sql)")" '^alter ' '\set VERBOSITY terse' 'begin;' "set local log_statement = 'none';" 'set local log_min_duration_statement = -1;' 'set local log_min_error_statement = panic;' "set local pgaudit.log = 'none';" 'set local pg_stat_statements.track_utility = off;'
|
|
check "rotate-secrets: the rotation session is named (PGAPPNAME passed by name)" bash -c '[ "$1" -eq 0 ] && grep -qF -- "-e PGAPPNAME" "$2"' _ "$RC" "$CASE/log"
|
|
check "rotate-secrets: no --single-transaction on the rotation session" no_single_transaction_rotation
|
|
|
|
# -- destroy refuses without a restorable backup, and names the way out
|
|
no_removal() { ! grep -qE '^docker (rm|volume rm|network rm) ' "$CASE/log"; }
|
|
new_case h5-way-one-volume; trial create
|
|
rm -f "$CASE/stub/volumes/faunosteo_trial_storage"
|
|
fresh_log; trial_tty faunosteo_trial destroy
|
|
check "destroy with one volume missing: refused, nothing removed, the way out lists what exists" bash -c '[ "$1" -ne 0 ] && grep -qF "lacks storage.tar" "$2" && grep -qF "docker rm faunosteo_trial_db faunosteo_trial_mail" "$2" && grep -qF " docker network rm faunosteo_trial_net" "$2" && grep -qF " docker volume rm faunosteo_trial_db" "$2" && grep -qF "pnpm db:trial destroy" "$2" && grep -qF "pre-destroy" "$2"' _ "$RC" "$CASE/out"
|
|
check "destroy with one volume missing: no removal was run" no_removal
|
|
for n in db mail auth storage rest gateway; do rm -f "$CASE/stub/containers/faunosteo_trial_$n" "$CASE/stub/ports/faunosteo_trial_$n"; done
|
|
rm -f "$CASE/stub/networks/faunosteo_trial_net" "$CASE/stub/volumes/faunosteo_trial_db"
|
|
fresh_log; trial_tty faunosteo_trial destroy
|
|
check "destroy after the manual removal: the state files go, backups kept" bash -c '[ "$1" -eq 0 ] && [ ! -e "$2/secrets.env" ] && [ -d "$2/backups" ] && ls -d "$2"/backups/*-pre-destroy* >/dev/null 2>&1' _ "$RC" "$STATE_DIR"
|
|
new_case h5-way-space; trial create
|
|
echo 999999999999 > "$CASE/stub/answers/measure-kib"
|
|
fresh_log; trial_tty faunosteo_trial destroy
|
|
check "destroy whose backup cannot be made: one failure message, the way out, nothing removed" bash -c '[ "$1" -ne 0 ] && [ "$(grep -c "backup failed" "$2")" -eq 1 ] && grep -qF "no backup could be made" "$2" && grep -qF " docker volume rm faunosteo_trial_db faunosteo_trial_storage" "$2" && grep -qF " docker network rm faunosteo_trial_net" "$2" && grep -qF "pnpm db:trial destroy" "$2"' _ "$RC" "$CASE/out"
|
|
check "destroy whose backup cannot be made: no removal was run" no_removal
|
|
new_case h5-way-forged; trial create
|
|
forge TR_SERVICE_KEY faunosteo-trial other service_role
|
|
fresh_log; trial_tty faunosteo_trial destroy
|
|
check "destroy with a forged key: refused with the way out, the backup named" bash -c '[ "$1" -ne 0 ] && grep -qF "not signed with its own secret" "$2" && grep -qE "backup [0-9]{8}T[0-9]{6}Z-pre-destroy[a-z0-9-]* is kept" "$2" && grep -qF " docker network rm faunosteo_trial_net" "$2" && grep -qF "pnpm db:trial destroy" "$2"' _ "$RC" "$CASE/out"
|
|
check "destroy with a forged key: no removal was run" no_removal
|
|
|
|
# -- destroy interrupted mid-removal names its backup
|
|
new_case h5-destroy-term; trial create
|
|
echo '^docker volume rm ' > "$CASE/stub/term-on"; fresh_log; trial_tty faunosteo_trial destroy
|
|
check "destroy terminated by SIGTERM mid-removal: one message naming the pre-destroy backup" bash -c '[ "$(grep -c "destroy stopped part-way" "$1")" -eq 1 ] && grep -qE "restore [0-9]{8}T[0-9]{6}Z-pre-destroy" "$1"' _ "$CASE/out"
|
|
|
|
# -- the rotations' traps follow the state
|
|
new_case h5-rotation-window; trial create
|
|
CASE_PATH="$WORK/bin-mvterm:$BASE_PATH"; fresh_log; trial rotate-secrets
|
|
check "rotate-secrets terminated between the rename and the flag: the committed branch, from the state" bash -c '[ "$1" -ne 0 ] && grep -qF "stopped after the database took the new secrets" "$2" && ! grep -qF "stopped before" "$2" && [ ! -e "$3/secrets.next.env" ]' _ "$RC" "$CASE/out" "$STATE_DIR"
|
|
new_case h5-keys-before-rename; trial create
|
|
cp -p "$STATE_DIR/secrets.env" "$CASE/secrets.before"
|
|
CASE_PATH="$WORK/bin-mvterm:$BASE_PATH"; fresh_log; trial rotate-keys
|
|
check "rotate-keys terminated before the rename: no 'holds the new keys' message, secrets.env unchanged" bash -c '[ "$1" -ne 0 ] && ! grep -qF "holds the new keys" "$2" && cmp -s "$3" "$4"' _ "$RC" "$CASE/out" "$STATE_DIR/secrets.env" "$CASE/secrets.before"
|
|
|
|
# -- restore: a leftover helper without a trial volume is refused before the confirmation
|
|
b2_stack h5-restore-helper
|
|
trial_tty faunosteo_trial destroy
|
|
: > "$CASE/stub/containers/faunosteo_trial_helper"
|
|
fresh_log; trial_tty "restore $RN" restore "$RN"
|
|
check "restore with a leftover helper and no trial volume: refused before the confirmation, the hint named" bash -c '[ "$1" -ne 0 ] && grep -qF "docker rm faunosteo_trial_helper" "$2" && ! grep -qF "to go on" "$2" && ! grep -qE "^docker (run|volume|rm|network)" "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
|
|
# -- a leftover secrets.next.env is kept by backups and brought back by restore
|
|
new_case h5-next-backup; trial create
|
|
printf 'SENTINEL-NEXT\n' > "$STATE_DIR/secrets.next.env"; chmod 600 "$STATE_DIR/secrets.next.env"
|
|
trial backup
|
|
RB="$(find "$STATE_DIR/backups" -mindepth 1 -maxdepth 1 -type d -name '*-manual' | head -n 1)"; RN="$(basename "$RB")"
|
|
check "backup with a leftover secrets.next.env holds it, listed in SHA256SUMS" bash -c '[ "$(cat "$1/secrets.next.env")" = SENTINEL-NEXT ] && grep -qF " secrets.next.env" "$1/SHA256SUMS"' _ "$RB"
|
|
rm -f "$STATE_DIR/secrets.next.env"
|
|
fresh_log; trial_tty "restore $RN" restore "$RN"
|
|
check "restore of that backup brings secrets.next.env back (600) and status flags it" bash -c '[ "$1" -eq 0 ] && [ "$(cat "$2/secrets.next.env")" = SENTINEL-NEXT ] && [ "$(stat -c %a "$2/secrets.next.env")" = 600 ]' _ "$RC" "$STATE_DIR"
|
|
fresh_log; trial status
|
|
check "status flags the restored secrets.next.env" out_has "secrets.next.env exists"
|
|
fresh_log; trial_tty "restore $RN" restore "$RN"
|
|
check "restore with a leftover secrets.next.env: the pre-restore backup note mentions it" bash -c '[ "$1" -eq 0 ] && grep -qF "also holds a leftover secrets.next.env" "$2"' _ "$RC" "$CASE/out"
|
|
|
|
echo "-- SIGTERM after the trap is set: one message"
|
|
new_case term-create; echo '^docker volume create .* faunosteo_trial_db$' > "$CASE/stub/term-on"; fresh_log; trial create
|
|
check "create terminated by SIGTERM: one message, nothing removed" bash -c '[ "$(grep -c "create stopped before the end" "$1")" -eq 1 ]' _ "$CASE/out"
|
|
new_case term-migrate; trial create
|
|
printf -- '-- harness\n' > "$WORK/repo/supabase/migrations/29991231000000_harness_term.sql"
|
|
: > "$CASE/stub/term-in-migrate"; fresh_log; trial migrate
|
|
rm -f "$WORK/repo/supabase/migrations/29991231000000_harness_term.sql"
|
|
check "migrate terminated by SIGTERM: one message naming the pre-migrate backup" bash -c '[ "$(grep -c "migrate stopped part-way" "$1")" -eq 1 ] && grep -qE "restore [0-9]{8}T[0-9]{6}Z-pre-migrate" "$1"' _ "$CASE/out"
|
|
new_case term-keys; trial create
|
|
echo '^docker run -d --name faunosteo_trial_storage ' > "$CASE/stub/term-on"; fresh_log; trial rotate-keys
|
|
check "rotate-keys terminated by SIGTERM: one message" bash -c '[ "$(grep -c "rotate-keys stopped part-way" "$1")" -eq 1 ]' _ "$CASE/out"
|
|
new_case term-rotation; trial create
|
|
echo '^tag:rotate$' > "$CASE/stub/term-on"; fresh_log; trial rotate-secrets
|
|
check "rotate-secrets terminated by SIGTERM: one message, the uncommitted branch" bash -c '[ "$(grep -c "rotate-secrets stopped" "$1")" -eq 1 ] && grep -qF "stopped before secrets.env took the new secrets" "$1"' _ "$CASE/out"
|
|
|
|
echo "-- accounts, grants, drawings, app"
|
|
PW=correct-horse-battery
|
|
fresh_stdin() { find "$CASE/stub/stdin" -type f -delete; }
|
|
no_role_assigned() { stdin_lacks assign_platform_role; }
|
|
# A catalogue grant never writes a platform role: neither the function nor the table appears in any SQL it sent.
|
|
catalog_grant_only() { stdin_lacks assign_platform_role && stdin_lacks profile_roles && stdin_has anatomical_catalog_grants; }
|
|
no_catalog_write() { stdin_lacks 'db-trial:grant-catalog-write'; } # the audit row is part of that SQL
|
|
set_factors() { # n: n verified factors, as the count and as the list the stub answers
|
|
echo "$1" > "$CASE/stub/answers/grant-factor-count"
|
|
printf '%s\n' 'Phone | 2026-11-09 10:00 UTC' 'Tablet | 2026-11-09 10:05 UTC' | head -n "$1" > "$CASE/stub/answers/grant-factors"
|
|
}
|
|
# shellcheck disable=SC2046
|
|
stdin_of() { grep -l -- "-- db-trial:$1\$" /dev/null $(stdin_files) | head -n 1; } # the SQL a tag sent
|
|
new_case people; trial create
|
|
check "people: create" [ "$RC" -eq 0 ]
|
|
fresh_log; trial account 'not-an-email'
|
|
check "account: a malformed address is refused before any call" refused_early "e-mail address"
|
|
fresh_log; trial_input account owner@trial.test <<<"$PW"$'\n'"$PW"
|
|
check "account: a password is never read from a pipe, nothing sent" bash -c '[ "$1" -ne 0 ] && grep -qF "needs a terminal" "$2" && ! grep -q "^curl .*admin/users" "$3" && ! grep -qF "$4" "$2" "$3"' _ "$RC" "$CASE/out" "$CASE/log" "$PW"
|
|
fresh_log; trial_typed $'short\nshort' account owner@trial.test
|
|
check "account: a short password is refused, nothing sent" bash -c '[ "$1" -ne 0 ] && ! grep -q "^curl .*admin/users" "$2" && grep -qF "12 characters" "$3" && ! grep -qF short "$2"' _ "$RC" "$CASE/log" "$CASE/out"
|
|
fresh_log; trial_typed "$PW"$'\nother-horse-battery' account owner@trial.test
|
|
check "account: two different passwords are refused, nothing sent" bash -c '[ "$1" -ne 0 ] && grep -qF "differ" "$2" && ! grep -q "^curl .*admin/users" "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
: > "$CASE/stub/fail/admin-users"
|
|
fresh_log; trial_typed "$PW"$'\n'"$PW" account owner@trial.test
|
|
check "account: GoTrue refusing the account is told, no password in calls or output" bash -c '[ "$1" -ne 0 ] && grep -qF "account not created" "$2" && ! grep -qF "$3" "$2" "$4"' _ "$RC" "$CASE/out" "$PW" "$CASE/log"
|
|
rm -f "$CASE/stub/fail/admin-users"
|
|
fresh_log; trial_typed "$PW"$'\n'"$PW" account owner@trial.test
|
|
check "account: created and confirmed" bash -c '[ "$1" -eq 0 ] && grep -qF "account owner@trial.test created and confirmed" "$2"' _ "$RC" "$CASE/out"
|
|
check "account: GoTrue admin API on loopback, header through a pipe fd, body on stdin" bash -c 'grep -qE "^curl -q --noproxy \* -fsS -o /dev/null -X POST http://127.0.0.1:58999/admin/users -H @/dev/fd/[0-9]+ -H Content-Type: application/json --data-binary @-$" "$1"' _ "$CASE/log"
|
|
check "account: the header sent carries exactly the checked service key, no header file exists" bash -c '[ "$(cat "$1")" = "$(printf "Authorization: Bearer %s\n" "$(sed -n "s/^TR_SERVICE_KEY=//p" "$2")" | sha256sum | cut -c1-16)" ] && [ ! -e "$3/service-header" ]' _ "$CASE/stub/curl-header-sha" "$STATE_DIR/secrets.env" "$STATE_DIR"
|
|
check "account: the password never appears in calls or output" bash -c '! grep -qF "$1" "$2" "$3"' _ "$PW" "$CASE/log" "$CASE/out"
|
|
check "account: no secret in calls or output" secrets_absent "$STATE_DIR/secrets.env"
|
|
check "account: the body is a confirmed account" stdin_has '"email_confirm":true'
|
|
check "account: the state folder holds no file that is not 600" bash -c '[ -z "$(find "$1" -type f ! -perm 600)" ]' _ "$STATE_DIR"
|
|
fresh_log; trial grant owner@trial.test root
|
|
check "grant: an unknown right is refused before any call" refused_early "right:"
|
|
set_factors 0
|
|
fresh_stdin; fresh_log; trial_tty 'grant owner' grant owner@trial.test owner
|
|
check "grant owner with no factor: refused (one needed), nothing assigned" bash -c '[ "$1" -ne 0 ] && grep -qF "owner needs 1" "$2" && grep -qF "nothing was granted" "$2"' _ "$RC" "$CASE/out"
|
|
check "grant owner with no factor: no role SQL ran" no_role_assigned
|
|
set_factors 2
|
|
fresh_log; trial_tty no grant owner@trial.test owner
|
|
check "grant owner, wrong phrase: nothing assigned" bash -c '[ "$1" -ne 0 ] && grep -qF "not confirmed" "$2"' _ "$RC" "$CASE/out"
|
|
check "grant owner, wrong phrase: no role SQL ran" no_role_assigned
|
|
fresh_log; trial_input grant owner@trial.test owner <<<'grant owner'
|
|
check "grant owner, phrase piped without a terminal: refused before any call" refused_early "needs a terminal"
|
|
check "grant owner, phrase piped: no role SQL ran" no_role_assigned
|
|
: > "$CASE/stub/fail/grant-factors"
|
|
fresh_log; trial_tty 'grant owner' grant owner@trial.test owner
|
|
check "grant: factors that cannot be read refuse, nothing granted" bash -c '[ "$1" -ne 0 ] && grep -qF "nothing was granted" "$2"' _ "$RC" "$CASE/out"
|
|
rm -f "$CASE/stub/fail/grant-factors"
|
|
: > "$CASE/stub/fail/grant-role"
|
|
fresh_log; trial_tty 'grant owner' grant owner@trial.test owner
|
|
check "grant owner: the role SQL failing is told" bash -c '[ "$1" -ne 0 ] && grep -qF "owner not granted to owner@trial.test" "$2"' _ "$RC" "$CASE/out"
|
|
rm -f "$CASE/stub/fail/grant-role"; fresh_stdin
|
|
fresh_log; trial_tty 'grant owner' grant owner@trial.test owner
|
|
check "grant owner: factors shown, operator path, audit row" bash -c '[ "$1" -eq 0 ] && grep -qF "Tablet | 2026-11-09 10:05 UTC" "$2" && grep -rlF "private.assign_platform_role(null, :'"'"'uid'"'"'::uuid" "$3" | grep -q . && grep -rlF "platform_role.operator_bootstrap" "$3" | grep -q .' _ "$RC" "$CASE/out" "$CASE/stub/stdin"
|
|
check "grant owner: email, role and operator as psql variables" log_has "-v email=owner@trial.test -v role=owner -v need=1 -v operator="
|
|
check "grant owner: no secret in calls or output" secrets_absent "$STATE_DIR/secrets.env"
|
|
set_factors 1
|
|
fresh_stdin; fresh_log; trial_tty 'grant owner' grant owner@trial.test owner
|
|
check "grant owner with one factor: granted, one factor suffices" bash -c '[ "$1" -eq 0 ] && grep -qF "owner granted to owner@trial.test" "$2"' _ "$RC" "$CASE/out"
|
|
check "grant owner with one factor: need=1 passed as a psql variable" log_has "-v email=owner@trial.test -v role=owner -v need=1 -v operator="
|
|
fresh_stdin
|
|
fresh_log; trial_tty 'grant admin' grant practitioner@trial.test admin
|
|
check "grant admin with one factor: granted, one factor suffices" bash -c '[ "$1" -eq 0 ] && grep -qF "admin granted to practitioner@trial.test" "$2"' _ "$RC" "$CASE/out"
|
|
check "grant admin: role passed as a psql variable" log_has "-v email=practitioner@trial.test -v role=admin -v need=1 -v operator="
|
|
set_factors 0
|
|
fresh_log; trial_tty 'grant admin' grant practitioner@trial.test admin
|
|
check "grant admin with no factor: refused" bash -c '[ "$1" -ne 0 ] && grep -qF "admin needs 1" "$2"' _ "$RC" "$CASE/out"
|
|
fresh_stdin; fresh_log; trial_tty 'grant sheet_editor' grant practitioner@trial.test sheet_editor
|
|
check "grant sheet_editor (admin already): inserted, no O1 note" bash -c '[ "$1" -eq 0 ] && grep -qF "sheet_editor granted" "$2" && ! grep -qF "rule O1" "$2"' _ "$RC" "$CASE/out"
|
|
check "grant sheet_editor: a catalogue right never assigns a platform role (no implicit admin)" catalog_grant_only
|
|
echo already > "$CASE/stub/answers/grant-catalog"
|
|
fresh_stdin; fresh_log; trial_tty 'x' grant practitioner@trial.test sheet_editor
|
|
check "grant sheet_editor again: nothing changed, nothing written" bash -c '[ "$1" -eq 0 ] && grep -qF "already active" "$2"' _ "$RC" "$CASE/out"
|
|
check "grant sheet_editor again: no write SQL sent" no_catalog_write
|
|
echo ok > "$CASE/stub/answers/grant-catalog"
|
|
fresh_log; trial_tty 'grant catalog_reader' grant practitioner@trial.test catalog_reader
|
|
check "grant catalog_reader: granted" bash -c '[ "$1" -eq 0 ] && grep -qF "catalog_reader granted" "$2"' _ "$RC" "$CASE/out"
|
|
echo 'oops' > "$CASE/stub/answers/grant-catalog"
|
|
fresh_log; trial_tty 'grant sheet_reviewer' grant practitioner@trial.test sheet_reviewer
|
|
check "grant: an unexpected database answer is refused" bash -c '[ "$1" -ne 0 ] && grep -qF "unexpected answer" "$2"' _ "$RC" "$CASE/out"
|
|
echo ok > "$CASE/stub/answers/grant-catalog"
|
|
: > "$CASE/stub/fail/grant-catalog-write"
|
|
fresh_stdin; fresh_log; trial_tty 'grant sheet_reviewer' grant practitioner@trial.test sheet_reviewer
|
|
check "grant: the catalogue write failing after a passing check: refused, nothing granted" bash -c '[ "$1" -ne 0 ] && grep -qF "sheet_reviewer not granted" "$2" && grep -qF "nothing was granted" "$2" && ! grep -qF "sheet_reviewer granted to" "$2"' _ "$RC" "$CASE/out"
|
|
rm -f "$CASE/stub/fail/grant-catalog-write"
|
|
|
|
echo "-- B3 review fixes"
|
|
# 3: every refusal reason, distinct, with no write SQL and no audit row.
|
|
for pair in 'no_account|no account practitioner@trial.test|sheet_reviewer' 'inactive|inactive or its e-mail is not confirmed|sheet_reviewer' \
|
|
'no_totp|holds no verified TOTP factor|sheet_reviewer' 'not_admin|grant practitioner@trial.test admin|sheet_editor' 'not_admin|grant practitioner@trial.test admin|sheet_publisher'; do
|
|
IFS='|' read -r status text kind <<<"$pair"
|
|
echo "$status" > "$CASE/stub/answers/grant-catalog"
|
|
fresh_stdin; fresh_log; trial_tty "grant $kind" grant practitioner@trial.test "$kind"
|
|
check "grant $kind, $status: refused with its own reason, nothing written" bash -c '[ "$1" -ne 0 ] && grep -qF -- "$2" "$3" && grep -qF "nothing was granted" "$3"' _ "$RC" "$text" "$CASE/out"
|
|
check "grant $kind, $status: no insert, no audit row" no_catalog_write
|
|
done
|
|
echo ok > "$CASE/stub/answers/grant-catalog"
|
|
# 3: the check SQL carries the rules of public.grant_catalog_right.
|
|
fresh_stdin; fresh_log; trial_tty 'grant sheet_editor' grant practitioner@trial.test sheet_editor
|
|
check "grant catalogue: the eligibility rules are in the check and again in the write" bash -c 'for f in "$@"; do grep -q is_confirmed_active_account "$f" && grep -q has_verified_totp "$f" && grep -q is_platform_admin "$f" || exit 1; done' _ "$(stdin_of grant-catalog)" "$(stdin_of grant-catalog-write)"
|
|
file_has_all() { local f="$1" t; shift; for t in "$@"; do grep -qF -- "$t" "$f" || return 1; done; }
|
|
ACTIVE_ROW="g.revoked_at is null and (g.expires_at is null or g.expires_at > now())"
|
|
check "grant catalogue: the check SQL carries every reason and rule of public.grant_catalog_right" file_has_all "$(stdin_of grant-catalog)" \
|
|
"when u.id is null then 'no_account'" "when not private.is_confirmed_active_account(u.id) then 'inactive'" \
|
|
"when :'kind' <> 'catalog_reader' and not private.has_verified_totp(u.id) then 'no_totp'" \
|
|
"when :'kind' in ('sheet_editor', 'sheet_publisher') and not private.is_platform_admin(u.id) then 'not_admin'" \
|
|
"$ACTIVE_ROW) then 'already'"
|
|
check "grant catalogue: the write SQL re-checks the same rules and the active-row rule" file_has_all "$(stdin_of grant-catalog-write)" \
|
|
"private.is_confirmed_active_account(:'uid'::uuid)" "(:'kind' = 'catalog_reader' or private.has_verified_totp(:'uid'::uuid))" \
|
|
"(:'kind' not in ('sheet_editor', 'sheet_publisher') or private.is_platform_admin(:'uid'::uuid))" "$ACTIVE_ROW"
|
|
check "grant catalogue: insert and audit row in one explicit transaction" bash -c 'f="$1"; [ "$(sed -n 2p "$f")" = "begin;" ] && grep -q "^insert into public.anatomical_catalog_grants" "$f" && grep -q "catalog_grant.operator_bootstrap" "$f" && [ "$(tail -n 1 "$f")" = "commit;" ]' _ "$(stdin_of grant-catalog-write)"
|
|
check "grant catalogue: the audit row names kind, operator and reason" bash -c 'grep -q "jsonb_build_object(.kind., :.kind., .operator., :.operator." "$1"' _ "$(stdin_of grant-catalog-write)"
|
|
check "grant catalogue: the script comments granted_by as the account's own id, and no platform role is written" bash -c 'grep -qF "# granted_by is the account'"'"'s own id" "$1" && ! grep -qE "profile_roles|assign_platform_role" "$2" "$3"' _ "$REPO/scripts/db-trial.sh" "$(stdin_of grant-catalog-write)" "$(stdin_of grant-catalog)"
|
|
check "grant: no --single-transaction in any psql call" bash -c '! grep -q -- "--single-transaction" "$1"' _ "$CASE/log"
|
|
fresh_stdin; fresh_log; trial_tty 'grant catalog_reader' grant practitioner@trial.test catalog_reader
|
|
check "grant catalog_reader: needs no TOTP and no admin (the check SQL scopes both to other kinds)" bash -c '[ "$1" -eq 0 ] && grep -qF "<> '"'"'catalog_reader'"'"' and not private.has_verified_totp" "$2" && grep -qF "catalog_reader granted" "$3"' _ "$RC" "$(stdin_of grant-catalog)" "$CASE/out"
|
|
# 4: exact typed phrase for a catalogue grant; piped or wrong refuses with nothing written.
|
|
fresh_stdin; fresh_log; trial_tty 'grant sheet_reviewe' grant practitioner@trial.test sheet_reviewer
|
|
check "grant catalogue, wrong phrase: not confirmed, nothing written" bash -c '[ "$1" -ne 0 ] && grep -qF "not confirmed" "$2"' _ "$RC" "$CASE/out"
|
|
check "grant catalogue, wrong phrase: no insert, no audit" no_catalog_write
|
|
fresh_log; trial_input grant practitioner@trial.test sheet_reviewer <<<'grant sheet_reviewer'
|
|
check "grant catalogue, phrase piped: refused before any call" refused_early "needs a terminal"
|
|
# 10: terminal-only commands refuse a piped stdin before any call.
|
|
fresh_log; trial_input account owner@trial.test <<<"$PW"
|
|
check "account, piped stdin: refused before any call" refused_early "needs a terminal"
|
|
fresh_log; trial_input restore 20261101T101010Z-manual <<<'restore'
|
|
check "restore, piped stdin: refused before any call" refused_early "needs a terminal"
|
|
fresh_log; trial_input destroy <<<'destroy'
|
|
check "destroy, piped stdin: refused before any call" refused_early "needs a terminal"
|
|
# 1: the count comes from SQL; a name with a newline cannot add a line.
|
|
set_factors 1
|
|
printf '%s\n' 'Phone | 2026-11-09 10:00 UTC' 'Injected | 2026-11-09 10:01 UTC' > "$CASE/stub/answers/grant-factors"
|
|
fresh_stdin; fresh_log; trial_tty 'x' grant owner@trial.test admin
|
|
check "grant: factor_list output is shown one indented line per factor line, nothing written before the confirmation" bash -c '[ "$1" -ne 0 ] && grep -qE "^ Phone \| 2026-11-09 10:00 UTC[[:cntrl:]]*$" "$2" && grep -qE "^ Injected \| 2026-11-09 10:01 UTC[[:cntrl:]]*$" "$2"' _ "$RC" "$CASE/out"
|
|
check "grant: no role SQL sent before the confirmation" stdin_lacks db-trial:grant-role
|
|
check "grant: the factor count is a count(*) in SQL" bash -c 'grep -qE "select count\(\*\)" "$1" && grep -q "factor_type = .totp. and f.status = .verified." "$1"' _ "$(stdin_of grant-factor-count)"
|
|
set_factors 2; fresh_stdin; fresh_log; trial_tty 'grant owner' grant owner@trial.test owner
|
|
SANITISED="left(regexp_replace(coalesce(nullif(f.friendly_name, ''), '(no name)'), '[^[:alnum:] ._-]', '?', 'g'), 40)"
|
|
check "grant: SQL text check, the displayed name is sanitised in SQL (no newline, CR or ESC reaches the terminal)" bash -c 'grep -qF -- "$2" "$1"' _ "$(stdin_of grant-factors)" "$SANITISED"
|
|
# 2: the transaction counts again.
|
|
echo 0 > "$CASE/stub/answers/txn-factors"; fresh_stdin
|
|
fresh_log; trial_tty 'grant owner' grant owner@trial.test owner
|
|
check "grant owner: script handling of a failing grant session (stub emulates \\gset with zero rows, count 2 then 0): nothing granted" bash -c '[ "$1" -ne 0 ] && grep -qF "nothing was granted" "$2" && ! grep -qF "owner granted to owner@trial.test" "$2"' _ "$RC" "$CASE/out"
|
|
check "grant owner: the transaction SQL counts the factors against :need" bash -c 'grep -q "mfa_factors" "$1" && grep -q ">= :need" "$1"' _ "$(stdin_of grant-role)"
|
|
check "grant role: explicit begin and commit, never --single-transaction" bash -c 'f="$1"; [ "$(sed -n 2p "$f")" = "begin;" ] && [ "$(tail -n 1 "$f")" = "commit;" ] && ! grep -q -- "--single-transaction" "$2"' _ "$(stdin_of grant-role)" "$CASE/log"
|
|
echo 1 > "$CASE/stub/answers/txn-factors"; fresh_stdin; fresh_log; trial_tty 'grant owner' grant owner@trial.test owner
|
|
check "grant owner: one factor still there in the transaction: granted" bash -c '[ "$1" -eq 0 ] && grep -qF "owner granted to owner@trial.test" "$2"' _ "$RC" "$CASE/out"
|
|
rm -f "$CASE/stub/answers/txn-factors"
|
|
# 7: the e-mail is lowercased before any use.
|
|
fresh_stdin; fresh_log; trial_tty 'grant sheet_reviewer' grant Foo@Example.com sheet_reviewer
|
|
check "grant Foo@Example.com: the lowercased address is used everywhere" bash -c '[ "$1" -eq 0 ] && grep -qF -- "-v email=foo@example.com" "$2" && ! grep -qF "Foo@" "$2" "$3"' _ "$RC" "$CASE/log" "$CASE/out"
|
|
fresh_stdin; fresh_log; trial_typed "$PW"$'\n'"$PW" account Foo@Example.com
|
|
check "account Foo@Example.com: the body carries the lowercased address" bash -c '[ "$1" -eq 0 ] && grep -qF "\"email\":\"foo@example.com\"" /dev/null $(find "$2" -type f) && ! grep -qF "Foo@" "$3"' _ "$RC" "$CASE/stub/stdin" "$CASE/out"
|
|
# 6: passwords count their blanks.
|
|
fresh_log; trial_typed '12345678901'$'\n''12345678901' account long@trial.test
|
|
check "account: an 11-character password is refused" bash -c '[ "$1" -ne 0 ] && grep -qF "12 characters" "$2" && ! grep -q "^curl .*admin/users" "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
fresh_stdin; fresh_log; trial_typed '123456789012'$'\n''123456789012' account long@trial.test
|
|
check "account: a 12-character password is accepted" [ "$RC" -eq 0 ]
|
|
SPACED=' leading-and-trailing '
|
|
fresh_stdin; fresh_log; trial_typed "$SPACED"$'\n'"$SPACED" account spaced@trial.test
|
|
check "account: a password with leading and trailing blanks reaches the body unchanged" bash -c '[ "$1" -eq 0 ] && [ "$(node -e "const b = JSON.parse(require(\"fs\").readFileSync(process.argv[1], \"utf8\")); console.log(b.password === process.argv[2] ? 1 : 0)" "$(find "$2" -type f | head -n 1)" "$3")" = 1 ]' _ "$RC" "$CASE/stub/stdin" "$SPACED"
|
|
check "account: the spaced password is in no call or output" bash -c '! grep -qF "leading-and-trailing" "$1" "$2"' _ "$CASE/log" "$CASE/out"
|
|
# 8: read_new_password cannot collide with a caller's variable name.
|
|
check "read_new_password: callers named typed or again still get their password" bash -c '
|
|
die() { echo "$*" >&2; exit 1; }
|
|
source <(sed -n "/^read_new_password()/,/^}/p" "$1")
|
|
for v in typed again; do
|
|
read_new_password "$v" <<<"correct-horse-battery"$'"'"'\n'"'"'"correct-horse-battery" 2>/dev/null || exit 1
|
|
[ "${!v}" = correct-horse-battery ] || exit 1
|
|
done' _ "$WORK/repo/scripts/db-trial.sh"
|
|
SERVICE_SHA="$(sed -n 's/^TR_SERVICE_KEY=//p' "$STATE_DIR/secrets.env" | tr -d '\n' | sha256sum | cut -c1-16)"
|
|
ANON_SHA="$(sed -n 's/^TR_ANON_KEY=//p' "$STATE_DIR/secrets.env" | tr -d '\n' | sha256sum | cut -c1-16)"
|
|
fresh_log; EXTRA=(INIT_CWD=/elsewhere FAUNOSTEO_DEV_HOST=127.0.0.1); trial assets; EXTRA=()
|
|
check "assets: upload then check, through the trial gateway" bash -c '[ "$1" -eq 0 ] && grep -qx "upload supabase/seed/anatomical-sheets/equine/draft" "$2" && grep -qx "upload --check supabase/seed/anatomical-sheets/equine/draft" "$2" && [ "$(grep -c "^upload-env url=http://127.0.0.1:58801 " "$2")" -eq 2 ]' _ "$RC" "$CASE/log"
|
|
check "assets: the service key by environment, LAN host and INIT_CWD dropped" bash -c '[ "$(grep -c "^upload-env .*key-sha=$1 dev-host= init-cwd=$" "$2")" -eq 2 ]' _ "$SERVICE_SHA" "$CASE/log"
|
|
check "assets: every drawing confirmed" out_has "1/1 uploaded"
|
|
check "assets: no secret in calls or output" secrets_absent "$STATE_DIR/secrets.env"
|
|
echo 0 > "$CASE/stub/answers/assets-uploaded"; fresh_log; trial assets
|
|
check "assets: a drawing not confirmed in the database fails" bash -c '[ "$1" -ne 0 ] && grep -qF "not every drawing row" "$2"' _ "$RC" "$CASE/out"
|
|
echo 1 > "$CASE/stub/answers/assets-uploaded"
|
|
EXTRA=(http_proxy=http://127.0.0.1:9 HTTPS_PROXY=http://127.0.0.1:9 ALL_PROXY=socks5://127.0.0.1:9 NODE_USE_ENV_PROXY=1)
|
|
fresh_log; trial app; EXTRA=()
|
|
check "app: Vite on the trial host and 5194, strict port" log_has 'vite --config vite/trial.config.ts --host 127.0.0.1 --port 5194 --strictPort'
|
|
check "app: anon key by environment, no PGPASSWORD, heap capped, trial gateway" bash -c 'grep -qx "vite-env anon-sha=$1 pgpassword= node-options=--max-old-space-size=768 gateway=http://127.0.0.1:58801 host=127.0.0.1 url=http://127.0.0.1:5194 proxies=" "$2"' _ "$ANON_SHA" "$CASE/log"
|
|
check "app: every curl pinned (-q, --noproxy), Vite started with no proxy variable" curls_pinned
|
|
check "app: no secret in calls or output" secrets_absent "$STATE_DIR/secrets.env"
|
|
if hold_port 5194; then fresh_log; trial app; check "app: port 5194 in use, nothing started" refused "5194 is in use"; release_port
|
|
else fail "could not hold 127.0.0.1:5194 for the app case"; fi
|
|
: > "$CASE/stub/term-in-vite"; fresh_log; trial app; rm -f "$CASE/stub/term-in-vite"
|
|
check "app terminated by SIGTERM: exit 130, one message, the stack untouched" bash -c '[ "$1" -eq 130 ] && [ "$(grep -c "trial app stopped" "$2")" -eq 1 ] && ! grep -qE "^docker (stop|rm)" "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
|
|
# 9: the stop waits for Vite and leaves no orphan, whichever signal ends the script.
|
|
vite_gone_and_port_free() { # script exit code, the expected code
|
|
[ "$RC" -eq "$1" ] && [ -s "$CASE/stub/vite.pid" ] && ! kill -0 "$(cat "$CASE/stub/vite.pid")" 2>/dev/null \
|
|
&& [ -z "$(ss -Hltn 'sport = :5194')" ] && [ "$(grep -c 'trial app stopped' "$CASE/out")" -eq 1 ] && ! grep -qE '^docker (stop|rm)' "$CASE/log"
|
|
}
|
|
for sig in term int; do
|
|
rm -f "$CASE/stub/vite.pid"; : > "$CASE/stub/vite-hold"; echo "$WORK/$sig-trial.sh" > "$CASE/stub/vite-hold-sig"
|
|
# A harness started in the background has SIGINT ignored, and a script cannot trap what it inherits ignored.
|
|
LAUNCH=(python3 -c 'import os, signal, sys; signal.signal(signal.SIGINT, signal.SIG_DFL); os.execvp(sys.argv[1], sys.argv[1:])')
|
|
fresh_log; run_script db-trial.sh app < /dev/null; LAUNCH=()
|
|
check "app ended by SIG${sig^^}: exit 130, Vite gone and port 5194 free on return, the stack untouched" vite_gone_and_port_free 130
|
|
rm -f "$CASE/stub/vite-hold" "$CASE/stub/vite-hold-sig"
|
|
done
|
|
# Each run of the app uses the host of its own FAUNOSTEO_TRIAL_HOST (the address is decided at each use).
|
|
PRIVATE_HOST="$(ip -4 -o addr | sed -n 's/^.* inet \(10\.[0-9.]*\|192\.168\.[0-9.]*\|172\.\(1[6-9]\|2[0-9]\|3[01]\)\.[0-9.]*\)\/.*$/\1/p' | head -n 1)"
|
|
for host in 127.0.0.1 $PRIVATE_HOST; do
|
|
fresh_log; EXTRA=(FAUNOSTEO_TRIAL_HOST="$host"); trial app; EXTRA=()
|
|
check "app: FAUNOSTEO_TRIAL_HOST=$host: Vite, URL and proxy host follow it" bash -c '[ "$1" -eq 0 ] && grep -qF -- "--host $2 --port 5194" "$3" && grep -qF "host=$2 url=http://$2:5194" "$3" && grep -qF "trial app: http://$2:5194" "$4"' _ "$RC" "$host" "$CASE/log" "$CASE/out"
|
|
done
|
|
[ -n "$PRIVATE_HOST" ] || echo "SKIP app with a private FAUNOSTEO_TRIAL_HOST: this machine has no private IPv4 address (untested)"
|
|
|
|
echo "-- the lock comes first for account, grant, assets"
|
|
new_case people-lock; trial create
|
|
rm -f "$CASE/stub/volumes/faunosteo_trial_db"
|
|
flock "$STATE_DIR/.lock" sleep 6 & LOCK_HOLDER=$!
|
|
sleep 0.5
|
|
fresh_log; trial assets
|
|
check "assets: the lock is taken before the stack is checked" bash -c '[ "$1" -ne 0 ] && grep -qF "another pnpm db:trial command is running" "$2"' _ "$RC" "$CASE/out"
|
|
fresh_log; trial_tty x grant owner@trial.test sheet_editor
|
|
check "grant: the lock is taken before the stack is checked" bash -c '[ "$1" -ne 0 ] && grep -qF "another pnpm db:trial command is running" "$2"' _ "$RC" "$CASE/out"
|
|
fresh_log; trial_typed "$PW"$'\n'"$PW" account owner@trial.test
|
|
check "account: the lock is taken before the prompt" bash -c '[ "$1" -ne 0 ] && grep -qF "another pnpm db:trial command is running" "$2" && ! grep -qF "Password" "$2"' _ "$RC" "$CASE/out"
|
|
wait "$LOCK_HOLDER"
|
|
|
|
echo "-- identity of the target (R13)"
|
|
new_case people-r13; trial create
|
|
echo other_service > "$CASE/stub/answers/identity"
|
|
for action in app assets; do
|
|
fresh_log; trial "$action"
|
|
check "$action: a gateway port answering another identity is refused" refused "does not answer as the faunosteo_trial gateway"
|
|
done
|
|
rm -f "$CASE/stub/answers/identity"; : > "$CASE/stub/fail/identity"
|
|
fresh_log; trial app
|
|
check "app: no identity answer at all is refused" refused "does not answer as the faunosteo_trial gateway"
|
|
rm -f "$CASE/stub/fail/identity"
|
|
cp -p "$CASE/stub/ports/faunosteo_trial_gateway" "$CASE/gateway.port"
|
|
echo '8000/tcp -> 127.0.0.1:58802' > "$CASE/stub/ports/faunosteo_trial_gateway"
|
|
for action in app assets; do
|
|
fresh_log; trial "$action"
|
|
check "$action: the gateway container published elsewhere is refused" refused "faunosteo_trial_gateway is not published on 127.0.0.1:58801 only"
|
|
done
|
|
cp -p "$CASE/gateway.port" "$CASE/stub/ports/faunosteo_trial_gateway"
|
|
cp -p "$CASE/stub/ports/faunosteo_trial_auth" "$CASE/auth.port"
|
|
echo '9999/tcp -> 0.0.0.0:58999' > "$CASE/stub/ports/faunosteo_trial_auth"
|
|
fresh_log; trial_typed "$PW"$'\n'"$PW" account second@trial.test
|
|
check "account: GoTrue published elsewhere is refused before the prompt" bash -c '[ "$1" -ne 0 ] && grep -qF "faunosteo_trial_auth is not published on 127.0.0.1:58999 only" "$2" && ! grep -qF "Password" "$2" && ! grep -q "^curl .*admin/users" "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
cp -p "$CASE/auth.port" "$CASE/stub/ports/faunosteo_trial_auth"
|
|
# Keys that look right but are not this stack's: the sandbox issuer signed with the trial secret,
|
|
# and the trial claims signed with another secret.
|
|
cp -p "$STATE_DIR/secrets.env" "$CASE/secrets.good"
|
|
forge TR_ANON_KEY db-sandbox own anon; fresh_log; trial app
|
|
check "app: an anon key of the sandbox issuer is refused" refused "anon key in secrets.env is not this stack's"
|
|
cp -p "$CASE/secrets.good" "$STATE_DIR/secrets.env"
|
|
forge TR_ANON_KEY faunosteo-trial other anon; fresh_log; trial app
|
|
check "app: an anon key signed with another secret is refused" refused "anon key in secrets.env is not this stack's"
|
|
cp -p "$CASE/secrets.good" "$STATE_DIR/secrets.env"
|
|
forge TR_SERVICE_KEY faunosteo-trial other service_role
|
|
fresh_log; trial assets
|
|
check "assets: a service key signed with another secret is refused" refused "service_role key in secrets.env is not this stack's"
|
|
fresh_log; trial_typed "$PW"$'\n'"$PW" account third@trial.test
|
|
check "account: the same forged service key is refused before the prompt" bash -c '[ "$1" -ne 0 ] && grep -qF "service_role key in secrets.env is not this stack" "$2" && ! grep -qF "Password" "$2" && ! grep -q "^curl .*admin/users" "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
DB_ENV_BEFORE="$(env_file_state "$STATE_DIR/db.env")"; STORAGE_ENV_BEFORE="$(env_file_state "$STATE_DIR/storage.env")"
|
|
rm -f "$CASE/stub/containers/faunosteo_trial_rest" "$CASE/stub/ports/faunosteo_trial_rest"
|
|
sleep 1; fresh_log; trial start
|
|
check "start: a forged service key and a missing container: refused, no env file rewritten (content, mtime)" bash -c '[ "$1" -ne 0 ] && grep -qF "service_role key in secrets.env is not this stack" "$2" && [ -z "$3" ] && [ "$4" = "$5" ] && [ "$6" = "$7" ]' _ "$RC" "$CASE/out" "$(changes)" "$DB_ENV_BEFORE" "$(env_file_state "$STATE_DIR/db.env")" "$STORAGE_ENV_BEFORE" "$(env_file_state "$STATE_DIR/storage.env")"
|
|
cp -p "$CASE/secrets.good" "$STATE_DIR/secrets.env"
|
|
fresh_log; trial start
|
|
check "start: with this stack's keys the missing container is recreated" bash -c '[ "$1" -eq 0 ] && grep -q "^docker run -d --name faunosteo_trial_rest " "$2"' _ "$RC" "$CASE/log"
|
|
|
|
echo "-- expired keys (F1)"
|
|
forge TR_ANON_KEY faunosteo-trial own anon -60; forge TR_SERVICE_KEY faunosteo-trial own service_role -60
|
|
fresh_log; trial app
|
|
check "app: an expired anon key is refused, naming rotate-keys" refused "expired: pnpm db:trial rotate-keys"
|
|
fresh_log; trial assets
|
|
check "assets: an expired service key is refused, naming rotate-keys" refused "expired: pnpm db:trial rotate-keys"
|
|
fresh_log; trial_typed "$PW"$'\n'"$PW" account fourth@trial.test
|
|
check "account: an expired service key is refused before the prompt" bash -c '[ "$1" -ne 0 ] && grep -qF "expired: pnpm db:trial rotate-keys" "$2" && ! grep -qF "Password" "$2" && ! grep -q "^curl .*admin/users" "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
fresh_log; trial status
|
|
check "status reports expired keys" out_has "EXPIRED"
|
|
rm -f "$CASE/stub/containers/faunosteo_trial_rest" "$CASE/stub/ports/faunosteo_trial_rest"
|
|
fresh_log; trial start
|
|
check "start: expired keys never block the recreation of a missing container" bash -c '[ "$1" -eq 0 ] && grep -q "^docker run -d --name faunosteo_trial_rest " "$2"' _ "$RC" "$CASE/log"
|
|
fresh_log; trial stop; fresh_log; trial rotate-keys
|
|
check "rotate-keys on a stopped stack with expired keys: renewed, Storage removed for start to recreate" bash -c '[ "$1" -eq 0 ] && grep -qx "docker rm faunosteo_trial_storage" "$2" && ! grep -q "^docker run -d --name faunosteo_trial_storage " "$2" && grep -qF "pnpm db:trial start recreates Storage" "$3"' _ "$RC" "$CASE/log" "$CASE/out"
|
|
fresh_log; trial start
|
|
check "start after it recreates Storage with the new keys; app accepts them" bash -c '[ "$1" -eq 0 ] && grep -q "^docker run -d --name faunosteo_trial_storage " "$2"' _ "$RC" "$CASE/log"
|
|
fresh_log; trial app
|
|
check "app: the renewed anon key passes" [ "$RC" -eq 0 ]
|
|
|
|
fresh_log; trial stop; fresh_log; trial app
|
|
check "app: refused while the stack is stopped" refused "is not running"
|
|
|
|
echo "-- closure code-review fixes (2026-11-11)"
|
|
# 1: a daemon lost between the dispatch check and an inspect is never read as "absent".
|
|
lost_refused() { # inspect kind, resource name
|
|
[ "$RC" -ne 0 ] && [ -z "$(changes)" ] && out_has "docker $1 inspect $2 failed (exit 1)"
|
|
}
|
|
new_case lost-create; : > "$CASE/stub/fail/daemon-lost"; trial create
|
|
check "daemon lost mid-command: create refuses, nothing created, no state written" bash -c '[ "$1" -ne 0 ] && [ ! -e "$2" ]' _ "$RC" "$STATE_DIR"
|
|
check "daemon lost mid-command: create names the container inspect" lost_refused container faunosteo_trial_db
|
|
new_case lost-create-network; : > "$CASE/stub/fail/daemon-lost-network"; trial create
|
|
check "daemon lost on a network inspect: create refuses, nothing created" lost_refused network faunosteo_trial_net
|
|
new_case lost-create-volume; : > "$CASE/stub/fail/daemon-lost-volume"; trial create
|
|
check "daemon lost on a volume inspect: create refuses, nothing created" lost_refused volume faunosteo_trial_db
|
|
b2_stack lost-stack
|
|
COUNT="$(backup_count)"; : > "$CASE/stub/fail/daemon-lost"
|
|
fresh_log; trial_tty faunosteo_trial destroy
|
|
check "daemon lost mid-command: destroy refuses, nothing removed, state files and backups kept" bash -c '[ -f "$1/secrets.env" ] && [ "$2" -eq "$3" ]' _ "$STATE_DIR" "$COUNT" "$(backup_count)"
|
|
check "daemon lost mid-command: destroy names the inspect that failed" lost_refused container faunosteo_trial_db
|
|
fresh_log; trial_tty "restore $RN" restore "$RN"
|
|
check "daemon lost mid-command: restore refuses, nothing removed, no backup taken" bash -c '[ -f "$1/secrets.env" ] && [ "$2" -eq "$3" ]' _ "$STATE_DIR" "$COUNT" "$(backup_count)"
|
|
check "daemon lost mid-command: restore names the inspect that failed (the recorded image, read first)" lost_refused image public.ecr.aws/supabase/postgres:17.11.0.004
|
|
rm -f "$CASE/stub/fail/daemon-lost"
|
|
|
|
# 2: container_running is tri-state; backup proves the stack stopped.
|
|
new_case stop-inspect; trial create
|
|
: > "$CASE/stub/fail/inspect-after-stop"; fresh_log; trial backup
|
|
check "backup: an inspect failing during the stop is refused, never read as stopped, no complete folder" bash -c '[ "$1" -ne 0 ] && grep -qF "failed (exit 1)" "$2" && ! ls "$3"/backups/*/SHA256SUMS >/dev/null 2>&1' _ "$RC" "$CASE/out" "$STATE_DIR"
|
|
new_case stop-noop; trial create
|
|
: > "$CASE/stub/fail/stop-noop"; COUNT="$(backup_count)"; fresh_log; trial backup
|
|
check "backup: a container still running after the stop is refused, nothing archived, no folder kept" bash -c '[ "$1" -ne 0 ] && grep -qF "still runs after the stop" "$2" && ! grep -qF "stays stopped" "$2" && ! grep -qF -- "--entrypoint tar" "$3" && [ "$4" -eq "$5" ]' _ "$RC" "$CASE/out" "$CASE/log" "$COUNT" "$(backup_count)"
|
|
|
|
# 3: docker volume create succeeds on an existing name.
|
|
b2_stack nonempty-volume
|
|
echo lost+found > "$CASE/stub/answers/volume-ls"
|
|
fresh_log; trial_tty "restore $RN" restore "$RN"
|
|
check "restore: a volume not empty once created is refused, nothing extracted, the pre-restore backup named" bash -c '[ "$1" -ne 0 ] && grep -qF "is not empty after its creation" "$2" && grep -qE "pnpm db:trial restore [0-9]{8}T[0-9]{6}Z-pre-restore" "$2" && ! grep -qF "docker run --rm -i" "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
check "restore: the emptiness is read by the helper, read-only, no network" log_has 'docker run --rm --name faunosteo_trial_helper --network none -v faunosteo_trial_db:/volume:ro --entrypoint sh public.ecr.aws/supabase/postgres:17.11.0.004 -c ls -A /volume'
|
|
|
|
# 6: backup and migrate stop the stack, so they refuse while the app runs.
|
|
new_case app-stop; trial create
|
|
printf -- '-- harness\n' > "$WORK/repo/supabase/migrations/29991231000003_harness_app.sql"
|
|
if hold_port 5194; then
|
|
fresh_log; trial backup
|
|
check "backup while port 5194 is in use (the app): refused, nothing stopped" refused "5194 is in use"
|
|
fresh_log; trial migrate
|
|
check "migrate while port 5194 is in use (the app): refused, nothing stopped, no backup" bash -c 'grep -qF "5194 is in use" "$1" && ! grep -qF faunosteo_trial_helper "$2"' _ "$CASE/out" "$CASE/log"
|
|
check "migrate while port 5194 is in use: no stop, no migration" refused "5194 is in use"
|
|
release_port
|
|
else fail "could not hold 127.0.0.1:5194 for the backup and migrate cases"; fi
|
|
rm -f "$WORK/repo/supabase/migrations/29991231000003_harness_app.sql"
|
|
|
|
# 7: the app host is checked before the first change.
|
|
refused_keeping_backups() { refused "$1" && [ "$COUNT" -eq "$(backup_count)" ]; }
|
|
b2_stack host-precheck
|
|
COUNT="$(backup_count)"; EXTRA=(FAUNOSTEO_TRIAL_HOST=8.8.8.8)
|
|
fresh_log; trial_tty "restore $RN" restore "$RN"
|
|
check "restore with no usable app host: refused before the confirmation, no backup, nothing changed" bash -c '! grep -qF "to go on" "$1"' _ "$CASE/out"
|
|
check "restore with no usable app host: refused on the host" refused_keeping_backups "must be loopback or a private address"
|
|
fresh_log; trial rotate-secrets
|
|
check "rotate-secrets with no usable app host: refused before any backup, nothing changed" refused_keeping_backups "must be loopback or a private address"
|
|
EXTRA=()
|
|
|
|
# 9: an address with no account is told as such on the role path too.
|
|
new_case no-account-grant; trial create
|
|
echo no_account > "$CASE/stub/answers/grant-factor-count"
|
|
for role in owner admin; do
|
|
fresh_stdin; fresh_log; trial_tty "grant $role" grant ghost@trial.test "$role"
|
|
check "grant $role for an address with no account: refused with the account hint, nothing granted" bash -c '[ "$1" -ne 0 ] && grep -qF "no account ghost@trial.test (pnpm db:trial account ghost@trial.test first): nothing was granted" "$2" && ! grep -qF "verified TOTP factor(s)" "$2"' _ "$RC" "$CASE/out"
|
|
check "grant $role for an address with no account: no role SQL ran" no_role_assigned
|
|
done
|
|
check "grant: the factor count answers no_account from SQL, the email through -v" bash -c 'grep -qF "no_account" "$1" && grep -qF -- "-v email=ghost@trial.test" "$2"' _ "$(stdin_of grant-factor-count)" "$CASE/log"
|
|
|
|
echo "-- closure re-review fixes (2026-11-11)"
|
|
# C1/C3: a failing inspect writes a bare newline to stdout and the sentence to stderr (Docker 29.9.3).
|
|
stub_inspect() { # kind name → stdout bytes, then stderr, of the stub's failing inspect
|
|
STUB_STATE="$CASE/stub" STUB_LOG="$CASE/log" "$WORK/bin/docker" "$1" inspect -f '{{.Id}}' "$2" 2>"$CASE/err" | od -An -c | tr -d ' '
|
|
}
|
|
stub_streams_split() {
|
|
local kind
|
|
for kind in container volume network image; do
|
|
[ "$(stub_inspect "$kind" x1)" = '\n' ] || return 1
|
|
[ -s "$CASE/err" ] && [ "$(wc -l < "$CASE/err")" -eq 1 ] || return 1
|
|
done
|
|
}
|
|
new_case streams; trial plan; : > "$CASE/stub/fail/image"
|
|
check "the stub's absent answers: a bare newline on stdout, one sentence on stderr, for all four kinds" stub_streams_split
|
|
: > "$CASE/stub/fail/daemon-lost"
|
|
check "the stub's daemon-lost answers split the streams the same way, image included" bash -c '[ "$1" = "\n" ] && [ "$2" = "\n" ]' _ "$(stub_inspect image x1)" "$(stub_inspect container x1)"
|
|
new_case absent-plan; trial plan
|
|
check "plan: stub-absent resources read as absent, nothing already exists" bash -c '[ "$1" -eq 0 ] && grep -qF "create would proceed" "$2" && ! grep -qF "already exists" "$2"' _ "$RC" "$CASE/out"
|
|
new_case absent-flow; trial create
|
|
check "create: the preflight reads every stub-absent resource as absent and goes on" [ "$RC" -eq 0 ]
|
|
fresh_log; trial backup
|
|
check "backup: the helper check reads the absent helper container as absent and goes on" bash -c '[ "$1" -eq 0 ] && ls "$2"/backups/*/SHA256SUMS >/dev/null 2>&1' _ "$RC" "$STATE_DIR"
|
|
fresh_log; trial status
|
|
check "status: reads absent resources as absent, no refusal" bash -c '[ "$1" -eq 0 ] && ! grep -qF "refused" "$2"' _ "$RC" "$CASE/out"
|
|
new_case absent-status; trial status
|
|
check "status without a stack: stub-absent resources, none listed, no refusal" bash -c '[ "$1" -eq 0 ] && ! grep -qF "present anyway" "$2" && ! grep -qF "refused" "$2"' _ "$RC" "$CASE/out"
|
|
|
|
# C2: a lost daemon is not "image not present locally".
|
|
b2_stack lost-restore
|
|
COUNT="$(backup_count)"; : > "$CASE/stub/fail/daemon-lost"
|
|
fresh_log; trial_tty "restore $RN" restore "$RN"
|
|
check "restore with the daemon lost: refused on the image inspect, never 'docker pull', nothing removed" bash -c '[ "$1" -ne 0 ] && grep -qF "cannot tell whether its images are present" "$2" && grep -qF "docker image inspect" "$2" && ! grep -qF "docker pull" "$2" && ! grep -qF "not present locally" "$2" && [ "$3" -eq "$4" ]' _ "$RC" "$CASE/out" "$COUNT" "$(backup_count)"
|
|
check "restore with the daemon lost: no change at all" [ -z "$(changes)" ]
|
|
|
|
# M6: the create trap ends with its hint when its listing fails.
|
|
new_case lost-after-create; : > "$CASE/stub/fail/daemon-lost-after-create"; trial create
|
|
check "create with the daemon lost after the first resource: the trap runs, nothing removed, state files kept, the hint printed" bash -c '[ "$1" -ne 0 ] && grep -qF "nothing was removed" "$2" && grep -qF "the listing failed" "$2" && grep -qF "inspect the faunosteo_trial resources by hand" "$2" && grep -qF "pnpm db:trial status shows the state" "$2" && [ -f "$3/secrets.env" ] && [ -f "$3/stack.conf" ] && ! grep -qE "^docker (rm|volume rm|network rm) " "$4"' _ "$RC" "$CASE/out" "$STATE_DIR" "$CASE/log"
|
|
|
|
# M7: start checks the app host before it starts or recreates anything.
|
|
new_case start-host; trial create; trial stop
|
|
rm -f "$CASE/stub/containers/faunosteo_trial_rest" "$CASE/stub/ports/faunosteo_trial_rest"
|
|
EXTRA=(FAUNOSTEO_TRIAL_HOST=8.8.8.8); fresh_log; trial start
|
|
check "start with no usable app host: refused before any container is started or recreated" refused "must be loopback or a private address"
|
|
EXTRA=()
|
|
|
|
|
|
echo "-- closure second re-review fixes (2026-11-11)"
|
|
# m4: a plan without a daemon does not call the images "not pulled yet".
|
|
new_case plan-down-images; : > "$CASE/stub/fail/daemon"; trial plan
|
|
check "plan with the daemon down: each of the six images is unknown, none 'not pulled yet'" bash -c '[ "$(grep -cF "unknown (Docker daemon unreachable)" "$1")" -eq 6 ] && ! grep -qF "not pulled yet" "$1"' _ "$CASE/out"
|
|
|
|
# m6/m3: a refused inspect shows Docker's answer, quoted, and both hints.
|
|
new_case inspect-shown; : > "$CASE/stub/fail/inspect-error"; trial create
|
|
check "an inspect error: the quoted Docker answer, the docker info hint and the wording hint" bash -c '[ "$1" -ne 0 ] && grep -qF "(answer '"'"'Error response from daemon: permission denied'"'"')" "$2" && grep -qF "(docker info)" "$2" && grep -qF "measured on Docker 29.9.3" "$2"' _ "$RC" "$CASE/out"
|
|
|
|
# m6/m10: the destroy way out when the listing fails, and when a container still runs.
|
|
new_case way-listing; trial create
|
|
: > "$CASE/stub/fail/archive"; : > "$CASE/stub/fail/lost-after-archive"
|
|
fresh_log; trial_tty faunosteo_trial destroy
|
|
check "destroy way out with the daemon lost after the failed archive: each kind prints its listing-failed line" bash -c '[ "$1" -ne 0 ] && for k in container network volume; do grep -qF "($k listing failed, Docker did not answer: inspect the faunosteo_trial ${k}s by hand)" "$2" || exit 1; done' _ "$RC" "$CASE/out"
|
|
new_case way-still-runs; trial create
|
|
: > "$CASE/stub/fail/stop-noop"; fresh_log; trial_tty faunosteo_trial destroy
|
|
check "destroy whose backup fails on a container that still runs: docker stop named before docker rm" bash -c '[ "$1" -ne 0 ] && grep -qF "still runs after the stop" "$2" && s=$(grep -nF " docker stop faunosteo_trial_db" "$2" | head -n 1 | cut -d: -f1) && r=$(grep -nF " docker rm faunosteo_trial_db" "$2" | head -n 1 | cut -d: -f1) && [ -n "$s" ] && [ -n "$r" ] && [ "$s" -lt "$r" ]' _ "$RC" "$CASE/out"
|
|
check "destroy whose backup fails on a container that still runs: nothing removed" no_removal
|
|
new_case way-stopped; trial create
|
|
echo 999999999999 > "$CASE/stub/answers/measure-kib"; fresh_log; trial_tty faunosteo_trial destroy
|
|
check "destroy way out with every container stopped: no docker stop line" bash -c '[ "$1" -ne 0 ] && grep -qF "no backup could be made" "$2" && ! grep -qF "docker stop faunosteo" "$2"' _ "$RC" "$CASE/out"
|
|
|
|
# m5: GoTrue's recreation reads the app host; backup's restart refuses before the first start.
|
|
new_case restart-host; trial create
|
|
rm -f "$CASE/stub/containers/faunosteo_trial_auth" "$CASE/stub/ports/faunosteo_trial_auth"
|
|
EXTRA=(FAUNOSTEO_TRIAL_HOST=8.8.8.8); fresh_log; trial backup
|
|
check "backup with GoTrue missing and no usable app host: the restart refuses before any container starts" bash -c '[ "$1" -ne 0 ] && grep -qF "must be loopback or a private address" "$2" && ! grep -qE "^docker (start|run -d|restart) " "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
|
EXTRA=()
|
|
|
|
# m9: a restore whose second volume fails says the first was extracted.
|
|
b2_stack restore-second
|
|
echo lost+found > "$CASE/stub/answers/volume-ls-storage"
|
|
fresh_log; trial_tty "restore $RN" restore "$RN"
|
|
check "restore: the storage volume not empty after the database volume was extracted says so" bash -c '[ "$1" -ne 0 ] && grep -qF "faunosteo_trial_storage is not empty after its creation: faunosteo_trial_db was extracted, faunosteo_trial_storage was not" "$2" && ! grep -qF "nothing was extracted" "$2"' _ "$RC" "$CASE/out"
|
|
|
|
|
|
echo "-- db:sandbox state guard"
|
|
new_case sandbox-guard; mkdir -p "$CASE/trialstate"; : > "$CASE/trialstate/.faunosteo-trial-state"
|
|
EXTRA=(FAUNOSTEO_SANDBOX_DIR="$CASE/trialstate"); sandbox down
|
|
check "db:sandbox down refuses a folder holding the trial marker, nothing run" refused_early "db:trial state folder"
|
|
EXTRA=(FAUNOSTEO_SANDBOX_DIR="$CASE/same" FAUNOSTEO_TRIAL_DIR="$CASE/same"); sandbox down
|
|
check "db:sandbox down refuses the db:trial state folder by path" refused_early "db:trial state folder"
|
|
fresh_log; EXTRA=(FAUNOSTEO_SANDBOX_DIR="$CASE/sandbox-state"); sandbox down
|
|
check "db:sandbox down on its own folder names faunosteo_dbsandbox_ resources only" bash -c '[ "$1" -eq 0 ] && grep -q "^docker rm -f faunosteo_dbsandbox_" "$2" && ! grep -oE "faunosteo_[a-z_]+" "$2" | grep -qv "^faunosteo_dbsandbox_"' _ "$RC" "$CASE/log"
|
|
|
|
echo "-- $PASS passed, $FAIL failed"
|
|
if [ "$FAIL" -eq 0 ] && [ "$PASS" -gt 0 ]; then echo "db-trial-check: ALL PASS"; else exit 1; fi
|