Summary Consolidates the “Tenant Operate Hub” work (Spec 085) and the follow-up adjustments from the 086 session merge into a single branch ready to merge into dev. Primary focus: stabilize Ops/Operate Hub UX flows, tighten/align authorization semantics, and make the full Sail test suite green. Key Changes Ops UX / Verification Readonly members can view verification operation runs (reports) while starting verification remains restricted. Normalized failure reason-code handling and aligned UX expectations with the provider reason-code taxonomy. Onboarding wizard UX “Start verification” CTA is hidden while a verification run is active; “Refresh” is shown during in-progress runs. Treats provider_permission_denied as a blocking reason (while keeping legacy compatibility). Test + fixture hardening Standardized use of default provider connection fixtures in tests where sync/restore flows require it. Fixed multiple Filament URL/tenant-context test cases to avoid 404s and reduce tenancy routing brittleness. Policy sync / restore safety Enrollment configuration type collision classification tests now exercise the real sync path (with required provider connection present). Restore edge-case safety tests updated to reflect current provider-connection requirements. Testing vendor/bin/sail artisan test --compact (green) vendor/bin/sail bin pint --dirty (green) Notes Includes merged 086 session work already (no separate PR needed). Co-authored-by: Ahmed Darrazi <ahmeddarrazi@ebc83aaa-d947-4a08-b88e-bd72ac9645f7.fritz.box> Co-authored-by: Ahmed Darrazi <ahmeddarrazi@MacBookPro.fritz.box> Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.fritz.box> Reviewed-on: #103
198 lines
7.0 KiB
PHP
198 lines
7.0 KiB
PHP
<?php
|
|
|
|
use App\Models\Policy;
|
|
use App\Models\PolicyVersion;
|
|
use App\Models\Tenant;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('renders policy version normalized settings for script policies', function (string $policyType, string $odataType) {
|
|
$originalEnv = getenv('INTUNE_TENANT_ID');
|
|
putenv('INTUNE_TENANT_ID=');
|
|
|
|
$tenant = Tenant::factory()->create();
|
|
[$user, $tenant] = createUserWithTenant($tenant, role: 'owner');
|
|
$this->actingAs($user);
|
|
putenv('INTUNE_TENANT_ID='.$tenant->tenant_id);
|
|
$tenant->makeCurrent();
|
|
|
|
$policy = Policy::factory()->create([
|
|
'tenant_id' => $tenant->id,
|
|
'policy_type' => $policyType,
|
|
'platform' => 'all',
|
|
'display_name' => 'Script policy',
|
|
'external_id' => 'policy-1',
|
|
]);
|
|
|
|
config([
|
|
'tenantpilot.display.show_script_content' => true,
|
|
]);
|
|
|
|
$scriptContent = str_repeat('X', 20);
|
|
if ($policyType === 'deviceShellScript') {
|
|
$scriptContent = "#!/bin/zsh\n".str_repeat('X', 20);
|
|
}
|
|
|
|
$contentKey = in_array($policyType, ['deviceHealthScript', 'deviceComplianceScript'], true)
|
|
? 'detectionScriptContent'
|
|
: 'scriptContent';
|
|
|
|
$version = PolicyVersion::factory()->create([
|
|
'policy_id' => $policy->id,
|
|
'tenant_id' => $tenant->id,
|
|
'policy_type' => $policyType,
|
|
'snapshot' => [
|
|
'@odata.type' => $odataType,
|
|
'displayName' => 'Script policy',
|
|
'description' => 'desc',
|
|
$contentKey => $contentKey === 'scriptContent' ? $scriptContent : base64_encode($scriptContent),
|
|
],
|
|
]);
|
|
|
|
$this->get(\App\Filament\Resources\PolicyVersionResource::getUrl('index').'?tenant='.(string) $tenant->external_id)
|
|
->assertSuccessful();
|
|
|
|
$this->get(\App\Filament\Resources\PolicyVersionResource::getUrl('view', ['record' => $version]).'?tab=normalized-settings&tenant='.(string) $tenant->external_id)
|
|
->assertSuccessful();
|
|
|
|
$originalEnv !== false
|
|
? putenv("INTUNE_TENANT_ID={$originalEnv}")
|
|
: putenv('INTUNE_TENANT_ID');
|
|
})->with([
|
|
['deviceManagementScript', '#microsoft.graph.deviceManagementScript'],
|
|
['deviceShellScript', '#microsoft.graph.deviceShellScript'],
|
|
['deviceHealthScript', '#microsoft.graph.deviceHealthScript'],
|
|
['deviceComplianceScript', '#microsoft.graph.deviceComplianceScript'],
|
|
]);
|
|
|
|
it('renders diff tab with highlighted script content for script policies', function () {
|
|
$originalEnv = getenv('INTUNE_TENANT_ID');
|
|
putenv('INTUNE_TENANT_ID=');
|
|
|
|
config([
|
|
'tenantpilot.display.show_script_content' => true,
|
|
'tenantpilot.display.max_script_content_chars' => 5000,
|
|
]);
|
|
|
|
$tenant = Tenant::factory()->create();
|
|
[$user, $tenant] = createUserWithTenant($tenant, role: 'owner');
|
|
$this->actingAs($user);
|
|
putenv('INTUNE_TENANT_ID='.$tenant->tenant_id);
|
|
$tenant->makeCurrent();
|
|
|
|
$policy = \App\Models\Policy::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
'policy_type' => 'deviceManagementScript',
|
|
'platform' => 'windows',
|
|
]);
|
|
|
|
$scriptOne = "# test\n".str_repeat("Write-Host 'one'\n", 40);
|
|
$scriptTwo = "# test\n".str_repeat("Write-Host 'two'\n", 40);
|
|
|
|
$v1 = \App\Models\PolicyVersion::factory()->create([
|
|
'policy_id' => $policy->getKey(),
|
|
'tenant_id' => $tenant->getKey(),
|
|
'version_number' => 1,
|
|
'policy_type' => 'deviceManagementScript',
|
|
'platform' => 'windows',
|
|
'snapshot' => [
|
|
'@odata.type' => '#microsoft.graph.deviceManagementScript',
|
|
'displayName' => 'My script',
|
|
'scriptContent' => base64_encode($scriptOne),
|
|
],
|
|
]);
|
|
|
|
$v2 = \App\Models\PolicyVersion::factory()->create([
|
|
'policy_id' => $policy->getKey(),
|
|
'tenant_id' => $tenant->getKey(),
|
|
'version_number' => 2,
|
|
'policy_type' => 'deviceManagementScript',
|
|
'platform' => 'windows',
|
|
'snapshot' => [
|
|
'@odata.type' => '#microsoft.graph.deviceManagementScript',
|
|
'displayName' => 'My script',
|
|
'scriptContent' => base64_encode($scriptTwo),
|
|
],
|
|
]);
|
|
|
|
$url = \App\Filament\Resources\PolicyVersionResource::getUrl('view', ['record' => $v2]).'?tenant='.(string) $tenant->external_id;
|
|
|
|
$this->get($url.'&tab=diff')
|
|
->assertSuccessful()
|
|
->assertSeeText('Fullscreen')
|
|
->assertSeeText("- Write-Host 'one'")
|
|
->assertSeeText("+ Write-Host 'two'")
|
|
->assertSee('bg-danger-50', false)
|
|
->assertSee('bg-success-50', false);
|
|
|
|
$originalEnv !== false
|
|
? putenv("INTUNE_TENANT_ID={$originalEnv}")
|
|
: putenv('INTUNE_TENANT_ID');
|
|
});
|
|
|
|
it('renders diff tab with highlighted script content for device compliance scripts', function () {
|
|
$originalEnv = getenv('INTUNE_TENANT_ID');
|
|
putenv('INTUNE_TENANT_ID=');
|
|
|
|
config([
|
|
'tenantpilot.display.show_script_content' => true,
|
|
'tenantpilot.display.max_script_content_chars' => 5000,
|
|
]);
|
|
|
|
$tenant = Tenant::factory()->create();
|
|
[$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'owner');
|
|
$this->actingAs($user);
|
|
putenv('INTUNE_TENANT_ID='.$tenant->tenant_id);
|
|
$tenant->makeCurrent();
|
|
|
|
$policy = Policy::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
'policy_type' => 'deviceComplianceScript',
|
|
'platform' => 'windows',
|
|
]);
|
|
|
|
$scriptOne = "# test\n".str_repeat("Write-Host 'one'\n", 40);
|
|
$scriptTwo = "# test\n".str_repeat("Write-Host 'two'\n", 40);
|
|
|
|
$v1 = PolicyVersion::factory()->create([
|
|
'policy_id' => $policy->getKey(),
|
|
'tenant_id' => $tenant->getKey(),
|
|
'version_number' => 1,
|
|
'policy_type' => 'deviceComplianceScript',
|
|
'platform' => 'windows',
|
|
'snapshot' => [
|
|
'@odata.type' => '#microsoft.graph.deviceComplianceScript',
|
|
'displayName' => 'My compliance script',
|
|
'detectionScriptContent' => base64_encode($scriptOne),
|
|
],
|
|
]);
|
|
|
|
$v2 = PolicyVersion::factory()->create([
|
|
'policy_id' => $policy->getKey(),
|
|
'tenant_id' => $tenant->getKey(),
|
|
'version_number' => 2,
|
|
'policy_type' => 'deviceComplianceScript',
|
|
'platform' => 'windows',
|
|
'snapshot' => [
|
|
'@odata.type' => '#microsoft.graph.deviceComplianceScript',
|
|
'displayName' => 'My compliance script',
|
|
'detectionScriptContent' => base64_encode($scriptTwo),
|
|
],
|
|
]);
|
|
|
|
$url = \App\Filament\Resources\PolicyVersionResource::getUrl('view', ['record' => $v2]).'?tenant='.(string) $tenant->external_id;
|
|
|
|
$this->get($url.'&tab=diff')
|
|
->assertSuccessful()
|
|
->assertSeeText('Fullscreen')
|
|
->assertSeeText("- Write-Host 'one'")
|
|
->assertSeeText("+ Write-Host 'two'")
|
|
->assertSee('bg-danger-50', false)
|
|
->assertSee('bg-success-50', false);
|
|
|
|
$originalEnv !== false
|
|
? putenv("INTUNE_TENANT_ID={$originalEnv}")
|
|
: putenv('INTUNE_TENANT_ID');
|
|
});
|