@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / 5abc335
Fork 0

سامانه صدور فاکتور و حسابداری

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 15:45 UTC

test: add C8 private-entry and index security assertions

davoodmehraban89 committed Oct 1, 2026 at 21:30 UTC 5abc335ef6fb172bd2e2bc48df4dbbd179a585c0
1 file changed +25
supabase/tests/office_c8_runtime_security.sql new
+25
@@ -0,0 +1,25 @@
1 +begin;
2 +select set_config('request.jwt.claim.sub','11111111-1111-4111-8111-111111111111',true);
3 +select set_config('request.jwt.claim.org','aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa',true);
4 +select set_config('request.jwt.claim.member_active','true',true);
5 +select set_config('request.jwt.claim.entitled','true',true);
6 +select set_config('request.jwt.claim.write','true',true);
7 +select set_config('request.jwt.claim.readable','true',true);
8 +select set_config('request.jwt.claim.capabilities','read,refer,edit,approve,configure',true);
9 +
10 +do $$ begin
11 + if private.office_workflow_read_impl('aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa','LETTER_RACE',-1,10)->'instance' is null then raise exception 'private read path failed legitimate request'; end if;
12 + perform set_config('request.jwt.claim.member_active','false',true);
13 + begin perform private.office_workflow_read_impl('aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa','LETTER_RACE',-1,10); raise exception 'private read bypassed suspended membership'; exception when insufficient_privilege then null; end;
14 + perform set_config('request.jwt.claim.member_active','true',true);
15 + perform set_config('request.jwt.claim.write','false',true);
16 + begin perform private.office_workflow_attach_impl('aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa','LETTER_RACE','race',1,'20000000-0000-4000-8000-000000000001'); raise exception 'private attach bypassed read-only entitlement'; exception when insufficient_privilege then null; end;
17 +end $$;
18 +
19 +do $$ begin
20 + if not exists(select 1 from pg_indexes where schemaname='private' and indexname='office_workflow_instances_attached_by_idx') then raise exception 'attached_by FK index missing'; end if;
21 + if not exists(select 1 from pg_indexes where schemaname='private' and indexname='office_workflow_events_actor_fk_idx') then raise exception 'actor_id FK index missing'; end if;
22 + if has_table_privilege('anon','private.office_workflow_instances','SELECT') or has_table_privilege('authenticated','private.office_workflow_instances','SELECT') then raise exception 'runtime instance table leaked to client roles'; end if;
23 + if has_table_privilege('anon','private.office_workflow_events','SELECT') or has_table_privilege('authenticated','private.office_workflow_events','SELECT') then raise exception 'runtime event table leaked to client roles'; end if;
24 +end $$;
25 +rollback;