1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-09-20 17:04:04 +00:00
Commit graph

1489 commits

Author SHA1 Message Date
lukinovec
823e5c34d6 Merge the 'served from the resolved root' tests 2026-09-08 18:18:54 +02:00
lukinovec
fe85fe45bd Merge 'not a local disk'/'not tenant-aware'/'unnamed parent' throwing tests into a single test 2026-09-08 18:11:41 +02:00
lukinovec
1abeb852de Merge the new "throws an exception when accessing a file in a directory whose name starts with the name of the asset root" test with the pre-existing one
"test asset controller returns a 404 when accessing a file outside the storage root" tested very similar things to the new test (which had some redundant config anyway). Merged these tests into one -- "tenant asset controller only serves files inside the asset root"
2026-09-08 17:54:20 +02:00
lukinovec
4af473ede5 Move falsy url_override assertions to more appropriate places 2026-09-08 16:59:23 +02:00
lukinovec
e3ba445630 Refactor scoped disk exception throwing tests, remove redundant test
"adding a scoped disk to tenancy.filesystem.disks throws an exception if its base disk is not listed" doesn't use a dataset and deal with inline baes disks anymore.

Added a separate test for scoped disks with inline base ("adding a scoped disk with an inline base disk to tenancy.filesystem.disks throws an exception").

Removed the "adding a scoped disk to tenancy.filesystem.disks has no effect on the disk when its base disk is listed too" test, it was mostly redundant.
2026-09-08 16:59:23 +02:00
lukinovec
e6d785a8d1 Refactor DeleteTenantStorage tests
Use the *original* 'tenant storage gets deleted during tenant deletion when the DeletingTenant pipeline contains DeleteTenantStorage' test and remove what's not necessary anymore. Also make it clear that enabling FS bootstrapper is not required for the deletion to work -- the tenant directory just has to exist.

Delete the nonsensical 'DeleteTenantStorage does not delete the central storage directory when the filesystem bootstrapper is disabled' test. That one was there to test that the central dir never gets deleted, but it was wrong. Added 'DeleteTenantStorage never deletes the central storage directory' which actually makes the job's realpath() comparison check pass and the job just returns.
2026-09-08 16:59:23 +02:00
lukinovec
45100453c5 Refactor scoped disks test
Remove redundant config(['filesystem.disks.public.prefix' => 'scoped_disk_prefix']); line, try making the test less dense.
2026-09-08 16:59:23 +02:00
lukinovec
496e0c36bd Improve TenantAssetController comments 2026-09-08 16:59:23 +02:00
lukinovec
45f6bc6b96 Fix getBoundTenantStoragePath -> getTenantStoragePath rename leftover 2026-09-07 18:32:15 -07:00
lukinovec
197ca18566 Simplify baseDiskName()
Refrain from dealing with the impossible "self-referencing" scoped disk case. Instead of that, test the inline parent behavior.

Also update the exception message in forgetDisks() so that it's a bit less vague.
2026-09-07 18:32:15 -07:00
lukinovec
dde9be6f58 Throw an exception if a scoped disk is listed in tenant-aware disks without its base disk
In FSBootstrapper::forgetDisks():
- `tenancy.filesystem.disks => ['scoped']` throws
- `tenancy.filesystem.disks => ['scoped', 'parent']` does NOT throw
- `tenancy.filesystem.disks => ['scoped_with_scoped_parent', 'scoped_parent']` (invalid config where a scoped disk's base disk doesn't actually exist because the scoped disks just reference themselves) throws
2026-09-07 18:32:15 -07:00
lukinovec
e7c0193931 Add comment above $attemptedPath
At first glance, it could look weird that $attemptedPath uses "/" but the check in abortIf below uses DIRECTORY_SEPARATOR. Add comment that explains this.
2026-09-07 18:32:15 -07:00
efc0877f10 minor polish 2026-09-07 18:32:15 -07:00
lukinovec
394a9fa562 Explicitly skip scoped disks in diskRoot()
If diskRoot() somehow ended up receiving a scoped disk (e.g. in case the scoped disk was listed in tenancy.filesystem.disks), its root would get configured, and it'd be completely redundant. It wouldn't break anything since scoped disk's configured root is ignored -- its parent's root is always used. Even though not adding this skipping code would essentially do no harm, it prevents the method from doing redundant work and defines the behavior a bit more clearly.

diskUrl() is similar in that regard, but that method already has a strict "disk driver has to be 'local'" -- scoped disks never made it through so nothing to change there.
2026-09-07 18:32:15 -07:00
lukinovec
9cda4cb3e4 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.
2026-09-07 18:32:15 -07:00
lukinovec
e20085588b Assert that TenantAssetController throws for scoped disks with a non-local parent 2026-09-07 18:32:15 -07:00
lukinovec
2cd514c781 Test that listing scoped disks in tenancy.filesystem.disks is harmless (regression test)
FilesystemTenancyBootstrapper should only change config of the base/parent disks -- scoped disks should be ignored.
2026-09-07 18:32:15 -07:00
lukinovec
3936ab9eff Test that non-local scoped disks get scoped per tenant 2026-09-07 18:32:15 -07:00
lukinovec
ae91281d3a Assert that nested scoped disks are scoped properly (regression test)
The test fails with the nested disk dataset because we resolve a disk first, then initialize tenancy, and because the nested scoped disks aren't forgotten, so the disk config changes that the FS bootstrapper applies aren't reflected on the already-resolved disk instance.
2026-09-07 18:32:15 -07:00
lukinovec
e0e696f83e Throw an exception in TenantAssetController if the disk is not tenant-aware
Instead of just saying that the publicDisk *should* be listed in tenancy.filesystem.disks, enforce that -- if the disk isn't tenant-aware, throw an exception.

Also update comments accordingly. E.g. since scoped disks don't have to have a single "parent disk" (the parent can also be a scoped disk and have another parent, and so on), use "base disk".
2026-09-07 18:32:15 -07:00
lukinovec
041b023a95 Assert that TenantAssetController cannot serve assets from a disk that isn't tenant-aware (regression test) 2026-09-07 18:32:15 -07:00
lukinovec
99994dca85 Delete redundant comment 2026-09-07 18:32:15 -07:00
lukinovec
8e671fe5be Use "placed within" instead of "appended to" in log bootstrapper comment
In response to https://github.com/archtechx/tenancy/pull/1479#discussion_r3876808350
2026-09-07 18:32:15 -07:00
41f7e2e034 improve comments 2026-09-07 18:32:15 -07:00
lukinovec
bb12443fa6 Update src/Jobs/DeleteTenantStorage.php
Co-authored-by: Samuel Stancl <samuel@archte.ch>
2026-09-07 18:32:15 -07:00
lukinovec
2ef1ea94ed Make LogChannelBootstrapper not depend on suffixed storage_path()
Since the tenant storage path can now be grabbed using FilesystemTenancyBootstrapper::getBoundTenantStoragePath(), the log bootstrapper doesn't need to depend on the FSBootstrapper being enabled and storage_path() being suffixed.

Instead of adding a regression test, just delete FilesystemTenancyBootstrapper from the config settings in the log bootstrapper tests (and in tests that did use storage_path() in tenant context assertions, use explicitly "hardcoded" paths instead).
2026-09-07 18:32:15 -07:00
lukinovec
ae88836c0b Clarify TenantAssetController's docblock 2026-09-07 18:32:15 -07:00
github-actions[bot]
ae98ac3bd4 Fix code style (php-cs-fixer) 2026-09-07 18:32:15 -07:00
lukinovec
802022a926 Exercise the valid asset path before testing traversal
Request photo.jpg and assert success before asserting rejection of ../media-originals/photo.jpg

(addresses https://github.com/archtechx/tenancy/pull/1479#pullrequestreview-4984403598)
2026-09-07 18:32:15 -07:00
lukinovec
e70057e3ba Read the tenant asset root from the resolved disk instead of the disk config
Also, instead of throwing the "no root path configured" exception, just throw an exception if the disk is not local (i.e. is not instanceof LocalFilesystemAdapter). A local disk HAS to have a string root, otherwise, Laravel throws an exception while instantiating that disk.
2026-09-07 18:32:15 -07:00
lukinovec
efa8c03680 Assert that the tenant asset root is read from the resolved disk (regression tests)
Test that tenant assets can be served from scoped disks, and that tenant asset roots respect the disk's configured prefix.

Currently, the tests fail because TenantAssetController grabs the root from the config instead of resolving it via Storage::disk(...)->path('').
2026-09-07 18:32:15 -07:00
lukinovec
848736448c Clarify TenantAssetController docblock 2026-09-07 18:32:15 -07:00
lukinovec
9403d8c8fd Add afterEach cleanup to TenantAssetTest 2026-09-07 18:32:15 -07:00
lukinovec
5e54e3e7d9 Reword DeleteTenantStorage docblock
The docblock said that the FSBootstrapper was required for this job to work at all, but that's not fully true since the job just uses the FSBootstrapper's public static methods to get the storage paths.
2026-09-07 18:32:15 -07:00
lukinovec
4826667ac1 Add test that covers how tenant_asset() works when called in central context
Added to cover the `return storage_path('app/public')` line in TenantAssetController::assetRoot
2026-09-07 18:32:15 -07:00
lukinovec
1a693d8e36 Improve comments
Correct misleading ones, add ones that were missing (e.g. the TenantAssetController's docblock, the FSBootstrapper dependency should be mentioned there)
2026-09-07 18:32:15 -07:00
lukinovec
15144def3c Update tenancy.filesystem config docblocks
Briefly document the root_override placeholders, make the links point to v4 docs instead of the v3 ones. Also in the url_override comments, mention that local disks must have a valid root in order for the override to work correctly.
2026-09-07 18:32:15 -07:00
lukinovec
7ecb34f3fe Skip disks with *empty* url_override in diskUrl()
Previously, we only skipped disks with `null` override. But an override with an empty string is also incorrect, and simply checking if $this->app['config']["tenancy.filesystem.url_override.{$disk}"]) is falsy instead of strictly null takes care of that.
2026-09-07 18:32:15 -07:00
lukinovec
6b27bc5f36 Assert that disks with an empty url_override are skipped by both the FS bootstrapper and possibleTenantSymlinks (regression test)
Update the existing "create storage symlinks action skips disks with a null url_override" test so that it covers disks with NO url_override (unset/null and empty string). The test fails with the empty string override at the moment.
2026-09-07 18:32:15 -07:00
lukinovec
223b49a395 Correct FSBootstrapper and DeleteTenantStorage docblocks
getBoundTenantStoragePath() and DeleteTenantStorage both claimed the tenant storage directory is where disks, cache and sessions are scoped to. That's only true when root_override points there and scope_cache/scope_sessions are enabled -- a root_override using %original_storage_path% puts the disk root outside it entirely.
2026-09-07 18:32:15 -07:00
lukinovec
ae77c49985 Stop requiring a root_override in possibleTenantSymlinks
The symlink target used to be built from the root_override template, so a disk without an entry there had nothing to resolve.
The symlink target is now the disk's tenant-context root, which the bootstrapper sets either way -- with a root_override it expands
the template, without one, it appends the suffix to the disk's own root. Disks that only have a url_override now get a working symlink
instead of being skipped while their URL was still overridden.

Skipping disks with a null url_override is now explicit. The root_override check used to cover that by accident, and without it str_replace() gets null and throws a TypeError.
2026-09-07 18:32:15 -07:00
lukinovec
aad435da44 Assert that symlinks work without a root_override and that disks with a null url_override are skipped (regression test) 2026-09-07 18:32:15 -07:00
lukinovec
79484cac09 Make the suffix_storage_path config comment clearer
The comment said that disks, cache and sessions are scoped ot the tenant's storage dir either way, but that's only true if the disks are included in tenancy.filesystem.disks, and  for cache and sessions, scope_cache and scope_sessions have to be enabled. This might be obvious, but it'll be better to make this completely clear from the comment.
2026-09-07 18:32:15 -07:00
lukinovec
2bd590ef0e Correct the regression test 2026-09-07 18:32:15 -07:00
lukinovec
0eb2cf18a4 Throw an exception in possibleTenantSymlinks if the disk is not tenant-aware
When a disk in url_override and root_override is absent from tenancy.filesystem.disks, FilesystemTenancyBootstrapper leaves its root unchanged, possibleTenantSymlinks allows creating a symlink for that unscoped disk (= a disk with a central root), which can expose shared files.

Fixed by throwing an exception in possibleTenantSymlinks saying that the disk should be tenant-aware (= included in the tenancy.filesystem.disks config).
2026-09-07 18:32:15 -07:00
lukinovec
b6e6aa634c Assert that CreateStorageSymlinksAction cannot create symlinks for disks that are not in tenancy.filesystem.disks, i.e. aren't tenant-aware (regression test) 2026-09-07 18:32:15 -07:00
lukinovec
4e1fb850bc Require a directory boundary when checking that an asset is inside the asset root
The resolved path was compared to the asset root using a plain string prefix, so a
directory whose name just starts with the asset root's name passed the check. This
didn't matter while the asset root was hardcoded to app/public, but $publicDisk lets
it be any disk root.
2026-09-07 18:32:15 -07:00
lukinovec
ff3a2a3e2c Assert that the tenant asset controller only serves files inside the configured disk's root (regression test)
Currently this fails because the controller checks that the requested file is inside the
asset root using a plain string prefix, so with the root set to
'%storage_path%/app/media/', a request for '../media-originals/photo.jpg' is served
from the sibling 'app/media-originals' directory.
2026-09-07 18:32:15 -07:00
lukinovec
a9cdeb220b Fix the suffix_storage_path comment in the config
Disabling the config doesn't break local disk tenancy -- it only affects the
storage_path() helper. Disks, cache and sessions are scoped either way, so the
tradeoff is that files accessed using storage_path() are shared by all tenants.
2026-09-07 18:32:15 -07:00
lukinovec
c1e09fb25d Assert that DeleteTenantStorage does not delete the central storage directory when the FS bootstrapper is disabled
With the bootstrapper
disabled, the job resolves the path to a tenant directory that was never created,
so nothing gets deleted.
2026-09-07 18:32:15 -07:00