From 4ce1ea9d4e82f4bc2665d64e35fc3a829f0b1c38 Mon Sep 17 00:00:00 2001 From: Alec LeFors Date: Mon, 30 Dec 2024 16:47:49 -0600 Subject: [PATCH] test: add RLS view regression --- tests/RLS/PolicyTest.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/RLS/PolicyTest.php b/tests/RLS/PolicyTest.php index dd7c502d..6ad51cee 100644 --- a/tests/RLS/PolicyTest.php +++ b/tests/RLS/PolicyTest.php @@ -78,6 +78,34 @@ beforeEach(function () { }); }); +test('rls command succeeds when a view is in the database', function (string $manager) { + DB::statement(" + CREATE VIEW post_comments AS + SELECT + comments.id AS comment_id, + posts.id AS post_id + FROM comments + INNER JOIN posts + ON posts.id = comments.post_id + "); + + // Inherit RLS rules from joined tables + DB::statement("ALTER VIEW post_comments SET (security_invoker = on)"); + + config(['tenancy.rls.manager' => $manager]); + + try { + pest()->artisan('tenants:rls'); + + pest()->assertTrue(true); + } catch (\Exception $e) { + pest()->assertTrue(false); + } +})->with([ + TableRLSManager::class, + TraitRLSManager::class, +]); + test('postgres user gets created using the rls command', function(string $manager) { config(['tenancy.rls.manager' => $manager]);