mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 13:54:04 +00:00
Add test for creating RLS policies for tables
This commit is contained in:
parent
9f4079e774
commit
4ceb7c82e1
2 changed files with 17 additions and 2 deletions
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use Stancl\Tenancy\CacheManager;
|
|
||||||
use Stancl\Tenancy\Middleware;
|
use Stancl\Tenancy\Middleware;
|
||||||
use Stancl\Tenancy\Resolvers;
|
use Stancl\Tenancy\Resolvers;
|
||||||
|
|
||||||
|
|
@ -11,6 +10,10 @@ return [
|
||||||
* Configuration for the models used by Tenancy.
|
* Configuration for the models used by Tenancy.
|
||||||
*/
|
*/
|
||||||
'models' => [
|
'models' => [
|
||||||
|
'rls' => [
|
||||||
|
// The tenants:create-rls-policies comand will create RLS policies
|
||||||
|
// For tables of the models specified here
|
||||||
|
],
|
||||||
'tenant' => Stancl\Tenancy\Database\Models\Tenant::class,
|
'tenant' => Stancl\Tenancy\Database\Models\Tenant::class,
|
||||||
'domain' => Stancl\Tenancy\Database\Models\Domain::class,
|
'domain' => Stancl\Tenancy\Database\Models\Domain::class,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,13 @@ declare(strict_types=1);
|
||||||
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||||
use Stancl\Tenancy\Jobs\CreatePostgresUserForTenant;
|
|
||||||
use Stancl\Tenancy\Jobs\DeleteTenantsPostgresUser;
|
use Stancl\Tenancy\Jobs\DeleteTenantsPostgresUser;
|
||||||
|
use Stancl\Tenancy\Jobs\CreatePostgresUserForTenant;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
DB::setDefaultConnection('pgsql');
|
DB::setDefaultConnection('pgsql');
|
||||||
|
|
||||||
|
config(['tenancy.models.tenant' => Tenant::class]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('postgres user can get created using the job', function() {
|
test('postgres user can get created using the job', function() {
|
||||||
|
|
@ -40,5 +42,15 @@ test('postgres user can get deleted using the job', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('correct rls policies get created using the command', function() {
|
test('correct rls policies get created using the command', function() {
|
||||||
|
config([
|
||||||
|
'tenancy.models.rls' => $rlsModels = [
|
||||||
|
Post::class, // Primary model (directly belongs to tenant)
|
||||||
|
Comment::class, // Secondary model (belongs to tenant through Post)
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
$getRlsPolicies = fn () => DB::select('select * from pg_policies');
|
||||||
|
|
||||||
|
expect($getRlsPolicies())->toHaveCount(0);
|
||||||
|
pest()->artisan('tenants:create-rls-policies');
|
||||||
|
expect($getRlsPolicies())->toHaveCount(count($rlsModels));
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue