fix(supabase): V1-2.1 audit M1 M2 M3 and LOW fixes in M5
Approval needs an active sheet (lock sheet, version, round); a base only from a still-published round version; rights.mfa before rights.capability; withdrawal of a published round refused; approver separation at publish; deprecate and working copy serialised; closed codes; append-only acks; upload policy bound to the registering editor. pgTAP 017-019 added.
This commit is contained in:
1 parent
3914eaa866
commit
d05f75da84
10 files changed
+1477
-127
No files matched your search
@@ -47,7 +47,9 @@ export const SHEET_FAILURE_KINDS = [
|
||||
'draft.unchanged',
|
||||
'draft.frozen',
|
||||
'draft.not_a_draft',
|
||||
'draft.exists',
|
||||
'document.shape',
|
||||
'document.schema_version',
|
||||
'document.species',
|
||||
'document.too_large',
|
||||
// sheet and species state
|
||||
@@ -57,6 +59,7 @@ export const SHEET_FAILURE_KINDS = [
|
||||
'sheet.published_history',
|
||||
'sheet.historical_read_only',
|
||||
'sheet.species_invalid',
|
||||
'sheet.slug_taken',
|
||||
'species.exists',
|
||||
'species.not_active',
|
||||
'species.not_inactive',
|
||||
@@ -83,9 +86,11 @@ export const SHEET_FAILURE_KINDS = [
|
||||
'publish.species.other',
|
||||
'publish.drawing.missing',
|
||||
'publish.drawing.changed',
|
||||
'view.asset.unknown',
|
||||
// uploads and working copy
|
||||
'upload_missing',
|
||||
'size_mismatch',
|
||||
'asset.referenced',
|
||||
'working_copy.source_invalid',
|
||||
'working_copy.exists',
|
||||
'working_copy.assets_missing',
|
||||
|
||||
@@ -28,8 +28,9 @@ create table auth.users (
|
||||
|
||||
-- MFA state read by the V1-2 assurance checks (private.has_aal2_session,
|
||||
-- private.has_verified_totp). Types, names and NOT NULL columns as in GoTrue
|
||||
-- v2.197.0 (checked on the pinned image by tests/sandbox/mfa.sandbox.ts);
|
||||
-- the columns the migrations never read are left out.
|
||||
-- v2.197.0 (compared with the pinned image by
|
||||
-- tests/sandbox/shim-columns.sandbox.ts); the columns the migrations never read
|
||||
-- are left out.
|
||||
create type auth.aal_level as enum ('aal1', 'aal2', 'aal3');
|
||||
create type auth.factor_type as enum ('totp', 'webauthn', 'phone', 'recovery_code');
|
||||
create type auth.factor_status as enum ('unverified', 'verified');
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
import { SHEET_FAILURE_KINDS, SheetFailure, classifySheetError } from '../src/sheets'
|
||||
import { migrationsDir } from './db/harness'
|
||||
|
||||
/**
|
||||
* The closed failure kinds of the sheet workflow (V1-2.1). The census reads
|
||||
* every closed code M4 and M5 raise (`raise exception '<code>'`, a lowercase
|
||||
* dotted word; free-text messages are not codes) so a code added on the server
|
||||
* can never reach a page as `unavailable` for want of a kind.
|
||||
*/
|
||||
const SHEET_MIGRATIONS = [
|
||||
'20261028100000_sheet_access_hardening.sql',
|
||||
'20261028110000_sheet_review_workflow.sql',
|
||||
]
|
||||
|
||||
async function raisedCodes(): Promise<string[]> {
|
||||
const codes = new Set<string>()
|
||||
for (const file of SHEET_MIGRATIONS) {
|
||||
const sql = await readFile(join(migrationsDir, file), 'utf8')
|
||||
for (const match of sql.matchAll(/raise exception '([a-z_]+(?:\.[a-z_]+)*)'/g))
|
||||
codes.add(match[1])
|
||||
}
|
||||
return [...codes].sort()
|
||||
}
|
||||
|
||||
describe('sheet failure kinds', () => {
|
||||
it('names every closed code the sheet migrations raise', async () => {
|
||||
const kinds = new Set<string>(SHEET_FAILURE_KINDS)
|
||||
const codes = await raisedCodes()
|
||||
expect(codes.length).toBeGreaterThan(50)
|
||||
expect(codes.filter((code) => !kinds.has(code))).toEqual([])
|
||||
})
|
||||
|
||||
it('folds an answer into its kind and fails closed on anything else', () => {
|
||||
expect(classifySheetError({ code: 'P0001', message: 'view.asset.unknown' })).toBe('view.asset.unknown')
|
||||
expect(classifySheetError({ code: '42501', message: 'rights.mfa' })).toBe('rights.mfa')
|
||||
expect(classifySheetError({ code: '40P01', message: 'deadlock detected' })).toBe('conflict_retry')
|
||||
expect(classifySheetError({ code: '23505', message: 'duplicate key value' })).toBe('unavailable')
|
||||
expect(classifySheetError({}, 401)).toBe('session_expired')
|
||||
expect(classifySheetError(new TypeError('fetch failed'))).toBe('network')
|
||||
expect(classifySheetError(new SheetFailure('draft.exists'))).toBe('draft.exists')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user