What this thread does
Do first: Run supabase start and write cross-user policy assertions against the local database.
Short answer
Supabase's policy-testing guide requires a second user to attempt reading, updating and deleting the first user's rows on every user-data table. It also requires a deliberate policy break to demonstrate that the suite catches access widening. Policy-testing guide
What to do
1. List each role and operation that must be allowed or denied, with one test per rule. For organization-based tenancy, include organization membership and cross-organization data isolation in those rules. Advanced multi-tenant example Cover select, insert, update and delete as anon and authenticated. RLS guide 2. Use Supabase CLI v1.11.4 or later. Create a file with supabase test new todos_rls; the guide's file is supabase/tests/todos_rls_test.sql. Enable pgTAP with create extension if not exists pgtap with schema extensions. Wrap fixtures and assertions in begin and rollback, then run supabase test db. CLI testing, policy-testing example 3. Seed distinct users and their rows. Use set local role authenticated and request.jwt.claim.sub to select the actor for each assertion. Check returned rows with results_eq; the example uses is_empty on a cross-user update with returning to show that it changed nothing. Policy-testing example 4. Temporarily add a policy using using (true) on the same table. Run supabase test db and require an assertion failure; remove the temporary policy afterward. Removing the real policy is not a useful substitute: default denial can leave denial assertions passing. Agent testing rules 5. Repeat the boundary assertions through the application's Supabase client. Give each suite unique user IDs and clean up its data. A cross-user update can report no error while changing no rows, so read back the original user's rows to assert they are unchanged. Application testing 6. Run the database suite on pull requests. Supabase's CI example starts the local stack with supabase start, then runs supabase test db. Testing overview
Limits and open questions
Execute access assertions as client roles: table owners normally bypass RLS, and superusers or BYPASSRLS roles always bypass it. PostgreSQL
Views need separate attention: they bypass RLS by default; on PostgreSQL 15 or later, security_invoker = true makes the view follow underlying-table policies for client roles. Database-unit assertions and application-client assertions are distinct parts of Supabase's testing guidance. RLS guide, testing overview
Not for: Firebase Security Rules testing.
Sources
- Test Row Level Security policies with pgTAP (Supabase).
- Advanced pgTAP testing (Supabase).
- Row Level Security (Supabase).
- Testing your database (Supabase).
- Testing overview (Supabase).
- Row Security Policies (PostgreSQL).
Checked
Primary pages checked 2026-11-30: Supabase’s Test Row Level Security policies with pgTAP, Advanced pgTAP testing, Row Level Security, Testing your database, and Testing overview; PostgreSQL’s Row Security Policies. We ran no command or code.
Started from a post by @igormiazek, packaged by the editor. Original post