pgtap-rls
/pgtap-rls
Pisze, przegląda i uruchamia testy pgTAP dla Row Level Security, uprawnień i funkcji SQL w projektach Supabase.
- Autor
- AndresDiagoM ↗
- Repozytorium
- agent-testing-skills ↗
- Licencja
- Apache-2.0
- Ostatnia zmiana repozytorium
- 12.11.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 43
- Skrypty
- 6
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 12.11.2026, bez odwołań do wycofanych modeli i API.
Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.
- 6 skryptów w paczce. Przejrzyj je przed instalacją, bo Claude może je uruchomić.
Skrypty: scripts/mutate-test.mjs, scripts/tap-to-evidence.mjs, scripts/test/evidence.test.mjs, scripts/test/mutate-test.test.mjs, scripts/test/schema-check.mjs, scripts/test/tap.test.mjs
Co robi i kiedy
Pisze, przegląda i uruchamia testy pgTAP dla Row Level Security, uprawnień i funkcji SQL w projektach Supabase.
Oryginalny opis (EN)
Write, review and run pgTAP tests for Row Level Security, grants and SQL functions in Supabase/Postgres projects (supabase/tests/database/*.test.sql, `supabase test db`): allow and deny cases per role (anon, owner, other user, service_role only for setup), JWT impersonation in a rolled-back transaction, silent UPDATE/DELETE denials, rls_enabled coverage, security definer and RPC checks, and a mutation check that proves a test can fail. Use when asked to test, audit or verify RLS policies, grants or SQL functions, to add or fix pgTAP tests, or to check that one user cannot read or write another
Jak działa
- When to read what (references/)
Podgląd SKILL.md
---
name: pgtap-rls
description: "Write, review and run pgTAP tests for Row Level Security, grants and SQL functions in Supabase/Postgres projects (supabase/tests/database/*.test.sql, `supabase test db`): allow and deny cases per role (anon, owner, other user, service_role only for setup), JWT impersonation in a rolled-back transaction, silent UPDATE/DELETE denials, rls_enabled coverage, security definer and RPC checks, and a mutation check that proves a test can fail. Use when asked to test, audit or verify RLS policies, grants or SQL functions, to add or fix pgTAP tests, or to check that one user cannot read or write another user's rows. Not for Playwright/e2e or Vitest/Jest tests, query performance, or designing the policies themselves."
license: Apache-2.0
compatibility: Needs the Supabase CLI and a running local Supabase stack (Docker) for `supabase test db`; Node 20+ for the optional scripts. Verified on Supabase CLI 3.1.0 / Postgres 17.
metadata:
version: "0.3.1"
verified-against: "Supabase CLI 3.1.0, Postgres 17.11, pgTAP 1.3.3 on a local stack (2026-11-12); client-level template not yet run, see references/VERSIONS.md"
---
# pgTAP tests for RLS
Repo rules (AGENTS.md, `.claude/rules/*`, OVERRIDES.md) win over this skill.
1. **Layout.** Tests go in `supabase/tests/database/NN_topic.test.sql`; every file is `begin; create extension if not exists pgtap with schema extensions; select plan(N); ... select * from finish(); rollback;` with an exact `plan(N)`.
2. **Local only.** Run only on the local stack via the repo script (`db:test`) or `supabase test db [paths]`; never pass `--remote`, never use `db reset`, `db push`, or a linked/remote DB for tests. If the stack is down, say so and stop (start it only if the repo rules or the user allow).
3. **Discover before writing.** Read the migrations (and, if the stack is up, the catalog) for tables, each policy's command/role/`using`/`with check`, grants and functions; never write tests from memory.
4. **Impersonate exactly.** `reset role;` then `select set_config('request.jwt.claims', '<json>', true);` then `set local role <role>;`. Claims for `anon` and `service_role` are `{"role":"anon"}` / `{"role":"service_role"}`, never a leftover user's claims.
5. **Matrix per policy.** For every table x command (select, insert, update, delete) x role (anon, owner, other user; service_role only to seed/read back) write one allow and one deny case, plus a positive control next to every deny.
6. **Know which layer denies.** Missing grant gives `42501` on any command; an RLS filter on SELECT/UPDATE/DELETE gives 0 rows and no error; `with check` on INSERT/UPDATE gives `42501`. Assert the layer that applies.
7. **Silent denials are asserted twice.** Other user (owning no rows): `is_empty(update t set c = 1 returning 1)`, no `where` (a column read applies the SELECT policy and can hide an open UPDATE policy); then re-read it as its owner.
8. **Every user table has RLS enabled** and its policy set pinned (`rls-coverage.test.sql`, `policies_are`); the table list comes from the catalog.
9. **Prove each deny test can fail.** Mutation check on the test (`scripts/mutate-test.mjs`): a temporary permissive `using (true)` policy (or a temporary grant, for grant denials) inside the test transaction must turn the deny test red. A test that stays green is vacuous: fix it.
10. **Never edit a policy, grant, function or migration to make a test pass.** If code and expectation disagree, stop and report the discrepancy (table, command, role, expected, actual, migration:line). Never weaken or delete an assertion, `skip()`, or `todo()` to get green.
11. **Functions.** For each: definer or invoker, `search_path` (`proconfig`), owner, `auth.uid()` use, EXECUTE grants per role, and a call with another user's ids.
12. **Fast and isolated.** No `db reset` per test; ids unique per file; fixtures created inside the file's transaction; never assert counts of seed data.
13. **No literal secrets, not even fake ones** (JWTs, keys, passwords): claims are built from ids; client-level tests read env vars or generate values at runtime. No destructive commands in examples.
14. **Report with evidence.** Run the full DB suite once, re-run only a failing file, finish with one full run; record it with `scripts/tap-to-evidence.mjs` and report wall time and passed/failed/skipped. Zero tests is a failure.
## When to read what (`references/`)
| Situation | Read |
|---|---|
| Unmapped repo or table | `discover.md` |
| Any role or claims switch | `impersonation.md` |
| Allow/deny cases, silent denials | `policy-matrix.md` |
| Coverage, pinned policies, mutation | `coverage-and-mutation.md` |
| Function, RPC, trigger, view, grants | `functions-and-grants.md` |
| Slow, flaky, colliding ids | `isolation-and-speed.md` |
| Real sign-in, PostgREST, doubles | `beyond-transactions.md` |
| Running, evidence, parsing TAP | `running-and-evidence.md` |
| Repo overrides, Basejump | `repo-basejump.md` |
Templates: `assets/` (skeleton, policy-matrix, claims-aal2, rls-coverage, client test). Unverified snippets: `references/VERSIONS.md`.
Pliki w paczce (43)
- SKILL.md 5 KB
- assets/claims-aal2.test.sql 5 KB
- assets/client-rls.test.ts.tmpl 5 KB
- assets/policy-matrix.test.sql 7 KB
- assets/rls-coverage.test.sql 2 KB
- assets/test-skeleton.test.sql 2 KB
- references/VERSIONS.md 5 KB
- references/beyond-transactions.md 2 KB
- references/coverage-and-mutation.md 5 KB
- references/discover.md 3 KB
- references/functions-and-grants.md 3 KB
- references/impersonation.md 4 KB
- references/isolation-and-speed.md 2 KB
- references/policy-matrix.md 5 KB
- references/repo-basejump.md 1 KB
- references/running-and-evidence.md 4 KB
- scripts/mutate-test.mjs 9 KB
- scripts/tap-to-evidence.mjs 35 KB
- scripts/test/evidence.test.mjs 9 KB
- scripts/test/mutate-test.test.mjs 5 KB
- scripts/test/schema-check.mjs 2 KB
- scripts/test/tap.test.mjs 15 KB
- scripts/test/fixtures/README.md 2 KB
- scripts/test/fixtures/all-pass.txt 1 KB
- scripts/test/fixtures/ansi-crlf.txt 1 KB
- scripts/test/fixtures/cli-died.err 1 KB
- scripts/test/fixtures/cli-died.out 1 KB
- scripts/test/fixtures/cli-fail.err 1 KB
- scripts/test/fixtures/cli-fail.out 1 KB
- scripts/test/fixtures/cli-pass.err 2 KB
- scripts/test/fixtures/cli-pass.out 1 KB
- scripts/test/fixtures/cli-plan.err 1 KB
- scripts/test/fixtures/cli-plan.out 1 KB
- scripts/test/fixtures/cli-skip.err 1 KB
- scripts/test/fixtures/cli-skip.out 1 KB
- scripts/test/fixtures/cli-zero.err 1 KB
- scripts/test/fixtures/cli-zero.out 1 KB
- scripts/test/fixtures/died-mid.txt 1 KB
- scripts/test/fixtures/garbage.txt 1 KB
- scripts/test/fixtures/one-fail.txt 1 KB
- scripts/test/fixtures/plan-bad.txt 1 KB
- scripts/test/fixtures/verbose.txt 1 KB
- scripts/test/fixtures/zero.txt 1 KB
Wersje
| Repozytorium | Wynik | Licencja |
|---|---|---|
| Ta strona · AndresDiagoM/agent-testing-skills | 100 | Apache-2.0 |
| AndresDiagoM/agent-testing-skills | 100 | Apache-2.0 |
Migawka bazy z 13.11.2026 · wersja paczki bc9be33b2354 (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 2 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100supabase-rls-policies
Pisze, przegląda i testuje polityki Row Level Security w Supabase, żeby jeden użytkownik nie czytał ani nie zmieniał cudzych wierszy. - 100secure-supabase-rls
Włącza RLS w tabelach i widokach Supabase, pisze polityki dla ról, indeksuje je i testuje dostęp w pgTAP. - 100data
Projektuje lub przegląda schemat Supabase i Postgres, migracje, polityki RLS, funkcje SECURITY DEFINER, indeksy i wydajność zapytań. - 100supabase-rls-audit
Sprawdza zabezpieczenia Row Level Security i ekspozycję bazy Supabase w aplikacji: polityki, widoki, funkcje, klucze service_role i zasobniki. - 100supabase-rls-audit
Audytuje Supabase RLS na podstawie migracji w repozytorium: tabele bez RLS, zbyt szerokie polityki i funkcje bez stałej ścieżki wyszukiwania. - 100postgres-security-audit
Audytuje bazę PostgreSQL i kod aplikacji pod kątem bezpieczeństwa i dowodzi każdego problemu testem: wersje, role, RLS i funkcje.