mirror of
https://github.com/archtechx/tenancy.git
synced 2026-06-21 01:34:04 +00:00
Improve hardening
Make hardening work correctly even for named SQLite DBs, also make the related test test named SQLite DBs instead of just MySQL (the SQLite dataset fails when the DatabaseTenancyBootstrapper changes get reverted).
This commit is contained in:
parent
7972da5475
commit
540e3635e2
2 changed files with 12 additions and 11 deletions
|
|
@ -63,7 +63,7 @@ test('harden prevents tenants from using the central database', function ($harde
|
|||
'hardening disabled' => false,
|
||||
]);
|
||||
|
||||
test('harden prevents tenants from using a database of another tenant', function ($harden) {
|
||||
test('harden prevents tenants from using a database of another tenant', function (bool $harden, string $connection) {
|
||||
config([
|
||||
'tenancy.bootstrappers' => [DatabaseTenancyBootstrapper::class],
|
||||
]);
|
||||
|
|
@ -74,15 +74,13 @@ test('harden prevents tenants from using a database of another tenant', function
|
|||
return $event->tenant;
|
||||
})->toListener());
|
||||
|
||||
$tenant = Tenant::create();
|
||||
$tenant = Tenant::create(['tenancy_db_connection' => $connection]);
|
||||
|
||||
Tenant::create([
|
||||
'tenancy_db_name' => $tenantDbName = 'foo' . Str::random(8),
|
||||
]);
|
||||
$dbName = Str::random(8) . ($connection === 'sqlite' ? '.sqlite' : '');
|
||||
|
||||
$tenant->update([
|
||||
'tenancy_db_name' => $tenantDbName, // Database of another tenant
|
||||
]);
|
||||
Tenant::create(['tenancy_db_name' => $dbName, 'tenancy_db_connection' => $connection]);
|
||||
|
||||
$tenant->update(['tenancy_db_name' => $dbName]);
|
||||
|
||||
if ($harden) {
|
||||
// Harden blocks initialization for tenants that use a database of another tenant
|
||||
|
|
@ -99,6 +97,9 @@ test('harden prevents tenants from using a database of another tenant', function
|
|||
})->with([
|
||||
'hardening enabled' => true,
|
||||
'hardening disabled' => false,
|
||||
])->with([
|
||||
'mysql' => 'mysql',
|
||||
'named sqlite' => 'sqlite',
|
||||
]);
|
||||
|
||||
test('database tenancy bootstrapper throws an exception if DATABASE_URL is set', function (string|null $databaseUrl) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue