42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
it('guards Filament::setTenant usage behind an explicit infrastructure allowlist', function (): void {
|
|
$allowlist = [
|
|
base_path('app/Support/OperateHub/OperateHubShell.php'),
|
|
base_path('app/Support/Middleware/EnsureEnvironmentContextSelected.php'),
|
|
base_path('app/Filament/Pages/Monitoring/Operations.php'),
|
|
base_path('app/Http/Controllers/SwitchWorkspaceController.php'),
|
|
base_path('app/Http/Controllers/ClearEnvironmentContextController.php'),
|
|
];
|
|
|
|
$violations = [];
|
|
|
|
foreach (File::allFiles(base_path('app')) as $file) {
|
|
$realPath = $file->getRealPath();
|
|
|
|
if (! is_string($realPath)) {
|
|
continue;
|
|
}
|
|
|
|
$contents = File::get($realPath);
|
|
|
|
if (! str_contains($contents, 'Filament::setTenant(')) {
|
|
continue;
|
|
}
|
|
|
|
if (! in_array($realPath, $allowlist, true)) {
|
|
$violations[] = str_replace(base_path().DIRECTORY_SEPARATOR, '', $realPath);
|
|
}
|
|
}
|
|
|
|
if ($violations !== []) {
|
|
test()->fail("Unexpected Filament::setTenant usage detected:\n- ".implode("\n- ", $violations));
|
|
}
|
|
|
|
expect($violations)->toBeEmpty();
|
|
});
|