test(supabase): make pgTAP counts seed-agnostic (real stack carries seed accounts)
This commit is contained in:
1 parent
d5a5a720a1
commit
a2e33fe4a2
2 files changed
+28
-8
No files matched your search
@@ -109,8 +109,19 @@ select is((select count(*) from public.profiles), 1::bigint, 'plain user still s
|
||||
|
||||
-- 6. Admin sees every grant and every profile (staff read)
|
||||
select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-00000000000a","role":"authenticated"}', true);
|
||||
select is((select count(*) from public.profile_roles), 3::bigint, 'admin sees all three grant rows');
|
||||
select is((select count(*) from public.profiles), 4::bigint, 'admin reads every profile');
|
||||
select is(
|
||||
(select count(*) from public.profile_roles
|
||||
where user_id in ('00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-00000000000a', '00000000-0000-0000-0000-00000000000b')),
|
||||
3::bigint,
|
||||
'admin sees all three fixture grant rows'
|
||||
);
|
||||
select is(
|
||||
(select count(*) from public.profiles where id in (
|
||||
'00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-00000000000a',
|
||||
'00000000-0000-0000-0000-00000000000b', '00000000-0000-0000-0000-00000000000c')),
|
||||
4::bigint,
|
||||
'admin reads every fixture profile'
|
||||
);
|
||||
|
||||
-- 7. Anonymous
|
||||
set local role anon;
|
||||
@@ -135,7 +146,9 @@ reset role;
|
||||
update public.profiles set active = false where id = '00000000-0000-0000-0000-00000000000a';
|
||||
select ok(not private.is_platform_admin('00000000-0000-0000-0000-00000000000a'), 'deactivated account loses its roles');
|
||||
|
||||
-- 9. Last-owner guard on the system path
|
||||
-- 9. Last-owner guard on the system path (neutralise owners seeded outside the fixtures)
|
||||
update public.profile_roles set revoked_at = now()
|
||||
where role = 'owner' and revoked_at is null and user_id <> '00000000-0000-0000-0000-000000000001';
|
||||
select throws_ok(
|
||||
$$ select private.withdraw_platform_role(null, '00000000-0000-0000-0000-000000000001', 'owner', 'oops') $$,
|
||||
'42501',
|
||||
|
||||
@@ -12,7 +12,7 @@ select private.assign_platform_role(null, '00000000-0000-0000-0000-000000000001'
|
||||
-- 1. Bootstrap is audited as a system action
|
||||
select results_eq(
|
||||
$$ select actor_user_id, action, resource_type, target_user_id, metadata ->> 'role'
|
||||
from audit.audit_logs $$,
|
||||
from audit.audit_logs where target_user_id = '00000000-0000-0000-0000-000000000001' $$,
|
||||
$$ values (null::uuid, 'platform_role.granted'::text, 'profile_role'::text,
|
||||
'00000000-0000-0000-0000-000000000001'::uuid, 'owner'::text) $$,
|
||||
'bootstrap grant logged with null actor'
|
||||
@@ -27,7 +27,8 @@ reset role;
|
||||
|
||||
select results_eq(
|
||||
$$ select action, actor_user_id, target_user_id, metadata ->> 'reason'
|
||||
from audit.audit_logs where actor_user_id is not null order by occurred_at, action $$,
|
||||
from audit.audit_logs where actor_user_id = '00000000-0000-0000-0000-000000000001'
|
||||
order by occurred_at, action $$,
|
||||
$$ values ('platform_role.granted'::text, '00000000-0000-0000-0000-000000000001'::uuid,
|
||||
'00000000-0000-0000-0000-00000000000a'::uuid, null::text),
|
||||
('platform_role.revoked'::text, '00000000-0000-0000-0000-000000000001'::uuid,
|
||||
@@ -36,9 +37,10 @@ select results_eq(
|
||||
);
|
||||
select is(
|
||||
(select count(*) from audit.audit_logs a
|
||||
join public.profile_roles r on r.id = a.resource_id),
|
||||
join public.profile_roles r on r.id = a.resource_id
|
||||
where a.target_user_id in ('00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-00000000000a')),
|
||||
3::bigint,
|
||||
'every audit row points at its profile_roles row'
|
||||
'every fixture audit row points at its profile_roles row'
|
||||
);
|
||||
|
||||
-- 3. Append-only, even for the privileged owner session
|
||||
@@ -72,7 +74,12 @@ select throws_ok(
|
||||
-- 5. Read access: owner yes, plain user no, anon no, nobody writes through the API
|
||||
set local role authenticated;
|
||||
select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-000000000001","role":"authenticated"}', true);
|
||||
select is((select count(*) from audit.audit_logs), 3::bigint, 'owner reads the audit log');
|
||||
select is(
|
||||
(select count(*) from audit.audit_logs
|
||||
where target_user_id in ('00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-00000000000a')),
|
||||
3::bigint,
|
||||
'owner reads the audit log'
|
||||
);
|
||||
select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-00000000000b","role":"authenticated"}', true);
|
||||
select is((select count(*) from audit.audit_logs), 0::bigint, 'plain user reads nothing');
|
||||
select throws_ok(
|
||||
|
||||
Reference in new issue
Block a user