test(ui): avoid a literal em dash in the em dash check

- test(ui): avoid a literal em dash in the em dash check
- fix(cli): accept any positive int64 audit count and share the last active admin rule
- fix(api): limit audit before_id to 2^53-1
- fix(api): audit unmatched api requests, bound every request body and record audit write failures
- fix(ui): recheck the account in the login transaction and require existing zones on zone pages
- fix(api): recheck the acting admin and the stored password hash in change transactions
- fix(db): keep committed outcomes on lock release failure, narrow the records contract and trace sql statements
- fix(db): make the initial migration restartable and verify the application schema
- fix(auth): never move last_seen_at backwards on concurrent session touches
- test(api): cover lock release failure after commit and handler tracing without secrets
- fix(test): redact credentials from mysql setup errors
- fix(audit): retain addressed objects on admin refusals
- test(db): cover migration restarts and records contract ranges in mysql
- test(api): verify account races and audit rollback in mysql
- fix(auth): reject password changes after account deletion
- docs: document unknown api audit entries
- fix(audit): bound failure retries and redact sensitive sql parameters
- fix(test): isolate docker resources and cover image cli commands
- test(auth): expect unauthorized after an account deletion race
- fix(db): verify application column widths and foreign keys
This commit is contained in:
bryanpedini committed 2026-11-19 15:46:12 +01:00
1 parent 5f17aab6ca
commit 53444bec7a
40 files changed
+2332 -254

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2026 Bryan Joshua Pedini
require_free_docker_name() {
if docker "$1" inspect "$2" >/dev/null 2>&1; then
echo "docker $1 already exists: $2" >&2
exit 1
fi
}
+54 -16
View File
@@ -4,35 +4,72 @@
set -eu
cd "$(dirname "$0")/.."
. ./scripts/docker-test-lib.sh
IT_ID=${IT_ID:-$$}
IT_NAME=${IT_NAME:-cdwu-it-${IT_ID}}
MYSQL_IMAGE=${MYSQL_IMAGE:-mysql:8.4}
network="${IT_NAME}"
network="$IT_NAME"
mysql="${IT_NAME}-mysql"
mysql_data="${IT_NAME}-data"
tests="${IT_NAME}-tests"
image="${IT_NAME}:integration"
root_password=$(od -An -tx1 -N16 /dev/urandom | tr -d ' \n')
require_free_docker_name network "$network"
require_free_docker_name container "$mysql"
require_free_docker_name volume "$mysql_data"
require_free_docker_name container "$tests"
require_free_docker_name image "$image"
network_id=
mysql_id=
tests_id=
volume=
tmp=$(mktemp -d)
owner=${tmp##*/}
owns_volume() {
[ "$(docker volume inspect --format '{{index .Labels "cdwu.test.owner"}}' "$1")" = "$owner" ]
}
cleanup() {
status=$?
if [ "$status" -ne 0 ]; then
docker logs --tail 80 "$mysql" >&2 2>&1 || true
if [ "$status" -ne 0 ] && [ -n "$mysql_id" ]; then
docker logs --tail 80 "$mysql_id" >&2 2>&1 || true
fi
docker rm --force --volumes "$tests" "$mysql" >/dev/null 2>&1 || true
docker volume rm "$mysql_data" >/dev/null 2>&1 || true
docker network rm "$network" >/dev/null 2>&1 || true
docker image rm --force "$image" >/dev/null 2>&1 || true
for container in "$tests_id" "$mysql_id"; do
if [ -n "$container" ]; then
docker rm --force --volumes "$container" >/dev/null 2>&1 || true
fi
done
if [ -n "$volume" ] && owns_volume "$volume" 2>/dev/null; then
docker volume rm "$volume" >/dev/null 2>&1 || true
fi
if [ -n "$network_id" ]; then
docker network rm "$network_id" >/dev/null 2>&1 || true
fi
if [ -s "$tmp/image-id" ] &&
[ "$(docker image inspect --format '{{.Id}}' "$image" 2>/dev/null)" = "$(cat "$tmp/image-id")" ]; then
docker image rm "$image" >/dev/null 2>&1 || true
fi
rm -rf "$tmp"
exit "$status"
}
trap cleanup EXIT
trap 'exit 130' INT TERM
docker build --target integration --file dockerfile --tag "$image" .
docker network create --internal "$network" >/dev/null
docker run --detach --name "$mysql" --network "$network" --network-alias mysql \
--volume "$mysql_data:/var/lib/mysql" \
--env MYSQL_ROOT_PASSWORD="$root_password" "$MYSQL_IMAGE" >/dev/null
root_password=$(od -An -tx1 -N16 /dev/urandom | tr -d ' \n')
volume=$(docker volume create --label "cdwu.test.owner=$owner" "$mysql_data")
if ! owns_volume "$volume"; then
echo "docker volume already exists: $mysql_data" >&2
exit 1
fi
network_id=$(docker network create --internal "$network")
require_free_docker_name image "$image"
docker build --target integration --file dockerfile --tag "$image" --iidfile "$tmp/image-id" .
mysql_id=$(docker create --name "$mysql" --network "$network_id" --network-alias mysql \
--volume "$volume:/var/lib/mysql" \
--env MYSQL_ROOT_PASSWORD="$root_password" "$MYSQL_IMAGE")
docker start "$mysql_id" >/dev/null
attempt=0
until docker exec --env MYSQL_PWD="$root_password" "$mysql" mysqladmin ping --host=127.0.0.1 --user=root --silent >/dev/null 2>&1; do
until docker exec --env MYSQL_PWD="$root_password" "$mysql_id" mysql --host=127.0.0.1 --user=root --execute 'SELECT 1' >/dev/null 2>&1; do
attempt=$((attempt + 1))
if [ "$attempt" -ge 120 ]; then
echo "mysql did not become ready" >&2
@@ -40,6 +77,7 @@ until docker exec --env MYSQL_PWD="$root_password" "$mysql" mysqladmin ping --ho
fi
sleep 1
done
docker run --name "$tests" --network "$network" \
tests_id=$(docker create --name "$tests" --network "$network_id" \
--env IT_MYSQL_HOST=mysql --env IT_MYSQL_PORT=3306 --env IT_MYSQL_ROOT_PASSWORD="$root_password" \
"$image"
"$(cat "$tmp/image-id")")
docker start --attach "$tests_id"
+102 -45
View File
@@ -8,6 +8,7 @@ if [ "$#" -ne 3 ]; then
exit 2
fi
cd "$(dirname "$0")/.."
. ./scripts/docker-test-lib.sh
image=$1
version=$2
commit=$3
@@ -18,24 +19,43 @@ network="$name"
mysql="${name}-mysql"
server="${name}-app"
exported="${name}-export"
probe_name="${name}-probe"
require_free_docker_name network "$network"
for container in "$mysql" "$server" "$exported" "$probe_name"; do
require_free_docker_name container "$container"
done
network_id=
mysql_id=
server_id=
exported_id=
probe_id=
tmp=$(mktemp -d)
root_password=$(od -An -tx1 -N16 /dev/urandom | tr -d ' \n')
db_password=coredns_webui_dev
pw_admin="pw$(od -An -tx1 -N12 /dev/urandom | tr -d ' \n')"
pw_user="pw$(od -An -tx1 -N12 /dev/urandom | tr -d ' \n')"
pw_reset="pw$(od -An -tx1 -N12 /dev/urandom | tr -d ' \n')"
pw_short="pw$(od -An -tx1 -N4 /dev/urandom | tr -d ' \n')"
rc=0
cleanup() {
status=$?
if [ "$status" -ne 0 ]; then
for container in "$server" "$mysql"; do
if docker inspect "$container" >/dev/null 2>&1; then
for container in "$server_id" "$mysql_id"; do
if [ -n "$container" ]; then
docker logs --tail 40 "$container" >&2 2>&1 || true
fi
done
fi
docker rm --force --volumes "$server" "$mysql" "$exported" "${name}-probe" >/dev/null 2>&1 || true
docker network rm "$network" >/dev/null 2>&1 || true
for container in "$server_id" "$mysql_id" "$exported_id" "$probe_id"; do
if [ -n "$container" ]; then
docker rm --force --volumes "$container" >/dev/null 2>&1 || true
fi
done
if [ -n "$network_id" ]; then
docker network rm "$network_id" >/dev/null 2>&1 || true
fi
rm -rf "$tmp"
exit "$status"
}
@@ -63,8 +83,15 @@ capture() {
"$@" >"$tmp/out" 2>"$tmp/err" && rc=0 || rc=$?
}
capture_probe() {
probe_id=$(docker create --name "$probe_name" "$@") || fail "could not create probe"
capture docker start --attach "$probe_id"
docker rm --force --volumes "$probe_id" >/dev/null
probe_id=
}
scan() {
if grep -qF -e "$pw_admin" -e "$pw_user" -e "$pw_short" -e "$db_password" -e "$root_password" "$@"; then
if grep -qF -e "$pw_admin" -e "$pw_user" -e "$pw_reset" -e "$pw_short" -e "$db_password" -e "$root_password" "$@"; then
fail "a secret appears in the output"
fi
}
@@ -72,12 +99,12 @@ scan() {
cli() {
input=$1
shift
printf '%s\n' "$input" | docker exec -i "$server" /app "$@" >"$tmp/out" 2>"$tmp/err" && rc=0 || rc=$?
printf '%s\n' "$input" | docker exec -i "$server_id" /app "$@" >"$tmp/out" 2>"$tmp/err" && rc=0 || rc=$?
scan "$tmp/out" "$tmp/err"
}
sql() {
docker exec --env MYSQL_PWD="$root_password" "$mysql" mysql --user=root --batch --skip-column-names --execute "$1"
docker exec --env MYSQL_PWD="$root_password" "$mysql_id" mysql --user=root --batch --skip-column-names --execute "$1"
}
usage_text() {
@@ -113,11 +140,12 @@ ok "OCI labels"
[ "$(docker image inspect --format '{{json .Config.Healthcheck.Test}}' "$image")" = '["CMD","/app","healthcheck"]' ] || fail "image healthcheck is not /app healthcheck"
ok "image user, entrypoint and healthcheck"
capture docker run --rm --name "${name}-probe" --entrypoint /bin/sh "$image" -c true
capture_probe --entrypoint /bin/sh "$image" -c true
[ "$rc" -ne 0 ] || fail "the image runs /bin/sh"
docker create --name "$exported" "$image" >/dev/null
docker export "$exported" | tar -t >"$tmp/files"
docker rm --force "$exported" >/dev/null
exported_id=$(docker create --name "$exported" "$image")
docker export "$exported_id" | tar -t >"$tmp/files"
docker rm --force --volumes "$exported_id" >/dev/null
exported_id=
while IFS= read -r entry; do
case ${entry%/} in
app | etc | etc/ssl | etc/ssl/cert.pem | etc/hostname | etc/hosts | etc/resolv.conf | etc/mtab) ;;
@@ -129,41 +157,45 @@ grep -qx 'app' "$tmp/files" || fail "/app missing from the image filesystem"
grep -qx 'etc/ssl/cert.pem' "$tmp/files" || fail "CA bundle missing from the image filesystem"
ok "image filesystem has no shell"
capture docker run --rm --name "${name}-probe" "$image"
capture_probe "$image"
expect_rc "start without configuration" 2
ok "exit 2 without configuration"
capture docker run --rm --name "${name}-probe" "$image" version
capture_probe "$image" version
expect_rc "version" 0
[ "$(cat "$tmp/out")" = "coredns-web-ui $version $commit" ] || fail "version output is not 'coredns-web-ui $version $commit'"
ok "version output"
capture docker run --rm --name "${name}-probe" "$image" help
capture_probe "$image" help
expect_rc "help" 0
cmp -s "$tmp/out" "$tmp/usage" || fail "help output differs from the usage text"
[ ! -s "$tmp/err" ] || fail "help wrote to stderr"
ok "help output"
for args in "bogus" "help extra"; do
capture docker run --rm --name "${name}-probe" "$image" $args
expect_rc "usage error ($args)" 2
[ ! -s "$tmp/out" ] || fail "usage error ($args) wrote to stdout"
head -n 1 "$tmp/err" | grep -q '^coredns-web-ui: usage error: ' || fail "usage error ($args) message has no usage error prefix"
tail -n +2 "$tmp/err" | cmp -s - "$tmp/usage" || fail "usage error ($args) does not end with the usage text"
for cmd in bogus help; do
set -- "$cmd"
if [ "$cmd" = help ]; then
set -- "$@" extra
fi
capture_probe "$image" "$@"
expect_rc "usage error ($*)" 2
[ ! -s "$tmp/out" ] || fail "usage error ($*) wrote to stdout"
head -n 1 "$tmp/err" | grep -q '^coredns-web-ui: usage error: ' || fail "usage error ($*) message has no usage error prefix"
tail -n +2 "$tmp/err" | cmp -s - "$tmp/usage" || fail "usage error ($*) does not end with the usage text"
done
ok "usage errors exit 2 with the usage text on stderr"
capture docker run --rm --name "${name}-probe" "$image" healthcheck
capture_probe "$image" healthcheck
expect_rc "healthcheck without a server" 1
ok "healthcheck fails without a server"
docker network create --internal "$network" >/dev/null
docker create --name "$mysql" --network "$network" --network-alias mysql --tmpfs /var/lib/mysql \
--env MYSQL_ROOT_PASSWORD="$root_password" "$mysql_image" >/dev/null
docker cp dev/mysql-init.sql "$mysql:/docker-entrypoint-initdb.d/mysql-init.sql"
docker start "$mysql" >/dev/null
network_id=$(docker network create --internal "$network")
mysql_id=$(docker create --name "$mysql" --network "$network_id" --network-alias mysql --tmpfs /var/lib/mysql \
--env MYSQL_ROOT_PASSWORD="$root_password" "$mysql_image")
docker cp dev/mysql-init.sql "$mysql_id:/docker-entrypoint-initdb.d/mysql-init.sql"
docker start "$mysql_id" >/dev/null
attempt=0
until docker exec --env MYSQL_PWD="$root_password" "$mysql" mysqladmin ping --host=127.0.0.1 --user=root --silent >/dev/null 2>&1; do
until docker exec --env MYSQL_PWD="$root_password" "$mysql_id" mysql --host=127.0.0.1 --user=root --execute 'SELECT 1' >/dev/null 2>&1; do
attempt=$((attempt + 1))
[ "$attempt" -lt 120 ] || fail "mysql did not become ready"
sleep 1
@@ -171,13 +203,14 @@ done
[ "$(sql 'SELECT COUNT(*) FROM coredns.coredns_records')" = 0 ] || fail "records table is not initialized"
ok "mysql ready"
docker run --detach --name "$server" --network "$network" --network-alias app \
server_id=$(docker create --name "$server" --network "$network_id" --network-alias app \
--health-interval 2s --health-timeout 5s --health-start-period 2s --health-retries 5 \
--env DB_HOST=mysql --env DB_USER=coredns_webui --env DB_PASSWORD="$db_password" --env DB_NAME=coredns \
--env COOKIE_SECURE=false --env LOG_LEVEL=TRACE "$image" >/dev/null
--env COOKIE_SECURE=false --env LOG_LEVEL=TRACE "$image")
docker start "$server_id" >/dev/null
attempt=0
while :; do
state=$(docker inspect --format '{{.State.Status}} {{if .State.Health}}{{.State.Health.Status}}{{end}}' "$server")
state=$(docker inspect --format '{{.State.Status}} {{if .State.Health}}{{.State.Health.Status}}{{end}}' "$server_id")
[ "$state" != "running healthy" ] || break
case $state in
running*) ;;
@@ -189,25 +222,36 @@ while :; do
done
ok "container healthy through its HEALTHCHECK"
[ "$(docker inspect --format '{{.Config.User}}' "$server")" = "65532:65532" ] || fail "the container does not run as 65532:65532"
[ "$(docker inspect --format '{{.Config.User}}' "$server_id")" = "65532:65532" ] || fail "the container does not run as 65532:65532"
ok "container runs as 65532:65532"
capture docker exec "$server" /bin/sh -c true
capture docker exec "$server_id" /bin/sh -c true
[ "$rc" -ne 0 ] || fail "docker exec /bin/sh succeeded"
ok "docker exec /bin/sh fails"
capture docker exec "$server" /app healthcheck
capture docker exec "$server_id" /app healthcheck
expect_rc "docker exec healthcheck" 0
ok "docker exec healthcheck"
health=$(docker run --rm --name "${name}-probe" --network "$network" "$probe" wget -qO- http://app:8080/health) || fail "GET /health failed"
[ "$health" = '{"status":"ok"}' ] || fail "unexpected /health body: $health"
page=$(docker run --rm --name "${name}-probe" --network "$network" "$probe" wget -qO- http://app:8080/version) || fail "GET /version failed"
printf '%s' "$page" | grep -qF "$version" || fail "/version does not render the version"
printf '%s' "$page" | grep -qF "$commit" || fail "/version does not render the commit"
capture docker exec "$server_id" /app version
expect_rc "docker exec version" 0
[ "$(cat "$tmp/out")" = "coredns-web-ui $version $commit" ] || fail "docker exec version returned unexpected output"
capture docker exec "$server_id" /app help
expect_rc "docker exec help" 0
cmp -s "$tmp/out" "$tmp/usage" || fail "docker exec help differs from the usage text"
[ ! -s "$tmp/err" ] || fail "docker exec help wrote to stderr"
ok "docker exec version and help"
capture_probe --network "$network_id" "$probe" wget -qO- http://app:8080/health
expect_rc "GET /health" 0
[ "$(cat "$tmp/out")" = '{"status":"ok"}' ] || fail "unexpected /health body"
capture_probe --network "$network_id" "$probe" wget -qO- http://app:8080/version
expect_rc "GET /version" 0
grep -qF "$version" "$tmp/out" || fail "/version does not render the version"
grep -qF "$commit" "$tmp/out" || fail "/version does not render the commit"
ok "/health and /version"
docker logs "$server" >"$tmp/startup.log" 2>&1
docker logs "$server_id" >"$tmp/startup.log" 2>&1
grep -qF "$commit" "$tmp/startup.log" || fail "commit $commit not in the startup log"
grep -qF "$version" "$tmp/startup.log" || fail "version $version not in the startup log"
ok "version and commit in the startup log"
@@ -225,6 +269,19 @@ expect_rc "user add user" 0
[ "$(sql "SELECT COUNT(*) FROM coredns.coredns_webui_users WHERE password_hash LIKE '\$argon2id\$%' AND deleted_at IS NULL")" = 2 ] || fail "passwords are not stored as argon2id hashes"
ok "user add with both roles"
hash_query="SELECT SHA2(password_hash, 256) FROM coredns.coredns_webui_users WHERE username = 'imguser'"
old_hash=$(sql "$hash_query")
sql "INSERT INTO coredns.coredns_webui_sessions (token_hash, user_id, created_at, last_seen_at, expires_at, origin, user_agent)
SELECT UNHEX(REPEAT('11', 32)), id, UTC_TIMESTAMP(6), UTC_TIMESTAMP(6),
UTC_TIMESTAMP(6) + INTERVAL 1 HOUR, '192.0.2.1', 'image test'
FROM coredns.coredns_webui_users WHERE username = 'imguser'"
cli "$pw_reset" user passwd imguser
expect_rc "user passwd" 0
new_hash=$(sql "$hash_query")
[ -n "$new_hash" ] && [ "$old_hash" != "$new_hash" ] || fail "user passwd did not replace the stored hash"
[ "$(sql 'SELECT COUNT(*) FROM coredns.coredns_webui_sessions')" = 0 ] || fail "user passwd did not revoke the session"
ok "user passwd changes the hash and revokes sessions"
cli "" user list
expect_rc "user list" 0
grep -q '^imgadmin ' "$tmp/out" || fail "user list does not show imgadmin"
@@ -260,20 +317,20 @@ cli "$pw_user" user add imguser user
[ "$(sql "SELECT COUNT(*) FROM coredns.coredns_webui_users WHERE username = 'imguser'")" = 1 ] || fail "user add changed the row of a deleted user"
ok "the username of a deleted user cannot be reused"
[ "$(sql "SELECT GROUP_CONCAT(operation ORDER BY id) FROM coredns.coredns_webui_audit")" = "user_create,user_create,user_role,user_role,user_delete" ] || fail "unexpected audit rows for the CLI changes"
[ "$(sql "SELECT COUNT(*) FROM coredns.coredns_webui_audit WHERE actor = 'cli' AND origin = 'local'")" = 5 ] || fail "CLI audit rows do not have actor cli and origin local"
[ "$(sql "SELECT GROUP_CONCAT(operation ORDER BY id) FROM coredns.coredns_webui_audit")" = "user_create,user_create,user_password,user_role,user_role,user_delete" ] || fail "unexpected audit rows for the CLI changes"
[ "$(sql "SELECT COUNT(*) FROM coredns.coredns_webui_audit WHERE actor = 'cli' AND origin = 'local'")" = 6 ] || fail "CLI audit rows do not have actor cli and origin local"
ok "CLI changes are audited"
docker logs "$server" >"$tmp/server.log" 2>&1
docker logs "$server_id" >"$tmp/server.log" 2>&1
scan "$tmp/server.log"
ok "no secret in the container logs"
started=$(date +%s)
docker stop --time 40 "$server" >/dev/null
docker stop --time 40 "$server_id" >/dev/null
elapsed=$(($(date +%s) - started))
[ "$(docker inspect --format '{{.State.ExitCode}}' "$server")" = 0 ] || fail "SIGTERM did not stop the container with exit code 0"
[ "$(docker inspect --format '{{.State.ExitCode}}' "$server_id")" = 0 ] || fail "SIGTERM did not stop the container with exit code 0"
[ "$elapsed" -lt 25 ] || fail "SIGTERM took ${elapsed}s, longer than the 25s grace period"
docker logs "$server" >"$tmp/server.log" 2>&1
docker logs "$server_id" >"$tmp/server.log" 2>&1
scan "$tmp/server.log"
ok "SIGTERM stops the container with exit 0 in ${elapsed}s"