pgsql-test-jwt-context
Installation
SKILL.md
Setting up JWT claims and role-based context for RLS testing with pgsql-test.
Overview
When testing Row-Level Security (RLS) policies, you need to simulate authenticated users with JWT claims. The pgsql-test library provides the setContext() method to configure PostgreSQL session variables that RLS policies can read.
The setContext API
Use setContext() to simulate different user roles and JWT claims:
db.setContext({
role: 'authenticated',
'jwt.claims.user_id': '00000000-0000-0000-0000-000000000001',
'jwt.claims.org_id': 'acme-corp'
});
This applies settings using SET LOCAL statements, ensuring they persist only for the current transaction and maintain proper isolation between tests.