TenantAtlas/apps/platform/tests/Feature/Providers/ProviderConnectionTargetScopeNeutralityTest.php
ahmido eceeee9c5c Complete Spec 287 prerequisite cutover (#346)
## Summary
- retire the remaining tenant-scoped provider-connection legacy routes and update canonical verification and link behavior
- complete the provider target-scope fallback cleanup so neutral shared scope data falls back to the managed environment when the raw connection tenant identifier is blank
- stop mirroring workspace roles into managed-environment scope persistence and cut the targeted admin-panel test helpers over to the post-cutover context path
- add and update the Spec 287 artifact package and targeted regression coverage for route retirement, provider-core neutralization, workspace-first RBAC, and helper cutover

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/ProviderConnections/LegacyRedirectTest.php tests/Feature/ProviderConnections/TenantlessListRouteTest.php tests/Feature/ProviderConnections/TenantlessListScopingTest.php tests/Feature/Auth/WorkspaceFirstManagedEnvironmentAccessTest.php tests/Feature/Rbac/ProviderConnectionWorkspaceFirstPolicyTest.php tests/Feature/Reviews/CustomerReviewWorkspaceLaunchLinksTest.php tests/Feature/Rbac/TriageReviewStateAuthorizationTest.php`
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Browser/Spec281ProviderConnectionScopeSmokeTest.php tests/Browser/Spec285WorkspaceRbacEnvironmentAccessSmokeTest.php`
- `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent`

## Notes
- Filament remains on Livewire v4 and provider registration stays unchanged in `apps/platform/bootstrap/providers.php`.
- No new asset registration or deployment-step changes are included in this slice.

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #346
2026-05-10 18:22:34 +00:00

99 lines
4.3 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\ProviderConnection;
use App\Models\ManagedEnvironment;
use App\Services\Providers\ProviderConnectionResolver;
use App\Support\Providers\TargetScope\ProviderConnectionSurfaceSummary;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('resolves provider connections and summaries through one neutral target-scope contract', function (): void {
config()->set('graph.client_id', 'platform-client-id');
config()->set('graph.client_secret', 'platform-client-secret');
[, $tenant] = createUserWithTenant(role: 'owner', ensureDefaultMicrosoftProviderConnection: false);
$connection = ProviderConnection::factory()
->platform()
->consentGranted()
->create([
'workspace_id' => (int) $tenant->workspace_id,
'managed_environment_id' => (int) $tenant->getKey(),
'provider' => 'microsoft',
'display_name' => 'Spec 281 provider connection',
'entra_tenant_id' => '11111111-1111-1111-1111-111111111111',
'is_default' => true,
'is_enabled' => true,
'verification_status' => 'healthy',
]);
$resolution = app(ProviderConnectionResolver::class)
->validateConnection($tenant, 'microsoft', $connection->fresh(['tenant']));
$summary = ProviderConnectionSurfaceSummary::forConnection($connection->fresh(['tenant']));
$summaryPayload = $summary->toArray();
expect($resolution->resolved)->toBeTrue()
->and($resolution->targetScope?->toArray())->toMatchArray([
'provider' => 'microsoft',
'scope_kind' => 'tenant',
'scope_identifier' => '11111111-1111-1111-1111-111111111111',
'shared_label' => 'Target scope',
])
->and($resolution->targetScope?->toArray())->not->toHaveKey('entra_tenant_id')
->and($summaryPayload['provider'])->toBe('microsoft')
->and($summaryPayload['target_scope'] ?? [])->toMatchArray([
'scope_identifier' => '11111111-1111-1111-1111-111111111111',
])
->and($summaryPayload['provider_context'] ?? [])->toMatchArray([
'provider' => 'microsoft',
])
->and($summaryPayload['target_scope'])->not->toHaveKey('entra_tenant_id')
->and($summaryPayload['provider_context']['details'][0] ?? [])->toMatchArray([
'detail_key' => 'microsoft_tenant_id',
'detail_value' => '11111111-1111-1111-1111-111111111111',
]);
});
it('falls back to the managed environment provider scope when the connection tenant identifier is blank', function (): void {
config()->set('graph.client_id', 'platform-client-id');
config()->set('graph.client_secret', 'platform-client-secret');
$tenant = ManagedEnvironment::factory()->create([
'name' => 'Fallback scope environment',
'managed_environment_id' => '66666666-6666-6666-6666-666666666666',
]);
$connection = ProviderConnection::factory()
->platform()
->consentGranted()
->create([
'workspace_id' => (int) $tenant->workspace_id,
'managed_environment_id' => (int) $tenant->getKey(),
'provider' => 'microsoft',
'display_name' => 'Fallback scope connection',
'entra_tenant_id' => '',
'is_default' => true,
'is_enabled' => true,
'verification_status' => 'healthy',
]);
$resolution = app(ProviderConnectionResolver::class)
->validateConnection($tenant, 'microsoft', $connection->fresh(['tenant']));
$summaryPayload = ProviderConnectionSurfaceSummary::forConnection($connection->fresh(['tenant']))->toArray();
expect($resolution->resolved)->toBeTrue()
->and($resolution->targetScope?->scopeIdentifier)->toBe('66666666-6666-6666-6666-666666666666')
->and($summaryPayload['target_scope'] ?? [])->toMatchArray([
'scope_identifier' => '66666666-6666-6666-6666-666666666666',
'scope_display_name' => 'Fallback scope environment',
])
->and($summaryPayload['provider_context']['details'][0] ?? [])->toMatchArray([
'detail_key' => 'microsoft_tenant_id',
'detail_value' => '66666666-6666-6666-6666-666666666666',
])
->and($summaryPayload['target_scope'])->not->toHaveKey('entra_tenant_id');
});