TenantAtlas/apps/platform/tests/Feature/Auth/AdminLocalSmokeLoginTest.php
ahmido acc8947384 feat: harden governance action semantics (#229)
## Summary
- add the Spec 194 governance action catalog, friction classes, reason policies, and regression guards
- align exception, review, evidence, finding, tenant, provider connection, and system run actions to the shared semantics model
- add focused feature, RBAC, audit, unit, and browser coverage, including the tenant detail triage header consistency update

## Verification
- ran the focused Spec 194 verification pack from the quickstart and task plan
- ran targeted tenant triage coverage after the detail-header update
- ran `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent`

## Filament Notes
- Filament v5 / Livewire v4 compliance preserved
- provider registration remains in `apps/platform/bootstrap/providers.php`
- globally searchable resources were not changed
- destructive actions remain confirmation-gated and server-authorized
- no new Filament assets were introduced; the existing `cd apps/platform && php artisan filament:assets` deploy step stays unchanged

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #229
2026-04-12 21:21:44 +00:00

93 lines
3.1 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Pages\TenantDashboard;
use App\Http\Middleware\SuppressDebugbarForSmokeRequests;
use Barryvdh\Debugbar\LaravelDebugbar;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
uses(RefreshDatabase::class);
it('logs into the admin smoke helper with explicit tenant and workspace context', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner', workspaceRole: 'manager');
$response = $this->get(route('admin.local.smoke-login', [
'email' => $user->email,
'tenant' => $tenant->external_id,
'workspace' => $tenant->workspace->slug,
]));
$response
->assertRedirect(TenantDashboard::getUrl(tenant: $tenant))
->assertPlainCookie(
SuppressDebugbarForSmokeRequests::COOKIE_NAME,
SuppressDebugbarForSmokeRequests::COOKIE_VALUE,
);
$this->assertAuthenticatedAs($user);
expect(session(App\Support\Workspaces\WorkspaceContext::SESSION_KEY))->toBe((int) $tenant->workspace_id)
->and(session(SuppressDebugbarForSmokeRequests::SESSION_KEY))
->toBe(SuppressDebugbarForSmokeRequests::COOKIE_VALUE)
->and(data_get(session(App\Support\Workspaces\WorkspaceContext::LAST_TENANT_IDS_SESSION_KEY), (string) $tenant->workspace_id))
->toBe((int) $tenant->getKey());
$this->get(TenantDashboard::getUrl(tenant: $tenant))->assertSuccessful();
});
it('suppresses debugbar only for smoke-cookie requests and restores normal state afterward', function (): void {
config(['debugbar.enabled' => true]);
Route::middleware('web')->get('/__tests/smoke-debugbar-state', function () {
$debugbarState = null;
if (app()->bound('debugbar')) {
$debugbar = app('debugbar');
if ($debugbar instanceof LaravelDebugbar) {
$debugbarState = $debugbar->isEnabled();
}
}
return response()->json([
'config_enabled' => (bool) config('debugbar.enabled'),
'service_enabled' => $debugbarState,
]);
});
$smokeResponse = $this->withUnencryptedCookies([
SuppressDebugbarForSmokeRequests::COOKIE_NAME => SuppressDebugbarForSmokeRequests::COOKIE_VALUE,
])->get('/__tests/smoke-debugbar-state');
$smokeResponse
->assertSuccessful()
->assertJsonPath('config_enabled', false);
if ($smokeResponse->json('service_enabled') !== null) {
expect($smokeResponse->json('service_enabled'))->toBeFalse();
}
config(['debugbar.enabled' => true]);
if (app()->bound('debugbar')) {
$debugbar = app('debugbar');
if ($debugbar instanceof LaravelDebugbar) {
$debugbar->enable();
}
}
$normalMiddlewareState = null;
$middleware = app(SuppressDebugbarForSmokeRequests::class);
$middleware->handle(Request::create('/admin/operations', 'GET'), function () use (&$normalMiddlewareState) {
$normalMiddlewareState = config('debugbar.enabled');
return response('ok');
});
expect($normalMiddlewareState)->toBeTrue();
});