1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-09-20 15:14:03 +00:00

Forget scoped disk's parent no matter how nested it is

This includes moving the TenantAssetController baseDiskName() method to FSBootstrapper and making it public static, since the same logic is used in two places now. Also cover the edge case where a scoped disk A has a scoped disk B as its parent, and B has A as its parent -- in that case, the method would be stuck in an infinite loop (also added separate test for this, commenting out the $visited-related code in baseDiskName will make the test fail).

Also updated the assetRoot's unnamed disk exception message.
This commit is contained in:
lukinovec 2026-09-03 16:16:27 +02:00 committed by Samuel Stancl
parent e20085588b
commit 9cda4cb3e4
4 changed files with 63 additions and 24 deletions

View file

@ -356,6 +356,31 @@ test('adding a scoped disk to tenancy.filesystem.disks has no effect on the disk
]);
});
test('scoped disks referencing each other do not make bootstrapper hang', function () {
config([
'tenancy.bootstrappers' => [
FilesystemTenancyBootstrapper::class,
],
'filesystems.disks.foo' => [
'driver' => 'scoped',
'disk' => 'bar',
'prefix' => 'foo',
],
'filesystems.disks.bar' => [
'driver' => 'scoped',
'disk' => 'foo',
'prefix' => 'bar',
],
]);
expect(FilesystemTenancyBootstrapper::baseDiskName('foo'))->toBeNull();
expect(FilesystemTenancyBootstrapper::baseDiskName('bar'))->toBeNull();
tenancy()->initialize(Tenant::create());
expect(tenant())->not()->toBeNull();
});
test('file cache stores get their paths scoped on bootstrap and restored back on revert', function () {
$fooPath = storage_path('framework/cache/foo_file');
$barPath = storage_path('framework/cache/bar_file');

View file

@ -199,7 +199,7 @@ test('tenant asset controller throws when the disk used for serving assets is no
})->with([
'disk' => ['media', 'Disk [media] is not tenant-aware.'],
'scoped disk' => ['scoped_media', 'Disk [media] is not tenant-aware.'],
'scoped disk with an inline parent disk' => ['inline_scoped_media', 'Disk [inline_scoped_media] has its parent disk configured inline.'],
'scoped disk with an inline parent disk' => ['inline_scoped_media', 'Disk [inline_scoped_media] has an unnamed parent disk.'],
]);
test('tenant assets are served from the resolved root of a scoped disk', function () {