test(supabase): avatar e2e on the sandbox only, per-session seed secret
pnpm e2e:avatar is now an alias of pnpm db:sandbox avatar-e2e and the DEV script scripts/avatar-e2e.sh is removed; the suite fails on any target but the sandbox gateway and database; an occupied port 57800 stops the run before anything starts. The sandbox replaces the seed accounts' DEV password by a per-session secret.
This commit is contained in:
1 parent
26e4b1b0ee
commit
cdd43ac431
16 files changed
+64
-100
No files matched your search
@@ -1,59 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Real-stack end-to-end run of the avatar flow (docs/development/STORAGE.md §6):
|
||||
# starts the worker container against the local Supabase stack with a fast sweep
|
||||
# and no quarantine grace, runs packages/supabase/tests/e2e, stops the container.
|
||||
# Needs: `pnpm db:start` done, Docker, the worker image (`pnpm worker:image`,
|
||||
# built here when absent). The keys come from `supabase status`; the service key
|
||||
# reaches the container through a 600-mode temporary env file, never the command line.
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
network="${SUPABASE_NETWORK:-supabase_network_faunosteo}"
|
||||
kong="${SUPABASE_INTERNAL_URL:-http://supabase_kong_faunosteo:8000}"
|
||||
image="${WORKER_IMAGE:-faunosteo_worker:dev}"
|
||||
name="faunosteo_worker_e2e"
|
||||
|
||||
. scripts/dev-env.sh
|
||||
status="$(node_modules/.bin/supabase status -o env 2>/dev/null)" \
|
||||
|| { echo "avatar-e2e: the local stack is not running (pnpm db:start)" >&2; exit 1; }
|
||||
value() { printf '%s\n' "$status" | sed -n "s/^$1=\"\(.*\)\"$/\1/p"; }
|
||||
api_url="$(value API_URL)"
|
||||
anon_key="$(value ANON_KEY)"
|
||||
service_key="$(value SERVICE_ROLE_KEY)"
|
||||
[ -n "$api_url" ] && [ -n "$anon_key" ] && [ -n "$service_key" ] \
|
||||
|| { echo "avatar-e2e: could not read the keys from supabase status" >&2; exit 1; }
|
||||
|
||||
if ! docker image inspect "$image" >/dev/null 2>&1; then
|
||||
echo "== building $image"
|
||||
docker build -f crates/worker/Dockerfile -t "$image" .
|
||||
fi
|
||||
|
||||
env_file="$(mktemp)"
|
||||
chmod 600 "$env_file"
|
||||
cleanup() {
|
||||
echo "== worker log (last lines)"
|
||||
docker logs --tail 40 "$name" 2>/dev/null || true
|
||||
docker rm -f "$name" >/dev/null 2>&1 || true
|
||||
rm -f "$env_file"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
{
|
||||
echo "SUPABASE_URL=$kong"
|
||||
echo "SUPABASE_SERVICE_ROLE_KEY=$service_key"
|
||||
echo "WORKER_ID=e2e"
|
||||
echo "WORKER_POLL_SECONDS=1"
|
||||
echo "WORKER_SWEEP_SECONDS=5"
|
||||
echo "WORKER_QUARANTINE_GRACE_SECONDS=0"
|
||||
} > "$env_file"
|
||||
|
||||
docker rm -f "$name" >/dev/null 2>&1 || true
|
||||
echo "== starting $name on $network"
|
||||
docker run -d --name "$name" --read-only --cap-drop ALL \
|
||||
--security-opt no-new-privileges:true --memory 512m --cpus 1 --pids-limit 64 \
|
||||
--network "$network" --env-file "$env_file" "$image" run >/dev/null
|
||||
|
||||
echo "== e2e suite"
|
||||
SUPABASE_URL="$api_url" SUPABASE_ANON_KEY="$anon_key" SUPABASE_SERVICE_ROLE_KEY="$service_key" \
|
||||
AVATAR_E2E_DB_CONTAINER="${AVATAR_E2E_DB_CONTAINER:-supabase_db_faunosteo}" \
|
||||
pnpm --filter @faunosteo/supabase test:e2e
|
||||
+25
-5
@@ -17,7 +17,7 @@
|
||||
# pnpm db:sandbox verify-e2e [args] the sheet verification worker against the sandbox: an
|
||||
# unpublished gateway, the worker container, then
|
||||
# tests/sandbox/sheet-verification.sandbox.ts (args go to vitest)
|
||||
# pnpm db:sandbox avatar-e2e [args] the avatar worker (default mode: avatars + sweep) against the
|
||||
# pnpm db:sandbox avatar-e2e [args] (= pnpm e2e:avatar) the avatar worker (default mode: avatars + sweep) against the
|
||||
# sandbox: a gateway on 127.0.0.1:$PORT_GATEWAY, the worker
|
||||
# container, then tests/e2e/avatar-flow.e2e.ts (args go to vitest)
|
||||
# pnpm db:sandbox sql psql as postgres on stdin
|
||||
@@ -62,6 +62,7 @@ load_secrets() {
|
||||
[ -f "$SECRETS" ] || die "not running (pnpm db:sandbox up fresh)"
|
||||
. "$SECRETS"
|
||||
[ -n "${SB_PW:-}" ] && [ -n "${SB_JWT_SECRET:-}" ] && [ -n "${SB_ANON_KEY:-}" ] && [ -n "${SB_SERVICE_KEY:-}" ] \
|
||||
&& [ -n "${SB_SEED_PW:-}" ] \
|
||||
|| die "secrets file incomplete (pnpm db:sandbox down, then up)"
|
||||
export PGPASSWORD="$SB_PW"
|
||||
}
|
||||
@@ -87,6 +88,7 @@ new_secrets() {
|
||||
return h + "." + b + "." + c.createHmac("sha256", secret).update(h + "." + b).digest("base64url"); };
|
||||
const exp = Math.floor(Date.now() / 1000) + 30 * 86400;
|
||||
console.log("SB_PW=" + c.randomBytes(24).toString("hex"));
|
||||
console.log("SB_SEED_PW=" + c.randomBytes(24).toString("hex"));
|
||||
console.log("SB_JWT_SECRET=" + secret);
|
||||
console.log("SB_ANON_KEY=" + jwt({ role: "anon", iss: "db-sandbox", exp }));
|
||||
console.log("SB_SERVICE_KEY=" + jwt({ role: "service_role", iss: "db-sandbox", exp }));
|
||||
@@ -189,6 +191,18 @@ gotrue_accounts() {
|
||||
--data-binary @- >/dev/null
|
||||
}
|
||||
|
||||
# The seed gives its accounts the DEV password (supabase/seed.sql); the sandbox
|
||||
# replaces it at once by this session's secret, through GoTrue, body on stdin.
|
||||
seed_passwords() {
|
||||
local id
|
||||
for id in $(sb_psql -t -A -c "select id from auth.users where email like '%@faunosteo.local'"); do
|
||||
[[ "$id" =~ ^[0-9a-f-]{36}$ ]] || die "unexpected seed account id"
|
||||
printf '{"password":"%s"}' "$SB_SEED_PW" \
|
||||
| curl -fsS -X PUT "http://127.0.0.1:$PORT_AUTH/admin/users/$id" \
|
||||
-H @"$STATE/service-header" -H 'Content-Type: application/json' --data-binary @- >/dev/null
|
||||
done
|
||||
}
|
||||
|
||||
# A CLI workdir holding only the migrations before <version>; kept in the
|
||||
# state folder and refilled at each run (the CLI writes .temp there).
|
||||
upgrade_workdir() { # version
|
||||
@@ -218,10 +232,10 @@ cmd_up() {
|
||||
start_services
|
||||
case "$mode" in
|
||||
fresh)
|
||||
migrate_up . ; seed ;;
|
||||
migrate_up . ; seed; seed_passwords ;;
|
||||
upgrade)
|
||||
migrate_up "$(upgrade_workdir "$2")"
|
||||
seed; gotrue_accounts
|
||||
seed; seed_passwords; gotrue_accounts
|
||||
echo "== before: $(sb_psql -t -A -c 'select count(*) from public.profiles') profiles"
|
||||
if [ -n "${3:-}" ]; then
|
||||
migrate_up "$(upgrade_workdir "$3")"
|
||||
@@ -242,7 +256,7 @@ cmd_down() {
|
||||
|
||||
# A test runner gets the endpoints and keys through its environment, never argv.
|
||||
with_sandbox_env() (
|
||||
export SANDBOX_DB_CONTAINER="$DB" SANDBOX_PG_PASSWORD="$SB_PW"
|
||||
export SANDBOX_DB_CONTAINER="$DB" SANDBOX_PG_PASSWORD="$SB_PW" SANDBOX_SEED_PASSWORD="$SB_SEED_PW"
|
||||
export SANDBOX_AUTH_URL="http://127.0.0.1:$PORT_AUTH" SANDBOX_REST_URL="http://127.0.0.1:$PORT_REST"
|
||||
export SANDBOX_STORAGE_URL="http://127.0.0.1:$PORT_STORAGE" SANDBOX_MAIL_URL="http://127.0.0.1:$PORT_MAIL"
|
||||
export SANDBOX_ANON_KEY="$SB_ANON_KEY" SANDBOX_SERVICE_KEY="$SB_SERVICE_KEY"
|
||||
@@ -322,11 +336,17 @@ cmd_verify_e2e() {
|
||||
}
|
||||
|
||||
# The avatar suite drives supabase-js through the gateway's loopback port; its
|
||||
# psql calls name the sandbox database container, which it requires.
|
||||
# psql calls name the sandbox database container. The suite accepts no other
|
||||
# target, and a port already taken stops the run before anything starts.
|
||||
cmd_avatar_e2e() {
|
||||
worker_preflight "$AVATAR_WORKER"
|
||||
if (exec 3<>"/dev/tcp/127.0.0.1/$PORT_GATEWAY") 2>/dev/null; then
|
||||
die "port 127.0.0.1:$PORT_GATEWAY is already in use: free it, nothing was started"
|
||||
fi
|
||||
trap 'worker_cleanup "$AVATAR_WORKER"' EXIT
|
||||
start_gateway -p 127.0.0.1:$PORT_GATEWAY:8000
|
||||
[ "$(docker port "$GATEWAY" 8000/tcp)" = "127.0.0.1:$PORT_GATEWAY" ] \
|
||||
|| die "the gateway is not published on 127.0.0.1:$PORT_GATEWAY only"
|
||||
start_worker "$AVATAR_WORKER" sandbox-avatar 512m \
|
||||
$'WORKER_SWEEP_SECONDS=5\nWORKER_QUARANTINE_GRACE_SECONDS=0\n' run
|
||||
SUPABASE_URL="http://127.0.0.1:$PORT_GATEWAY" SUPABASE_ANON_KEY="$SB_ANON_KEY" \
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
# The one place the DEV origin is decided (docs/development/ENVIRONMENTS.md §2).
|
||||
# Sourced by the wrappers (scripts/supabase.sh, scripts/dev.sh, scripts/avatar-e2e.sh):
|
||||
# Sourced by the wrappers (scripts/supabase.sh, scripts/dev.sh, scripts/db-sandbox.sh):
|
||||
# every service the browser of another device must reach is addressed by the
|
||||
# host's LAN address, never by 127.0.0.1 or localhost.
|
||||
#
|
||||
|
||||
Reference in new issue
Block a user