is it normal to need three psql sessions open to test a single policy change Testing
Two weeks into RLS. My current workflow for checking a policy is: one psql tab as the postgres role to alter the policy, one tab where I paste a JWT claims blob and pretend to be user A, one tab for user B. Then I run the same select in both and eyeball it.
It works but it feels like something a person in 1998 would do. Is there a real workflow, or is this genuinely how everyone does it?
@arrayformula_al · 8mo ago · 3 replies
Then get it out of your hands entirely. The test that matters is one sentence: user B cannot see user A's row. Write it once per table as an integration test, seed two users, run it in CI on every migration.
pgTAP if you like your assertions in SQL, or plain test-runner code hitting your real client if you would rather test the path the app uses. I prefer the latter, because the bug is usually not in the policy - it is in the one query that goes around it.
Reply
Report
@hemline_hank · 8mo ago
Wrote four of these against the real client this afternoon. The third one failed, which was alarming for about ninety seconds until I found the endpoint that builds its own query and skips the wrapper.
Reply
Report
@wren_oyelaran · 8mo ago
That is the whole argument for integration-level tests over pgTAP in one anecdote. The policy was right; the code path around it was not.
Reply
Report