From 7b092ec9d3997344de7692b25be1b634d95fbecd Mon Sep 17 00:00:00 2001 From: lukinovec Date: Thu, 15 Jun 2023 13:16:57 +0200 Subject: [PATCH] Check RLS policies by name --- tests/PostgresRLSTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/PostgresRLSTest.php b/tests/PostgresRLSTest.php index 0050878b..3e257c0d 100644 --- a/tests/PostgresRLSTest.php +++ b/tests/PostgresRLSTest.php @@ -113,7 +113,7 @@ test('postgres user can get deleted using the job', function() { test('correct rls policies get created', function () { $tenantModels = tenancy()->getTenantModels(); $modelTables = collect($tenantModels)->map(fn (Model $model) => $model->getTable()); - $getRlsPolicies = fn () => DB::select('select * from pg_policies'); + $getRlsPolicies = fn () => array_map(fn ($policy) => $policy->policyname, DB::select('select * from pg_policies')); $getRlsTables = fn () => $modelTables->map(fn ($table) => DB::select('select relname, relrowsecurity, relforcerowsecurity from pg_class WHERE oid = ' . "'$table'::regclass"))->collapse(); // Drop all existing policies to check if the command creates policies for multiple tables @@ -128,7 +128,9 @@ test('correct rls policies get created', function () { // Check if all tables with policies are RLS protected (even the ones not directly related to the tenant) // Models related to tenant through some model must use the BelongsToPrimaryModel trait // For the command to create the policy correctly for the model's table - expect($getRlsPolicies())->toHaveCount(count($tenantModels)); // 2 + expect($getRlsPolicies()) + ->toContain(...$tenantModels->map(fn (Model $model) => $model->getTable() . '_rls_policy', )) + ->toHaveCount(count($tenantModels)); // 2 expect($getRlsTables())->toHaveCount(count($tenantModels)); // 2 foreach ($getRlsTables() as $table) {