fix: highlight deviceComplianceScript diffs
This commit is contained in:
parent
ad7e32c4fc
commit
105241d6ae
@ -58,7 +58,7 @@
|
||||
|
||||
$canHighlightScripts = static function (?string $policyType): bool {
|
||||
return (bool) config('tenantpilot.display.show_script_content', false)
|
||||
&& in_array($policyType, ['deviceManagementScript', 'deviceShellScript', 'deviceHealthScript'], true);
|
||||
&& in_array($policyType, ['deviceManagementScript', 'deviceShellScript', 'deviceHealthScript', 'deviceComplianceScript'], true);
|
||||
};
|
||||
|
||||
$selectGrammar = static function (?string $policyType, string $code): string {
|
||||
|
||||
@ -131,3 +131,68 @@
|
||||
? 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=');
|
||||
|
||||
$this->actingAs(User::factory()->create());
|
||||
|
||||
config([
|
||||
'tenantpilot.display.show_script_content' => true,
|
||||
'tenantpilot.display.max_script_content_chars' => 5000,
|
||||
]);
|
||||
|
||||
$tenant = Tenant::factory()->create();
|
||||
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]);
|
||||
|
||||
$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');
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user