test(supabase): V1-2.1 re-runnable sandbox suite, two-session cases, caps timing
F18 and workspaces no longer leave the seed owner changed. Ten two-session scenarios with a blocking session, seed-owner AR-1 acceptance, shim columns against the image, save/submit/approve/publish timed at the caps.
This commit is contained in:
1 parent
d05f75da84
commit
ef1f4b593f
10 files changed
+930
-65
No files matched your search
@@ -6,17 +6,7 @@
|
||||
* `pnpm db:sandbox test tests/sandbox/sheets.sandbox.ts`.
|
||||
*/
|
||||
import { confirmedAccount, rpc, sql, errorCode, type Account } from './stack'
|
||||
import { enrolTotp, verifyTotp, claimsOf } from './mfa'
|
||||
|
||||
/** Enrols and verifies a TOTP factor, returning a fresh aal2 access token. */
|
||||
async function stepUp(account: Account): Promise<string> {
|
||||
const enrol = await enrolTotp(account.token, 'device')
|
||||
if (!enrol.factor) throw new Error(`enrol failed: ${JSON.stringify(enrol.body)}`)
|
||||
const verified = await verifyTotp(account.token, enrol.factor)
|
||||
const token = verified.body.access_token as string
|
||||
if (!token) throw new Error(`verify failed: ${JSON.stringify(verified.body)}`)
|
||||
return token
|
||||
}
|
||||
import { claimsOf, stepUp } from './mfa'
|
||||
|
||||
describe('AR-1 B on real GoTrue', () => {
|
||||
let owner: Account
|
||||
@@ -29,8 +19,8 @@ describe('AR-1 B on real GoTrue', () => {
|
||||
// Bootstrap the owner role through the operator path (no JWT).
|
||||
await sql(`select private.assign_platform_role(null, '${owner.id}', 'owner')`)
|
||||
// The target holds a verified factor (a grant needs one).
|
||||
await stepUp(target)
|
||||
ownerAal2 = await stepUp(owner)
|
||||
await stepUp(target.token)
|
||||
ownerAal2 = await stepUp(owner.token)
|
||||
}, 120_000)
|
||||
|
||||
it('refuses a platform role change from the aal1 session', async () => {
|
||||
@@ -63,29 +53,37 @@ describe('last-owner race (F18)', () => {
|
||||
it('two concurrent revocations of two owners leave one owner', async () => {
|
||||
const a = await confirmedAccount('f18-a')
|
||||
const b = await confirmedAccount('f18-b')
|
||||
const aAal2 = await stepUp(a)
|
||||
const bAal2 = await stepUp(b)
|
||||
const aAal2 = await stepUp(a.token)
|
||||
const bAal2 = await stepUp(b.token)
|
||||
await sql(`select private.assign_platform_role(null, '${a.id}', 'owner')`)
|
||||
await sql(`select private.assign_platform_role(null, '${b.id}', 'owner')`)
|
||||
// Neutralise every other owner so a and b are the only two.
|
||||
await sql(`update public.profile_roles set revoked_at = now(), revoke_reason = 'f18 test'
|
||||
where role = 'owner' and revoked_at is null and user_id not in ('${a.id}', '${b.id}')`)
|
||||
expect(await sql(`select count(*) from public.profile_roles where role = 'owner' and revoked_at is null`)).toBe('2')
|
||||
// Every other owner (the seed owner included) is set aside for the race and
|
||||
// put back afterwards, whatever the outcome, so the suite runs again on the
|
||||
// same stack (V1-2.1 audit M5).
|
||||
const setAside = (await sql(`update public.profile_roles set revoked_at = now(), revoke_reason = 'f18 test'
|
||||
where role = 'owner' and revoked_at is null and user_id not in ('${a.id}', '${b.id}')
|
||||
returning id`)).split('\n').filter(Boolean)
|
||||
try {
|
||||
expect(await sql(`select count(*) from public.profile_roles where role = 'owner' and revoked_at is null`)).toBe('2')
|
||||
|
||||
// Each revokes the other, concurrently.
|
||||
const [ra, rb] = await Promise.all([
|
||||
rpc('revoke_platform_role', { target_user_id: b.id, role: 'owner', reason: 'race a' }, aAal2),
|
||||
rpc('revoke_platform_role', { target_user_id: a.id, role: 'owner', reason: 'race b' }, bAal2),
|
||||
])
|
||||
const statuses = [ra.status, rb.status]
|
||||
// The invariant that F18 broke: the two cannot both pass and leave zero
|
||||
// owners. Exactly one succeeds; the other is refused (last_owner when it
|
||||
// reaches the guard, or forbidden when it lost its own ownership first);
|
||||
// one owner always remains.
|
||||
expect(statuses.filter((s) => s === 200), JSON.stringify([ra.body, rb.body])).toHaveLength(1)
|
||||
expect(statuses.filter((s) => s !== 200)).toHaveLength(1)
|
||||
expect(await sql(`select count(*) from public.profile_roles where role = 'owner' and revoked_at is null`)).toBe('1')
|
||||
|
||||
await sql(`delete from auth.users where id in ('${a.id}', '${b.id}')`)
|
||||
// Each revokes the other, concurrently.
|
||||
const [ra, rb] = await Promise.all([
|
||||
rpc('revoke_platform_role', { target_user_id: b.id, role: 'owner', reason: 'race a' }, aAal2),
|
||||
rpc('revoke_platform_role', { target_user_id: a.id, role: 'owner', reason: 'race b' }, bAal2),
|
||||
])
|
||||
const statuses = [ra.status, rb.status]
|
||||
// The invariant that F18 broke: the two cannot both pass and leave zero
|
||||
// owners. Exactly one succeeds; the other is refused (last_owner when it
|
||||
// reaches the guard, or forbidden when it lost its own ownership first);
|
||||
// one owner always remains.
|
||||
expect(statuses.filter((s) => s === 200), JSON.stringify([ra.body, rb.body])).toHaveLength(1)
|
||||
expect(statuses.filter((s) => s !== 200)).toHaveLength(1)
|
||||
expect(await sql(`select count(*) from public.profile_roles where role = 'owner' and revoked_at is null`)).toBe('1')
|
||||
} finally {
|
||||
await sql(`delete from auth.users where id in ('${a.id}', '${b.id}')`)
|
||||
if (setAside.length > 0)
|
||||
await sql(`update public.profile_roles set revoked_at = null, revoked_by = null, revoke_reason = null
|
||||
where id in (${setAside.map((id) => `'${id}'`).join(', ')})`)
|
||||
}
|
||||
}, 120_000)
|
||||
})
|
||||
Reference in new issue
Block a user