TenantAtlas/tests/Feature/Hardening/RestoreStartGateBypassTest.php
ahmido 0dc79520a4 feat: provider access hardening (RBAC write gate) (#132)
Implements provider access hardening for Intune write operations:

- RBAC-based write gate with configurable staleness thresholds
- Gate enforced at restore start and in jobs (execute + assignments)
- UI affordances: disabled rerun action, tenant RBAC status card, refresh RBAC action
- Audit logging for blocked writes
- Ops UX label: `rbac.health_check` now displays as “RBAC health check”
- Adds/updates Pest tests and SpecKit artifacts for feature 108

Notes:
- Filament v5 / Livewire v4 compliant.
- Destructive actions require confirmation.
- Assets: no new global assets.

Tested:
- `vendor/bin/sail artisan test --compact` (suite previously green) + focused OpsUx tests for OperationCatalog labels.
- `vendor/bin/sail bin pint --dirty`.

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #132
2026-02-23 00:49:37 +00:00

46 lines
1.4 KiB
PHP

<?php
use App\Contracts\Hardening\WriteGateInterface;
use App\Models\Tenant;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Log;
uses(RefreshDatabase::class);
test('gate bypasses when disabled and logs warning', function () {
config()->set('tenantpilot.hardening.intune_write_gate.enabled', false);
$tenant = Tenant::factory()->create([
'rbac_status' => null,
'rbac_last_checked_at' => null,
]);
Log::shouldReceive('warning')
->once()
->withArgs(function (string $message, array $context) use ($tenant): bool {
return str_contains($message, 'write gate is disabled')
&& ($context['tenant_id'] ?? null) === $tenant->getKey()
&& ($context['operation_type'] ?? null) === 'restore.execute';
});
$gate = app(WriteGateInterface::class);
// Should not throw even with null rbac_status
$gate->evaluate($tenant, 'restore.execute');
expect(true)->toBeTrue();
});
test('wouldBlock returns false when gate is disabled', function () {
config()->set('tenantpilot.hardening.intune_write_gate.enabled', false);
$tenant = Tenant::factory()->create([
'rbac_status' => null,
'rbac_last_checked_at' => null,
]);
Log::shouldReceive('warning')->once();
expect(app(WriteGateInterface::class)->wouldBlock($tenant))->toBeFalse();
});