packages/supabase/tests/e2e/avatar-flow.e2e.ts (pnpm e2e:avatar through scripts/avatar-e2e.sh: worker container on the Supabase network, 5 s sweep, no quarantine grace; a fresh account per run): clean upload and owner-only download (Bob, anon, quarantine key, direct final-key write refused), replacement purged after the grace (queue clock shifted through psql), late bytes through a still-valid signed upload URL swept, hostile and corrupted uploads rejected with closed codes, removal with the purge queue drained. Worker: the Storage API answers a missing object with HTTP 400 and statusCode 404; normalised to 404 so a purge of a never-written key is acked. docker-compose.yml: service worker under the worker profile (read-only, cap_drop ALL, no-new-privileges, 512m, 1 cpu, 64 pids, .env.worker, external Supabase network). docs/development/STORAGE.md: the implementation contract.
58 lines
2.2 KiB
Bash
Executable File
58 lines
2.2 KiB
Bash
Executable File
#!/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"
|
|
|
|
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" \
|
|
pnpm --filter @faunosteo/supabase test:e2e
|