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
@@ -3,7 +3,7 @@
|
||||
-- upload INSERT policy exists, no UPDATE/DELETE policy. Rows are seeded
|
||||
-- directly (table owner) to exercise the policy, not the RPCs (those are 016).
|
||||
begin;
|
||||
select plan(15);
|
||||
select plan(16);
|
||||
|
||||
-- Bucket
|
||||
select is((select public from storage.buckets where id = 'anatomical-sheet-assets'), false, 'the bucket is private');
|
||||
@@ -21,22 +21,27 @@ select is(
|
||||
0::bigint, 'no UPDATE or DELETE policy on the bucket'
|
||||
);
|
||||
|
||||
-- Accounts: owner, editor (admin + capability), reader (catalog_reader), plain.
|
||||
-- Accounts: owner, two editors (admin + capability), reader (catalog_reader), plain.
|
||||
insert into auth.users (id, email, email_confirmed_at) values
|
||||
('30000000-0000-0000-0000-000000000001', 'own-st@test.local', now()),
|
||||
('30000000-0000-0000-0000-00000000000e', 'ed-st@test.local', now()),
|
||||
('30000000-0000-0000-0000-0000000000e2', 'ed2-st@test.local', now()),
|
||||
('30000000-0000-0000-0000-0000000000d0', 'rd-st@test.local', now()),
|
||||
('30000000-0000-0000-0000-0000000000d1', 'pl-st@test.local', now());
|
||||
insert into auth.mfa_factors (id, user_id, factor_type, status, created_at, updated_at)
|
||||
values (gen_random_uuid(), '30000000-0000-0000-0000-00000000000e', 'totp', 'verified', now(), now());
|
||||
values (gen_random_uuid(), '30000000-0000-0000-0000-00000000000e', 'totp', 'verified', now(), now()),
|
||||
(gen_random_uuid(), '30000000-0000-0000-0000-0000000000e2', 'totp', 'verified', now(), now());
|
||||
insert into auth.sessions (id, user_id, aal) values
|
||||
('31000000-0000-0000-0000-000000000001', '30000000-0000-0000-0000-000000000001', 'aal2'),
|
||||
('31000000-0000-0000-0000-00000000000e', '30000000-0000-0000-0000-00000000000e', 'aal2');
|
||||
('31000000-0000-0000-0000-00000000000e', '30000000-0000-0000-0000-00000000000e', 'aal2'),
|
||||
('31000000-0000-0000-0000-0000000000e2', '30000000-0000-0000-0000-0000000000e2', 'aal2');
|
||||
select set_config('request.jwt.claims', '', true);
|
||||
select private.assign_platform_role(null, '30000000-0000-0000-0000-000000000001', 'owner');
|
||||
select private.assign_platform_role(null, '30000000-0000-0000-0000-00000000000e', 'admin');
|
||||
select private.assign_platform_role(null, '30000000-0000-0000-0000-0000000000e2', 'admin');
|
||||
insert into public.anatomical_catalog_grants (user_id, grant_kind, reason, verification_note, granted_by) values
|
||||
('30000000-0000-0000-0000-00000000000e', 'sheet_editor', 'author', 'checked', '30000000-0000-0000-0000-000000000001'),
|
||||
('30000000-0000-0000-0000-0000000000e2', 'sheet_editor', 'author', 'checked', '30000000-0000-0000-0000-000000000001'),
|
||||
('30000000-0000-0000-0000-0000000000d0', 'catalog_reader', 'beta', null, '30000000-0000-0000-0000-000000000001');
|
||||
|
||||
-- An official sheet with a published version (asset A), a deprecated version
|
||||
@@ -82,12 +87,21 @@ create function pg_temp.act(p_uid uuid, p_sid uuid, p_aal text) returns void lan
|
||||
select set_config('request.jwt.claims', jsonb_build_object('sub',p_uid,'role','authenticated','aal',p_aal,'session_id',p_sid)::text, true);
|
||||
$$;
|
||||
grant execute on function pg_temp.act(uuid,uuid,text) to authenticated;
|
||||
-- The objects of this file's keys the caller reads: the stack may hold other
|
||||
-- drawings (sandbox suites, DEV after its first publications, LRN-093).
|
||||
create function pg_temp.objects_seen() returns table (name text) language sql as $$
|
||||
select o.name from storage.objects o
|
||||
where o.bucket_id = 'anatomical-sheet-assets'
|
||||
and o.name in (select repeat(c, 64) || '.svg' from unnest(array['a', 'b', 'c', 'd', 'e']) c)
|
||||
order by o.name;
|
||||
$$;
|
||||
grant execute on function pg_temp.objects_seen() to authenticated;
|
||||
|
||||
-- Reader (catalog_reader, aal1): the published and deprecated drawings only.
|
||||
set local role authenticated;
|
||||
select pg_temp.act('30000000-0000-0000-0000-0000000000d0', gen_random_uuid(), 'aal1');
|
||||
select results_eq(
|
||||
$$ select name from storage.objects where bucket_id='anatomical-sheet-assets' order by name $$,
|
||||
$$ select name from pg_temp.objects_seen() $$,
|
||||
$$ values (repeat('a',64)||'.svg'), (repeat('b',64)||'.svg') $$,
|
||||
'a catalogue reader reads the published and deprecated drawings, not the draft or pending ones'
|
||||
);
|
||||
@@ -95,7 +109,7 @@ select results_eq(
|
||||
-- Editor at aal2: every uploaded drawing of the official sheet (a, b, c), not the pending d.
|
||||
select pg_temp.act('30000000-0000-0000-0000-00000000000e', '31000000-0000-0000-0000-00000000000e', 'aal2');
|
||||
select results_eq(
|
||||
$$ select name from storage.objects where bucket_id='anatomical-sheet-assets' order by name $$,
|
||||
$$ select name from pg_temp.objects_seen() $$,
|
||||
$$ values (repeat('a',64)||'.svg'), (repeat('b',64)||'.svg'), (repeat('c',64)||'.svg') $$,
|
||||
'an editor at aal2 reads every confirmed drawing of the official sheet, not the pending one'
|
||||
);
|
||||
@@ -105,14 +119,14 @@ select results_eq(
|
||||
-- shows the published and deprecated drawings (not the draft's).
|
||||
select pg_temp.act('30000000-0000-0000-0000-00000000000e', gen_random_uuid(), 'aal1');
|
||||
select results_eq(
|
||||
$$ select name from storage.objects where bucket_id='anatomical-sheet-assets' order by name $$,
|
||||
$$ select name from pg_temp.objects_seen() $$,
|
||||
$$ values (repeat('a',64)||'.svg'), (repeat('b',64)||'.svg') $$,
|
||||
'the editor at aal1 falls back to the reader branch: published and deprecated only'
|
||||
);
|
||||
|
||||
-- A plain confirmed account with no right: nothing.
|
||||
select pg_temp.act('30000000-0000-0000-0000-0000000000d1', gen_random_uuid(), 'aal1');
|
||||
select is((select count(*) from storage.objects where bucket_id='anatomical-sheet-assets'), 0::bigint,
|
||||
select is((select count(*) from pg_temp.objects_seen()), 0::bigint,
|
||||
'a confirmed account without any right reads nothing');
|
||||
|
||||
-- The INSERT policy only allows a pending key of one''s own sheet: a confirmed
|
||||
@@ -125,16 +139,23 @@ select throws_ok(
|
||||
'42501', null, 'an editor cannot insert a confirmed (non-pending) object key'
|
||||
);
|
||||
|
||||
-- A fifth asset, pending, with no object yet: the editor uploads its key.
|
||||
-- A fifth asset, pending, registered by the first editor, with no object yet:
|
||||
-- only the editor who registered it uploads its key (§9.3 step 2).
|
||||
reset role;
|
||||
select set_config('request.jwt.claims', '{"sub":"30000000-0000-0000-0000-000000000001"}', true);
|
||||
insert into public.anatomical_sheet_assets (id, sheet_id, sha256, byte_size, file_name)
|
||||
values ('32000000-0000-0000-0000-00000000000e', '32000000-0000-0000-0000-000000000001', repeat('e',64), 100, 'e.svg');
|
||||
insert into public.anatomical_sheet_assets (id, sheet_id, sha256, byte_size, file_name, created_by)
|
||||
values ('32000000-0000-0000-0000-00000000000e', '32000000-0000-0000-0000-000000000001', repeat('e',64), 100, 'e.svg',
|
||||
'30000000-0000-0000-0000-00000000000e');
|
||||
set local role authenticated;
|
||||
select pg_temp.act('30000000-0000-0000-0000-0000000000e2', '31000000-0000-0000-0000-0000000000e2', 'aal2');
|
||||
select throws_ok(
|
||||
$$ insert into storage.objects (bucket_id, name, metadata) values ('anatomical-sheet-assets', repeat('e',64)||'.svg', '{"size":100}') $$,
|
||||
'42501', null, 'another editor cannot upload a pending key it did not register'
|
||||
);
|
||||
select pg_temp.act('30000000-0000-0000-0000-00000000000e', '31000000-0000-0000-0000-00000000000e', 'aal2');
|
||||
select lives_ok(
|
||||
$$ insert into storage.objects (bucket_id, name, metadata) values ('anatomical-sheet-assets', repeat('e',64)||'.svg', '{"size":100}') $$,
|
||||
'an editor uploads the pending key of their own sheet'
|
||||
'the editor who registered the pending row uploads its key'
|
||||
);
|
||||
|
||||
-- confirm with the storage check: a wrong size is refused, the right one works.
|
||||
|
||||
Reference in new issue
Block a user