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,15 +1,15 @@
|
||||
/**
|
||||
* Avatar flow against a real stack and the worker container
|
||||
* (docs/development/STORAGE.md §4, §3; STEP8_FILES_ANALYSIS IV.2 "integration"
|
||||
* and "real-stack e2e"). Run through `pnpm db:sandbox avatar-e2e` (the throwaway
|
||||
* stack) or `pnpm e2e:avatar` (scripts/avatar-e2e.sh, the local DEV stack), both
|
||||
* starting the worker with a 5 s sweep and a 0 s quarantine grace.
|
||||
* and "real-stack e2e"). Run through `pnpm e2e:avatar` (= `pnpm db:sandbox
|
||||
* avatar-e2e`): the throwaway stack only, the worker started with a 5 s sweep and
|
||||
* a 0 s quarantine grace.
|
||||
*
|
||||
* Environment: SUPABASE_URL, SUPABASE_ANON_KEY, SUPABASE_SERVICE_ROLE_KEY
|
||||
* (the service key is used for inspection only: listing objects and shifting
|
||||
* the purge clock through psql) and AVATAR_E2E_DB_CONTAINER, the database
|
||||
* container of that same stack, named by the caller: no default, so a run never
|
||||
* reaches another stack's database. Both accounts are made per run.
|
||||
* the purge clock through psql) and AVATAR_E2E_DB_CONTAINER. The URL and the
|
||||
* container must be the sandbox's own: any other value, or a missing one, fails
|
||||
* the run before any request. Both accounts are made per run.
|
||||
*/
|
||||
import { createHash, randomBytes } from 'node:crypto'
|
||||
import { execFileSync } from 'node:child_process'
|
||||
@@ -30,6 +30,11 @@ const URL_ = process.env.SUPABASE_URL
|
||||
const ANON = process.env.SUPABASE_ANON_KEY
|
||||
const SERVICE = process.env.SUPABASE_SERVICE_ROLE_KEY
|
||||
const DB_CONTAINER = process.env.AVATAR_E2E_DB_CONTAINER
|
||||
/** The only target accepted: the gateway and database of `pnpm db:sandbox avatar-e2e`. */
|
||||
const SANDBOX_URL = 'http://127.0.0.1:57800'
|
||||
const SANDBOX_DB = 'faunosteo_dbsandbox_db'
|
||||
if (URL_ !== SANDBOX_URL || DB_CONTAINER !== SANDBOX_DB || !ANON || !SERVICE)
|
||||
throw new Error('avatar e2e: run it through pnpm e2e:avatar, on the sandbox stack only')
|
||||
/** Per run, kept in memory only: both accounts are deleted after the suite. */
|
||||
const PASSWORD = randomBytes(18).toString('base64url')
|
||||
const WORKER_WAIT_MS = 60_000
|
||||
@@ -37,7 +42,7 @@ const WORKER_WAIT_MS = 60_000
|
||||
type Client = SupabaseClient<Database>
|
||||
|
||||
function anonClient(): Client {
|
||||
return createClient<Database>(URL_ ?? '', ANON ?? '', {
|
||||
return createClient<Database>(SANDBOX_URL, ANON ?? '', {
|
||||
auth: { persistSession: false, autoRefreshToken: false },
|
||||
})
|
||||
}
|
||||
@@ -50,7 +55,7 @@ async function signedIn(email: string): Promise<Client> {
|
||||
}
|
||||
|
||||
function serviceClient(): Client {
|
||||
return createClient<Database>(URL_ ?? '', SERVICE ?? '', {
|
||||
return createClient<Database>(SANDBOX_URL, SERVICE ?? '', {
|
||||
auth: { persistSession: false, autoRefreshToken: false },
|
||||
})
|
||||
}
|
||||
@@ -169,7 +174,7 @@ async function objectExists(service: Client, bucket: string, key: string): Promi
|
||||
|
||||
function psql(sql: string): string {
|
||||
return execFileSync('docker', [
|
||||
'exec', DB_CONTAINER ?? '', 'psql', '-U', 'postgres', '-d', 'postgres', '-Atc', sql,
|
||||
'exec', SANDBOX_DB, 'psql', '-U', 'postgres', '-d', 'postgres', '-Atc', sql,
|
||||
]).toString().trim()
|
||||
}
|
||||
|
||||
@@ -200,8 +205,6 @@ function sha256(bytes: Uint8Array): string {
|
||||
|
||||
// --- suite ------------------------------------------------------------------
|
||||
|
||||
const configured = Boolean(URL_ && ANON && SERVICE && DB_CONTAINER)
|
||||
|
||||
/** A confirmed throwaway account; resolves with its id. */
|
||||
async function newAccount(service: Client, tag: string, name: string): Promise<{ id: string; email: string }> {
|
||||
const email = `e2e-${tag}-${Date.now()}@faunosteo.local`
|
||||
@@ -215,7 +218,7 @@ async function newAccount(service: Client, tag: string, name: string): Promise<{
|
||||
return { id: created.data.user.id, email }
|
||||
}
|
||||
|
||||
describe.skipIf(!configured)('avatar flow on the real stack', () => {
|
||||
describe('avatar flow on the sandbox stack', () => {
|
||||
const service = serviceClient()
|
||||
let alice: Client
|
||||
let aliceId: string
|
||||
|
||||
@@ -8,16 +8,15 @@
|
||||
* factors and sessions made here are removed afterwards (as postgres), so the
|
||||
* owner is back to no factor and the suite runs again on the same stack.
|
||||
*/
|
||||
import { confirmedAccount, errorCode, rest, rpc, signIn, sql } from './stack'
|
||||
import { SEED_PASSWORD, confirmedAccount, errorCode, rest, rpc, signIn, sql } from './stack'
|
||||
import { claimsOf, enrolTotp, stepUp, verifyTotp } from './mfa'
|
||||
|
||||
const OWNER = '10000000-0000-0000-0000-000000000001'
|
||||
const OWNER_EMAIL = 'owner@faunosteo.local'
|
||||
const OWNER_PASSWORD = 'LocalDev-only-password-1'
|
||||
const FACTOR_PREFIX = 'seed-owner-test'
|
||||
|
||||
const passwordSession = async (): Promise<string> => {
|
||||
const session = await signIn(OWNER_EMAIL, OWNER_PASSWORD)
|
||||
const session = await signIn(OWNER_EMAIL, SEED_PASSWORD)
|
||||
return session.body.access_token as string
|
||||
}
|
||||
const refusal = (result: { status: number; body: unknown }) =>
|
||||
|
||||
@@ -25,6 +25,8 @@ export const stack = {
|
||||
serviceKey: need('SANDBOX_SERVICE_KEY'),
|
||||
}
|
||||
const PG_PASSWORD = need('SANDBOX_PG_PASSWORD')
|
||||
/** The seeded accounts' password in this sandbox session (db-sandbox.sh replaces the seed's). */
|
||||
export const SEED_PASSWORD = need('SANDBOX_SEED_PASSWORD')
|
||||
/** The password of the accounts a run creates: random per run, kept in memory only. */
|
||||
export const PASSWORD = randomBytes(18).toString('base64url')
|
||||
|
||||
|
||||
Reference in new issue
Block a user