testing-rls-pgtap
Write and run pgTAP tests that validate Supabase Row Level Security (RLS) policies. Ensures tenants can only see their own rows, admins see all, etc…
от nghiahsgs★ 31 звезда на GitHub
Установить testing-rls-pgtap в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
testing-rls-pgtap — Supabase RLS Policy Tests
Step 0 — Detect existing setup
Read supabase/config.toml:
grep -E 'enabled.*=.*true' supabase/config.toml | grep -i 'test\|pgtap' || echo "pgTAP not enabled yet"
Scan supabase/migrations/ for tables with RLS:
grep -l 'ENABLE ROW LEVEL SECURITY' supabase/migrations/*.sql
grep -l 'CREATE POLICY' supabase/migrations/*.sql
For each table found, verify at least 1 policy exists. Tables with RLS enabled but NO policies = "default-deny, everything denied" — flag before writing tests.
Step 1 — Enable pgTAP (one-time per project)
In supabase/config.toml ensure:
[db]
major_version = 15
[db.seed]
enabled = true
[experimental]
# pgTAP comes built-in with Supabase CLI ≥ 1.100
Create supabase/tests/ directory. Each test file = one .sql ending with .test.sql.
Step 2 — Test file anatomy
-- supabase/tests/rls_orders.test.sql
begin;
select plan(5); -- 5 assertions below
-- Set up 2 users in auth.users (or use existing seed)
insert into auth.users (id, email)
values
('00000000-0000-0000-0000-000000000001', 'alice@test'),
('00000000-0000-0000-0000-000000000002', 'bob@test');
-- Seed orders owned by each
insert into public.orders (id, user_id, total)
values
('ord_alice', '00000000-0000-0000-0000-000000000001', 100),
('ord_bob', '00000000-0000-0000-0000-000000000002', 200);
-- Impersonate alice
set local role authenticated;
set local request.jwt.claims to
'{"sub":"00000000-0000-0000-0000-000000000001","role":"authenticated"}';
select is(
(select count(*) from public.orders)::int, 1,
'alice sees only her order'
);
select results_eq(
$$ select id from public.orders $$,
$$ values ('ord_alice'::text) $$,
'alice sees her order id only'
);
-- Switch to bob
set local request.jwt.claims to
'{"sub":"00000000-0000-0000-0000-000000000002","role":"authenticated"}';
select is(
(select count(*) from public.orders)::int, 1,
'bob sees only his order'
);
-- Unauthenticated
set local request.jwt.claims to '{"role":"anon"}';
select is(
(select count(*) from public.orders)::int, 0,
'anon sees zero orders'
);
-- Write denied for non-owner
set local request.jwt.claims to
'{"sub":"00000000-0000-0000-0000-000000000001","role":"authenticated"}';
select throws_ok(
$$ update public.orders set total = 999 where id = 'ord_bob' $$,
'42501',
null,
'alice cannot update bob''s order'
);
select * from finish();
rollback;
Step 3 — Useful pgTAP assertions
| Assertion | Use for |
|---|---|
is(x, y, 'desc') |
equality |
isnt(x, y, 'desc') |
inequality |
ok(boolean, 'desc') |
any truthy |
results_eq($$ q $$, $$ values (...) $$, 'desc') |
whole result set |
throws_ok($$ q $$, sqlstate, msg, 'desc') |
expect error |
lives_ok($$ q $$, 'desc') |
no error |
has_table('schema', 'table', 'desc') |
DDL assertion |
col_not_null('t', 'col', 'desc') |
constraint |
policies_are('schema', 'table', ARRAY['p1','p2']) |
exact policy set |
Step 4 — Run tests
Local Supabase running:
supabase db reset # wipes + reapplies migrations + runs seed
supabase test db # runs all .test.sql in supabase/tests/
Expected output:
# Tests 5
# Pass 5
ok
Step 5 — Common policy patterns to cover
For each policy type, at minimum:
Own-rows-only SELECT (user_id = auth.uid()):
- Owner sees own rows → 1 row returned
- Other user sees nothing → 0 rows
- Anon sees nothing → 0 rows
Insert with owner auto-fill (default auth.uid() in INSERT policy):
- Authenticated can insert
user_idfield cannot be forged (server rewrites to auth.uid())- Anon cannot insert → throws 42501
Role-based (auth.jwt() ->> 'role' = 'admin'):
- Admin sees all
- Regular user sees only own
- Anon sees nothing
Soft-delete visibility (deleted_at is null):
- Soft-deleted rows hidden from normal query
- Admin can still see via
include_deletedflag
Step 6 — CI integration
In .github/workflows/test.yml:
- uses: supabase/setup-cli@v1
with: { version: latest }
- run: supabase start
- run: supabase test db
Constraints
- Tests run against the LOCAL Supabase instance — never against cloud prod
- Every test wraps in
begin; ... rollback;so state doesn't leak between files set localis crucial —setwithoutlocalpersists across the rollback boundary- If RLS is declared but no policy exists, it's "default deny" — test should assert 0 rows returned, not skip the table
- Don't use real emails or PII in seed — use
@testpseudo-domain
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
- 01
Read - 02
Write - 03
Edit - 04
Bash - 05
Grep
FAQ
Что делает скилл testing-rls-pgtap?
Write and run pgTAP tests that validate Supabase Row Level Security (RLS) policies. Ensures tenants can only see their own rows, admins see all, etc. Detection-first — reads supabase/migrations/ to auto-infer tables and policies. Trigger phrases (EN + VN): "rls test", "pgtap", "supabase rls", "test policy", "kiem tra rls", "test bao mat database".
Как установить скилл testing-rls-pgtap?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл testing-rls-pgtap запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…