mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 02:54:03 +00:00
Test data separation with comment constraints
This commit is contained in:
parent
1d87e4b00f
commit
df0d96f9bf
1 changed files with 12 additions and 4 deletions
|
|
@ -165,15 +165,22 @@ test('correct rls policies get created with the correct hash using table manager
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('queries are correctly scoped using RLS', function (bool $forceRls) {
|
test('queries are correctly scoped using RLS', function (
|
||||||
|
bool $forceRls,
|
||||||
|
bool $commentConstraint,
|
||||||
|
) {
|
||||||
CreateUserWithRLSPolicies::$forceRls = $forceRls;
|
CreateUserWithRLSPolicies::$forceRls = $forceRls;
|
||||||
|
|
||||||
// 3-levels deep relationship
|
// 3-levels deep relationship
|
||||||
Schema::create('notes', function (Blueprint $table) {
|
Schema::create('notes', function (Blueprint $table) use ($commentConstraint) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('text')->default('foo');
|
$table->string('text')->default('foo');
|
||||||
// no rls comment needed, $scopeByDefault is set to true
|
// no rls comment needed, $scopeByDefault is set to true
|
||||||
$table->foreignId('comment_id')->onUpdate('cascade')->onDelete('cascade')->constrained('comments');
|
if ($commentConstraint) {
|
||||||
|
$table->foreignId('comment_id')->comment('rls comments.id');
|
||||||
|
} else {
|
||||||
|
$table->foreignId('comment_id')->constrained('comments');
|
||||||
|
}
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -328,7 +335,8 @@ test('queries are correctly scoped using RLS', function (bool $forceRls) {
|
||||||
|
|
||||||
expect(fn () => DB::statement("INSERT INTO notes (text, comment_id) VALUES ('baz', {$post1Comment->id})"))
|
expect(fn () => DB::statement("INSERT INTO notes (text, comment_id) VALUES ('baz', {$post1Comment->id})"))
|
||||||
->toThrow(QueryException::class);
|
->toThrow(QueryException::class);
|
||||||
})->with([true, false]);
|
})->with(['forceRls is true' => true, 'forceRls is false' => false])
|
||||||
|
->with(['comment constraint' => true, 'real constraint' => false]);
|
||||||
|
|
||||||
test('table rls manager generates shortest paths that lead to the tenants table correctly', function (bool $scopeByDefault) {
|
test('table rls manager generates shortest paths that lead to the tenants table correctly', function (bool $scopeByDefault) {
|
||||||
TableRLSManager::$scopeByDefault = $scopeByDefault;
|
TableRLSManager::$scopeByDefault = $scopeByDefault;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue