test(app): authenticated shell suite on the isolated stack

pnpm e2e:shell (db-sandbox e2e-shell) builds a Vite server on 127.0.0.1:5192 against a Supabase URL that resolves nowhere and replays its calls on the sandbox. Per-test fictitious accounts through the admin API, a clean avatar seeded: sign-in, dashboard, the photo confirmation with a slow removal, the phone drawer, FR and EN, axe. No trace kept, fixture values masked in reports.
This commit is contained in:
bchanot committed 2026-10-25 22:46:19 +01:00
1 parent 8371aa0a2a
commit e3a2b3e114
7 files changed
+395 -19

No files matched your search

+40 -10
View File
@@ -12,10 +12,14 @@ import {
type Project,
} from '@playwright/test'
/** Desktop and the 375 × 667 phone of the V1-1 contract (§12.5); Chromium only until V1-5. */
/**
* Desktop and the 375 × 667 phone of the V1-1 contract (§12.5); Chromium only
* until V1-5. A test tagged `@phone` covers what exists on small screens only.
*/
export const PROJECTS: Project[] = [
{
name: 'chromium-desktop',
grepInvert: /@phone/,
use: {
...devices['Desktop Chrome'],
viewport: { width: 1280, height: 800 },
@@ -40,16 +44,23 @@ export interface GuardOptions {
forbiddenInUrls: string[]
}
export interface RequestGuard {
/** Adds values made during the test (a fictitious account) to `forbiddenInUrls`. */
forbid: (...values: string[]) => void
}
/**
* Every test runs under a request guard: a request to an origin outside the
* allowlist (the DEV stack, a CDN, anything) is aborted, and the test fails
* listing it, as it fails on a URL holding a fixture value.
* listing it, as it fails on a URL holding a fixture value (masked in the
* report, which never shows the value itself).
*/
export const test = base.extend<GuardOptions & { requestGuard: void }>({
export const test = base.extend<GuardOptions & { requests: RequestGuard }>({
allowedOrigins: [[], { option: true }],
forbiddenInUrls: [[], { option: true }],
requestGuard: [
requests: [
async ({ context, allowedOrigins, forbiddenInUrls }, use) => {
const forbidden = forbiddenInUrls.filter((value) => value !== '')
const refused: string[] = []
const leaking: string[] = []
await context.route(
@@ -61,10 +72,19 @@ export const test = base.extend<GuardOptions & { requestGuard: void }>({
)
context.on('request', (request) => {
const url = decodeURIComponent(request.url())
if (forbiddenInUrls.some((value) => value && url.includes(value)))
leaking.push(url)
const found = forbidden.filter((value) => url.includes(value))
if (found.length > 0)
leaking.push(
found.reduce(
(masked, value) => masked.replaceAll(value, '<fixture>'),
url,
),
)
})
await use({
forbid: (...values) =>
forbidden.push(...values.filter((v) => v !== '')),
})
await use()
expect(refused, 'requests outside the allowed origins').toEqual([])
expect(leaking, 'request URLs carrying a fixture value').toEqual([])
},
@@ -77,13 +97,23 @@ export { expect }
/**
* Serious violations found before V1-1.3, outside its code, listed in TODO RR-7
* until their own fix: the scan lets these exact nodes through and fails on any
* other. The language switcher's buttons show « FR » / « EN » but are named
* « Passer en français » / « Switch to English » (WCAG 2.5.3 label in name).
* other (WCAG 2.5.3 label in name, 1.3.1 info and relationships).
*/
const KNOWN_VIOLATIONS: { id: string; target: RegExp }[] = [
const KNOWN_VIOLATIONS: { id: string; target: RegExp; note: string }[] = [
{
id: 'label-content-name-mismatch',
target: /^button\[aria-label="(Passer en français|Switch to English)"\]$/,
note: 'LanguageSwitcher: shows « FR » / « EN », named « Passer en français » / « Switch to English »',
},
{
id: 'label-content-name-mismatch',
target: /^\.pr-1$/,
note: 'AppLayout top bar account link: shows the display name, named « Mon compte » / « My account »',
},
{
id: 'definition-list',
target: /^dl$/,
note: 'DashboardRoute account card: the verified-status row is a div without dt/dd inside the dl',
},
]
+109
View File
@@ -0,0 +1,109 @@
/**
* The shell suite's backend: the throwaway stack of `pnpm db:sandbox`, never
* DEV. The app is built against a fake origin that resolves nowhere; every
* request to it is replayed on the sandbox's loopback services, the way Kong
* maps them on the CLI stack. Accounts are fictitious and made per test.
*/
import { createHash, randomBytes, randomUUID } from 'node:crypto'
import type { BrowserContext } from '@playwright/test'
import { sql, stack } from '../../../../packages/supabase/tests/sandbox/stack'
/** The Supabase URL the e2e:shell dev server is built with (RFC 6761 `.invalid`). */
export const FAKE_SUPABASE_ORIGIN = 'http://sandbox.faunosteo.invalid'
const storageUrl = process.env.SANDBOX_STORAGE_URL
if (!storageUrl)
throw new Error('SANDBOX_STORAGE_URL missing: run pnpm e2e:shell')
const ROUTES: [prefix: string, target: string][] = [
['/auth/v1/', `${stack.authUrl}/`],
['/rest/v1/', `${stack.restUrl}/`],
['/storage/v1/', `${storageUrl}/`],
]
/** Replays the page's Supabase calls on the sandbox; an unmapped path is refused. */
export async function routeToSandbox(context: BrowserContext): Promise<void> {
await context.route(`${FAKE_SUPABASE_ORIGIN}/**`, async (route) => {
const path =
new URL(route.request().url()).pathname +
new URL(route.request().url()).search
const mapped = ROUTES.find(([prefix]) => path.startsWith(prefix))
if (!mapped) return route.abort('blockedbyclient')
const response = await route.fetch({
url: mapped[1] + path.slice(mapped[0].length),
})
await route.fulfill({ response })
})
}
/** 1 × 1 lossless WebP: a real image for the clean avatar the account starts with. */
const AVATAR_WEBP = Buffer.from(
'UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA==',
'base64',
)
export interface SandboxAccount {
email: string
password: string
displayName: string
}
async function admin(path: string, init: RequestInit): Promise<Response> {
const response = await fetch(`${stack.authUrl}${path}`, {
...init,
headers: {
Authorization: `Bearer ${stack.serviceKey}`,
apikey: stack.serviceKey,
'Content-Type': 'application/json',
},
})
if (!response.ok)
throw new Error(`sandbox admin ${path}: HTTP ${response.status}`)
return response
}
/** The clean avatar the worker would have produced: row as postgres, object with the service key. */
async function seedAvatar(ownerId: string): Promise<void> {
const assetId = randomUUID()
const key = `profiles/${ownerId}/${assetId}/avatar.webp`
const sha256 = createHash('sha256').update(AVATAR_WEBP).digest('hex')
const upload = await fetch(`${storageUrl}/object/avatars/${key}`, {
method: 'POST',
headers: {
Authorization: `Bearer ${stack.serviceKey}`,
'Content-Type': 'image/webp',
},
body: AVATAR_WEBP,
})
if (!upload.ok)
throw new Error(`sandbox avatar upload: HTTP ${upload.status}`)
await sql(`insert into public.assets
(id, owner_id, kind, bucket_id, object_key, status, declared_mime, declared_size, byte_size, sha256)
values ('${assetId}', '${ownerId}', 'profile_avatar', 'avatars', '${key}', 'clean',
'image/webp', ${AVATAR_WEBP.length}, ${AVATAR_WEBP.length}, '${sha256}')`)
}
/** A confirmed fictitious account, its profile in `locale`, with or without a photo. */
export async function createAccount(
locale: 'fr' | 'en',
withAvatar: boolean,
): Promise<SandboxAccount> {
const tag = randomUUID().slice(0, 8)
const account = {
email: `e2e-shell-${tag}@sandbox.local`,
password: randomBytes(18).toString('base64url'),
displayName: `Praticienne Fictive ${tag}`,
}
const response = await admin('/admin/users', {
method: 'POST',
body: JSON.stringify({
email: account.email,
password: account.password,
email_confirm: true,
user_metadata: { display_name: account.displayName, locale },
}),
})
const { id } = (await response.json()) as { id: string }
if (withAvatar) await seedAvatar(id)
return account
}