Implements Spec 081 provider-connection cutover. Highlights: - Adds provider connection resolution + gating for operations/verification. - Adds provider credential observer wiring. - Updates Filament tenant verify flow to block with next-steps when provider connection isn’t ready. - Adds spec docs under specs/081-provider-connection-cutover/ and extensive Spec081 test coverage. Tests: - vendor/bin/sail artisan test --compact tests/Feature/Filament/TenantSetupTest.php - Focused suites for ProviderConnections/Verification ran during implementation (see local logs). Co-authored-by: Ahmed Darrazi <ahmeddarrazi@MacBookPro.fritz.box> Reviewed-on: #98
92 lines
2.8 KiB
PHP
92 lines
2.8 KiB
PHP
<?php
|
|
|
|
use App\Models\ProviderConnection;
|
|
use App\Models\Tenant;
|
|
use App\Support\Providers\ProviderReasonCodes;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('stores successful admin consent on provider connection status', function () {
|
|
$tenant = Tenant::create([
|
|
'tenant_id' => 'tenant-1',
|
|
'name' => 'Contoso',
|
|
]);
|
|
|
|
$response = $this->get(route('admin.consent.callback', [
|
|
'tenant' => $tenant->tenant_id,
|
|
'admin_consent' => 'true',
|
|
]));
|
|
|
|
$response->assertOk();
|
|
|
|
$connection = ProviderConnection::query()
|
|
->where('tenant_id', (int) $tenant->getKey())
|
|
->where('provider', 'microsoft')
|
|
->where('entra_tenant_id', $tenant->graphTenantId())
|
|
->first();
|
|
|
|
expect($connection)->not->toBeNull()
|
|
->and($connection?->status)->toBe('connected')
|
|
->and($connection?->last_error_reason_code)->toBeNull();
|
|
|
|
$this->assertDatabaseHas('audit_logs', [
|
|
'tenant_id' => $tenant->id,
|
|
'action' => 'tenant.consent.callback',
|
|
'status' => 'success',
|
|
]);
|
|
});
|
|
|
|
it('creates tenant and provider connection when callback tenant does not exist', function () {
|
|
$response = $this->get(route('admin.consent.callback', [
|
|
'tenant' => 'new-tenant',
|
|
'state' => 'state-456',
|
|
]));
|
|
|
|
$response->assertOk();
|
|
|
|
$tenant = Tenant::where('tenant_id', 'new-tenant')->first();
|
|
expect($tenant)->not->toBeNull();
|
|
|
|
$connection = ProviderConnection::query()
|
|
->where('tenant_id', (int) $tenant->id)
|
|
->where('provider', 'microsoft')
|
|
->where('entra_tenant_id', $tenant->graphTenantId())
|
|
->first();
|
|
|
|
expect($connection)->not->toBeNull()
|
|
->and($connection?->status)->toBe('needs_consent')
|
|
->and($connection?->last_error_reason_code)->toBe(ProviderReasonCodes::ProviderConsentMissing);
|
|
});
|
|
|
|
it('records consent callback errors on provider connection state', function () {
|
|
$tenant = Tenant::create([
|
|
'tenant_id' => 'tenant-2',
|
|
'name' => 'Fabrikam',
|
|
]);
|
|
|
|
$response = $this->get(route('admin.consent.callback', [
|
|
'tenant' => $tenant->tenant_id,
|
|
'error' => 'access_denied',
|
|
]));
|
|
|
|
$response->assertOk();
|
|
|
|
$connection = ProviderConnection::query()
|
|
->where('tenant_id', (int) $tenant->getKey())
|
|
->where('provider', 'microsoft')
|
|
->where('entra_tenant_id', $tenant->graphTenantId())
|
|
->first();
|
|
|
|
expect($connection)->not->toBeNull()
|
|
->and($connection?->status)->toBe('error')
|
|
->and($connection?->last_error_reason_code)->toBe(ProviderReasonCodes::ProviderAuthFailed)
|
|
->and($connection?->last_error_message)->toBe('access_denied');
|
|
|
|
$this->assertDatabaseHas('audit_logs', [
|
|
'tenant_id' => $tenant->id,
|
|
'action' => 'tenant.consent.callback',
|
|
'status' => 'error',
|
|
]);
|
|
});
|