M4 20261028100000_sheet_access_hardening + M5 20261028110000_sheet_review_workflow (applied together; no unprotected window). Implements contract §5-§14. - Catalogue rights table + owner RPCs; has_mfa / has_aal2_session (live auth.sessions check); grant_active vs caller_has split; catalogue reader predicate; can_edit_sheet on the sheet_editor capability (F14). - AR-1 B: aal2 required on every platform role change, target verified factor, race-free last-owner guard (F18/F19); service_role loses table privileges on the catalogue + profiles/profile_roles and EXECUTE on the role RPCs (F12/F17). - Reviewed lifecycle: version provenance + review columns, content/freeze/ author triggers, rounds/comments/acknowledgments, save/submit/withdraw/ comment/acknowledge/decide, atomic publish_sheet_version(review_id) on the stored verdict, deprecate/archive/restore, species RPCs, equine working copy, uploads with the storage check (F7) + editor INSERT policy + 2 MiB bucket. F1-F3,F5,F6,F8,F9,F13,F15,F16 closed. Verdict is a fixture until M6 (V1-2.3). - O22: SQL business mirror removed, declared status check kept; pgTAP 011 and the Rust generator's SQL parts deleted, ledger retargeted. - Access layer sheets.ts (closed SheetFailure kinds); old client publish gate deleted; types regenerated; upload tool reads via get_sheet_asset_state. Tested on the throwaway sandbox only; DEV untouched. pgTAP 850 (real stack) / 122 (PGlite) green; real-GoTrue AR-1 B + F18 race green; fresh install and M3->M5 upgrade green; V1-1 regression green; rust:check, typecheck, lint, build, types drift clean. BDR-084, LRN-095.
71 lines
4.0 KiB
PL/PgSQL
71 lines
4.0 KiB
PL/PgSQL
-- Schema contract: objects exist, RLS is on, API roles start from zero.
|
|
begin;
|
|
select plan(26);
|
|
|
|
-- Schemas
|
|
select has_schema('private', 'schema private exists');
|
|
select has_schema('audit', 'schema audit exists');
|
|
|
|
-- Tables
|
|
select has_table('public', 'profiles', 'table public.profiles exists');
|
|
select has_table('public', 'profile_roles', 'table public.profile_roles exists');
|
|
select has_table('audit', 'audit_logs', 'table audit.audit_logs exists');
|
|
|
|
-- RLS enabled everywhere (pgTAP has no helper: read pg_class)
|
|
select ok(
|
|
(select relrowsecurity from pg_class where oid = 'public.profiles'::regclass),
|
|
'RLS enabled on profiles'
|
|
);
|
|
select ok(
|
|
(select relrowsecurity from pg_class where oid = 'public.profile_roles'::regclass),
|
|
'RLS enabled on profile_roles'
|
|
);
|
|
select ok(
|
|
(select relrowsecurity from pg_class where oid = 'audit.audit_logs'::regclass),
|
|
'RLS enabled on audit_logs'
|
|
);
|
|
|
|
-- Enum
|
|
select enum_has_labels(
|
|
'public', 'platform_role',
|
|
array['owner', 'admin', 'moderator', 'support'],
|
|
'platform_role has exactly the four platform roles (no professional status)'
|
|
);
|
|
|
|
-- Functions
|
|
select has_function('private', 'log_event', 'private.log_event exists');
|
|
select has_function('private', 'is_platform_owner', array['uuid'], 'private.is_platform_owner exists');
|
|
select has_function('private', 'is_platform_admin', array['uuid'], 'private.is_platform_admin exists');
|
|
select has_function('private', 'is_platform_moderator', array['uuid'], 'private.is_platform_moderator exists');
|
|
select has_function('private', 'is_support', array['uuid'], 'private.is_support exists');
|
|
select has_function('public', 'grant_platform_role', array['uuid', 'platform_role'], 'public.grant_platform_role exists');
|
|
select has_function('public', 'revoke_platform_role', array['uuid', 'platform_role', 'text'], 'public.revoke_platform_role exists');
|
|
|
|
-- Privileges: anon has nothing, authenticated has only what RLS then filters
|
|
select ok(not has_table_privilege('anon', 'public.profiles', 'select'), 'anon cannot select profiles');
|
|
select ok(not has_table_privilege('anon', 'public.profile_roles', 'select'), 'anon cannot select profile_roles');
|
|
select ok(not has_table_privilege('authenticated', 'public.profiles', 'insert'), 'authenticated cannot insert profiles');
|
|
select ok(not has_table_privilege('authenticated', 'public.profiles', 'delete'), 'authenticated cannot delete profiles');
|
|
select ok(not has_table_privilege('authenticated', 'public.profile_roles', 'insert'), 'authenticated cannot insert profile_roles');
|
|
select ok(not has_column_privilege('authenticated', 'public.profiles', 'active', 'update'), 'authenticated cannot update profiles.active');
|
|
select ok(not has_schema_privilege('anon', 'private', 'usage'), 'anon has no usage on schema private');
|
|
select ok(not has_function_privilege('anon', 'public.grant_platform_role(uuid, public.platform_role)', 'execute'), 'anon cannot execute grant_platform_role');
|
|
|
|
-- Private helpers: EXECUTE revoked from everyone except the predicates the policies evaluate.
|
|
-- (has_function_privilege is true for any role while proacl is null, i.e. the built-in PUBLIC default.)
|
|
select is(
|
|
(select count(*) from pg_proc p join pg_namespace n on n.oid = p.pronamespace
|
|
where n.nspname in ('private', 'audit') and has_function_privilege('anon', p.oid, 'execute')),
|
|
0::bigint, 'anon can execute nothing in private/audit'
|
|
);
|
|
select is(
|
|
(select string_agg(p.proname::text, ',' order by p.proname::text collate "C")
|
|
from pg_proc p join pg_namespace n on n.oid = p.pronamespace
|
|
where n.nspname in ('private', 'audit') and has_function_privilege('authenticated', p.oid, 'execute')),
|
|
'asset_in_catalog_version,caller_can_see_official_sheet,caller_is_catalog_staff,caller_workspace_ids,can_read_avatar_object,can_read_catalog_sheet,can_read_sheet_asset_object,can_upload_avatar_object,can_upload_sheet_asset_object,fold_text,has_mfa,has_platform_role,is_platform_admin,is_platform_moderator,is_platform_owner,is_support',
|
|
'authenticated executes only the policy predicates in private'
|
|
);
|
|
|
|
select * from finish();
|
|
rollback;
|