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
+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" \
|
||||
|
||||
Reference in new issue
Block a user