Files
myeasycms-v2/apps/web/supabase/tests/database/personal-accounts.test.sql
Giancarlo Buomprisco 131b1061e6 Enforce RLS when user opted in to MFA. (#188)
* Allow Super Admin to view tables using RLS
* Replace previous usages of the Admin client using the authed client using the new RLS
* Enforce MFA for Super Admin users
* Enforce RLS when user opted in to MFA.
* Add Super Admin Access Policies and Update Database Types
* Consolidate super admin logic into a single function that uses the RPC is_super_admin
* Added Super Admin E2E tests
* Fixes and improvements
* Bump version to 2.5.0
2025-03-02 11:21:01 +08:00

57 lines
1.6 KiB
PL/PgSQL

BEGIN;
create extension "basejump-supabase_test_helpers" version '0.0.6';
select no_plan();
--- we insert a user into auth.users and return the id into user_id to use
select tests.create_supabase_user('test1', 'test1@test.com');
select tests.create_supabase_user('test2');
------------
--- Primary Owner
------------
select makerkit.authenticate_as('test1');
-- should create the personal account automatically with the same ID as the user
SELECT row_eq(
$$ select primary_owner_user_id, is_personal_account, name from public.accounts order by created_at desc limit 1 $$,
ROW (tests.get_supabase_uid('test1'), true, 'test1'::varchar),
'Inserting a user should create a personal account when personal accounts are enabled'
);
-- anon users should not be able to see the personal account
set local role anon;
SELECT throws_ok(
$$ select * from public.accounts order by created_at desc limit 1 $$,
'permission denied for schema public'
);
-- the primary owner should be able to see the personal account
select makerkit.authenticate_as('test1');
SELECT isnt_empty(
$$ select * from public.accounts where primary_owner_user_id = tests.get_supabase_uid('test1') $$,
'The primary owner should be able to see the personal account'
);
------------
--- Other Users
-- other users should not be able to see the personal account
select makerkit.authenticate_as('test2');
SELECT is_empty(
$$ select * from public.accounts where primary_owner_user_id = tests.get_supabase_uid('test1') $$,
'Other users should not be able to see the personal account'
);
SELECT *
FROM finish();
ROLLBACK;