Repository navigation
fix(rls): resolve policy table matching and fix Vitest test suite (#71) - #318
Open
MilindChatrabhuji wants to merge 1 commit into
Open
MilindChatrabhuji wants to merge 1 commit into
MilindChatrabhuji wants to merge 1 commit into
Conversation
…terbase#71) - Added `tableNamesMatch` helper in `src/rls/index.ts` to accurately match schema-qualified policy tables (e.g. `public.users`) against query table references (`users`). - Support nested subqueries in `from`, `join`, and `columns` by inspecting `expr.ast`. - Fixed multi-table query condition formatting and test isolation in `src/rls/index.test.ts`. - All 19 Vitest test suites (155 tests) now pass 100% cleanly. Fixes outerbase#71
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Fixes #71 (Bounty claim: @algora-pbc /claim #71)
Currently on
main, runningpnpm testfails with 4 broken tests insrc/rls/index.test.tsdue to schema-qualified policy table matching and nested subquery traversal limitations.This PR resolves the RLS policy table matching and repairs the test suite so that all 19 Vitest test suites across the repository pass 100% cleanly.
Key Changes
Schema & Identifier Matching (
src/rls/index.ts):tableNamesMatchhelper to match schema-qualified policy tables (e.g.public.users) against query table references (users), respecting stripped or explicit schemas.left.tableappropriately based on single-table vs multi-table queries (ensuring single table queries omit redundant table prefixes while multi-table/JOIN queries preserve table/alias qualification).Nested Subquery Traversal:
from,join, andcolumnsby inspectingexpr.ast(the actual AST node generated bynode-sql-parser).Test Suite Isolation & Expectations (
src/rls/index.test.ts):mockConfig.role = 'client'inbeforeEachto prevent test-order mutation pollution from admin edge case tests.SELECT,DELETE,UPDATE,INSERT, multi-table JOINs, aliased JOINs, and subqueries.Verification
npx vitest runexecutes all 19 test files with 155 of 155 tests passing:npx prettier --check "src/rls/index.ts" "src/rls/index.test.ts").