mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 10:24:03 +00:00
test: Add unit test for dropRLSPolicies to verify removal of PostgreSQL policies
This commit is contained in:
parent
712d7aabec
commit
9f0328f9ef
1 changed files with 18 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ use Stancl\Tenancy\Commands\CreateUserWithRLSPolicies;
|
|||
use Stancl\Tenancy\RLS\PolicyManagers\TableRLSManager;
|
||||
use Stancl\Tenancy\RLS\PolicyManagers\TraitRLSManager;
|
||||
use Stancl\Tenancy\Bootstrappers\PostgresRLSBootstrapper;
|
||||
use Stancl\Tenancy\Tenancy;
|
||||
use function Stancl\Tenancy\Tests\pest;
|
||||
|
||||
beforeEach(function () {
|
||||
|
|
@ -189,6 +190,23 @@ test('rls command recreates policies if the force option is passed', function (s
|
|||
TraitRLSManager::class,
|
||||
]);
|
||||
|
||||
test('dropRLSPolicies removes postgres policies', function () {
|
||||
// create dummy policy with characters that require quoting to ensure identifier handling works
|
||||
DB::statement('CREATE POLICY "comments_rls_policy_manual" ON comments USING (true)');
|
||||
|
||||
$policyCount = fn () => count(DB::select(
|
||||
'SELECT policyname FROM pg_policies WHERE tablename = ? AND policyname = ?',
|
||||
['comments', 'comments_rls_policy_manual']
|
||||
));
|
||||
|
||||
expect($policyCount())->toBe(1);
|
||||
|
||||
$removed = Tenancy::dropRLSPolicies('comments');
|
||||
|
||||
expect($removed)->toBe(1);
|
||||
expect($policyCount())->toBe(0);
|
||||
});
|
||||
|
||||
test('queries will stop working when the tenant session variable is not set', function(string $manager, bool $forceRls) {
|
||||
CreateUserWithRLSPolicies::$forceRls = $forceRls;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue