feat(supabase): owner trial served on the LAN address, sandbox kept on loopback
This commit is contained in:
1 parent
a69eba569b
commit
d74c54ed05
6 files changed
+260
-21
No files matched your search
@@ -0,0 +1,154 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { fr } from '@/i18n/fr'
|
||||
import type { Page } from '@playwright/test'
|
||||
import { totpCode } from '../../../../packages/supabase/tests/sandbox/totp'
|
||||
import { expect, test } from '../support/browser'
|
||||
|
||||
// Owner trial through its LAN origin (C47): sign-in, TOTP enrolment and challenge, the
|
||||
// catalogue, a non-equine sheet, an SVG import, save and reload. The request guard of
|
||||
// support/browser.ts fails on any request outside the origin; the listener below also
|
||||
// names 127.0.0.1 and localhost. TRIAL_EMAIL and TRIAL_PW_FILE (first line, mode 600).
|
||||
|
||||
const dict = fr
|
||||
const email = process.env.TRIAL_EMAIL ?? ''
|
||||
const password =
|
||||
(process.env.TRIAL_PW_FILE ?? '')
|
||||
? readFileSync(process.env.TRIAL_PW_FILE ?? '', 'utf8').split('\n')[0]
|
||||
: ''
|
||||
|
||||
const SVG =
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 300">' +
|
||||
'<style>.a{fill:#c96}</style>' +
|
||||
'<rect class="a" x="20" y="20" width="360" height="260"/></svg>'
|
||||
|
||||
const revisionLine = (page: Page) =>
|
||||
page.getByRole('status').filter({ hasText: /^Révision \d+/ })
|
||||
|
||||
async function revisionShown(page: Page): Promise<number> {
|
||||
const text = (await revisionLine(page).textContent()) ?? ''
|
||||
return Number(/Révision (\d+)/.exec(text)?.[1])
|
||||
}
|
||||
|
||||
async function nextCode(secret: string): Promise<string> {
|
||||
const left = 30_000 - (Date.now() % 30_000)
|
||||
if (left < 3000) await new Promise((r) => setTimeout(r, left + 200))
|
||||
return totpCode(secret)
|
||||
}
|
||||
|
||||
async function signIn(page: Page) {
|
||||
await page.goto('/login')
|
||||
await page.getByLabel(dict['auth.email']).fill(email)
|
||||
await page.getByLabel(dict['auth.password'], { exact: true }).fill(password)
|
||||
await page.getByRole('button', { name: dict['auth.login.submit'] }).click()
|
||||
await expect(page).toHaveURL(/\/app\/?$/)
|
||||
}
|
||||
|
||||
async function enrol(page: Page): Promise<string> {
|
||||
await page.goto('/app/account')
|
||||
await page.getByRole('button', { name: dict['mfa.enrol.start'] }).click()
|
||||
await page.getByLabel(dict['mfa.enrol.name']).fill('Essai LAN')
|
||||
await page.getByRole('button', { name: dict['mfa.enrol.continue'] }).click()
|
||||
const key = page.getByText(/^[A-Z2-7]{16,}$/)
|
||||
await expect(key).toBeVisible()
|
||||
const secret = ((await key.textContent()) ?? '').trim()
|
||||
await page.getByLabel(dict['mfa.code.label']).fill(await nextCode(secret))
|
||||
await page.getByRole('button', { name: dict['mfa.code.verify'] }).click()
|
||||
await expect(page.getByText(dict['mfa.enrol.done'])).toBeVisible()
|
||||
return secret
|
||||
}
|
||||
|
||||
async function challenge(page: Page, secret: string) {
|
||||
await page.goto('/app/admin')
|
||||
const field = page.getByRole('main').getByLabel(dict['mfa.code.label'])
|
||||
await expect(field).toBeVisible()
|
||||
await page.waitForLoadState('networkidle')
|
||||
await field.fill(await nextCode(secret))
|
||||
await page
|
||||
.getByRole('main')
|
||||
.getByRole('button', { name: dict['mfa.code.verify'] })
|
||||
.click()
|
||||
await expect(field).toBeHidden()
|
||||
}
|
||||
|
||||
async function createNonEquineSheet(page: Page, tag: string) {
|
||||
await page.goto('/app/admin/sheets')
|
||||
await expect(
|
||||
page.getByRole('heading', { name: dict['admin.sheets.title'] }),
|
||||
).toBeVisible()
|
||||
await page.getByRole('link', { name: dict['admin.sheets.new'] }).click()
|
||||
const species = page.getByLabel(dict['admin.sheet_form.species'], {
|
||||
exact: true,
|
||||
})
|
||||
const nonEquine = species.locator(
|
||||
'option:not([value=""]):not([value="equine"])',
|
||||
)
|
||||
await expect(nonEquine.first()).toBeAttached()
|
||||
await page.waitForLoadState('networkidle')
|
||||
const chosen = (await nonEquine.first().getAttribute('value')) ?? ''
|
||||
await species.selectOption(chosen)
|
||||
await expect(species).toHaveValue(chosen)
|
||||
await page
|
||||
.getByLabel(dict['admin.sheet_form.name_fr'])
|
||||
.fill(`Fiche LAN ${tag}`)
|
||||
await page
|
||||
.getByLabel(dict['admin.sheet_form.name_en'])
|
||||
.fill(`LAN sheet ${tag}`)
|
||||
await page
|
||||
.getByRole('button', { name: dict['admin.sheet_form.submit'] })
|
||||
.click()
|
||||
await expect(page).toHaveURL(/\/app\/admin\/sheets\/[0-9a-f-]{36}\/draft$/)
|
||||
}
|
||||
|
||||
test('trial through the LAN origin: MFA, new sheet, SVG import, save, reload', async ({
|
||||
page,
|
||||
}) => {
|
||||
test.skip(!email || !password, 'TRIAL_EMAIL and TRIAL_PW_FILE are required')
|
||||
test.setTimeout(120_000)
|
||||
const local: string[] = []
|
||||
page.on('request', (request) => {
|
||||
if (/\/\/(127\.0\.0\.1|localhost)/.test(request.url()))
|
||||
local.push(request.url())
|
||||
})
|
||||
const tag = Date.now().toString(36)
|
||||
await signIn(page)
|
||||
const secret = await enrol(page)
|
||||
// Enrolment leaves an aal2 session: a new sign-in brings the real challenge.
|
||||
await page
|
||||
.getByRole('button', { name: dict['shell.sign_out'] })
|
||||
.first()
|
||||
.click()
|
||||
await expect(page).not.toHaveURL(/\/app/)
|
||||
await signIn(page)
|
||||
await challenge(page, secret)
|
||||
await createNonEquineSheet(page, tag)
|
||||
await page
|
||||
.getByRole('tab', { name: dict['editor.tab.views'], exact: true })
|
||||
.click()
|
||||
await page
|
||||
.locator('[data-testid$="-file"]')
|
||||
.first()
|
||||
.setInputFiles({
|
||||
name: 'lan.svg',
|
||||
mimeType: 'image/svg+xml',
|
||||
buffer: Buffer.from(SVG),
|
||||
})
|
||||
const dialog = page.getByRole('dialog', {
|
||||
name: dict['editor.cleaning.title'],
|
||||
})
|
||||
await expect(dialog).toBeVisible()
|
||||
await dialog
|
||||
.getByRole('button', { name: dict['editor.cleaning.confirm'] })
|
||||
.click()
|
||||
await expect(page.getByText(dict['editor.upload.done'])).toBeVisible()
|
||||
const before = await revisionShown(page)
|
||||
await page.getByRole('button', { name: dict['common.save'] }).click()
|
||||
await expect(revisionLine(page)).toHaveText(`Révision ${before + 1}`)
|
||||
await page.reload()
|
||||
await page
|
||||
.getByRole('tab', { name: dict['editor.tab.views'], exact: true })
|
||||
.click()
|
||||
await expect(
|
||||
page.getByRole('tabpanel').getByText(dict['editor.views.drawing.ok']),
|
||||
).toBeVisible()
|
||||
expect(local, 'requests to 127.0.0.1 or localhost').toEqual([])
|
||||
})
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* `playwright test -c e2e/playwright.lan.config.ts` (docs/development/V1-2-6_OWNER_TRIAL.md):
|
||||
* the owner's trial reached through its LAN origin, which is a non-secure context like a
|
||||
* phone's browser. It needs a running `pnpm db:sandbox trial` and a trial account; the
|
||||
* page may reach that origin only. No trace, no report: they would hold the session tokens
|
||||
* and the password. Run by hand, never part of check:all.
|
||||
*/
|
||||
import { defineConfig } from '@playwright/test'
|
||||
import type { GuardOptions } from './support/browser'
|
||||
|
||||
const ORIGIN = process.env.TRIAL_ORIGIN ?? 'http://192.168.1.100:5193'
|
||||
|
||||
export default defineConfig<GuardOptions>({
|
||||
testDir: './lan',
|
||||
outputDir: './test-results/lan',
|
||||
forbidOnly: true,
|
||||
retries: 0,
|
||||
expect: { timeout: 15_000 },
|
||||
reporter: [['list']],
|
||||
use: {
|
||||
baseURL: ORIGIN,
|
||||
locale: 'fr-FR',
|
||||
allowedOrigins: [ORIGIN],
|
||||
trace: 'off',
|
||||
screenshot: 'off',
|
||||
viewport: { width: 1280, height: 900 },
|
||||
},
|
||||
})
|
||||
Reference in new issue
Block a user