TenantAtlas/apps/platform/tests/Unit/ScriptsPolicyNormalizerTest.php
ahmido ce0615a9c1 Spec 182: relocate Laravel platform to apps/platform (#213)
## Summary
- move the Laravel application into `apps/platform` and keep the repository root for orchestration, docs, and tooling
- update the local command model, Sail/Docker wiring, runtime paths, and ignore rules around the new platform location
- add relocation quickstart/contracts plus focused smoke coverage for bootstrap, command model, routes, and runtime behavior

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/PlatformRelocation`
- integrated browser smoke validated `/up`, `/`, `/admin`, `/admin/choose-workspace`, and tenant route semantics for `200`, `403`, and `404`

## Remaining Rollout Checks
- validate Dokploy build context and working-directory assumptions against the new `apps/platform` layout
- confirm web, queue, and scheduler processes all start from the expected working directory in staging/production
- verify no legacy volume mounts or asset-publish paths still point at the old root-level `public/` or `storage/` locations

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #213
2026-04-08 08:40:47 +00:00

166 lines
5.6 KiB
PHP

<?php
use App\Services\Intune\PolicyNormalizer;
it('normalizes deviceManagementScript into readable settings', function () {
$normalizer = app(PolicyNormalizer::class);
$snapshot = [
'@odata.type' => '#microsoft.graph.deviceManagementScript',
'displayName' => 'My PS script',
'description' => 'Does a thing',
'scriptContent' => str_repeat('A', 10),
'runFrequency' => 'weekly',
];
$result = $normalizer->normalize($snapshot, 'deviceManagementScript', 'windows');
expect($result['status'])->toBe('ok');
expect($result['settings'])->toBeArray()->not->toBeEmpty();
expect($result['settings'][0]['type'])->toBe('keyValue');
expect(collect($result['settings'][0]['entries'])->pluck('key')->all())->toContain('Display name');
});
it('normalizes deviceShellScript into readable settings', function () {
$normalizer = app(PolicyNormalizer::class);
$snapshot = [
'@odata.type' => '#microsoft.graph.deviceShellScript',
'displayName' => 'My macOS shell script',
'scriptContent' => str_repeat('B', 5),
];
$result = $normalizer->normalize($snapshot, 'deviceShellScript', 'macOS');
expect($result['status'])->toBe('ok');
expect($result['settings'])->toBeArray()->not->toBeEmpty();
expect($result['settings'][0]['type'])->toBe('keyValue');
});
it('normalizes deviceHealthScript into readable settings', function () {
$normalizer = app(PolicyNormalizer::class);
$snapshot = [
'@odata.type' => '#microsoft.graph.deviceHealthScript',
'displayName' => 'My remediation',
'detectionScriptContent' => str_repeat('C', 3),
'remediationScriptContent' => str_repeat('D', 4),
];
$result = $normalizer->normalize($snapshot, 'deviceHealthScript', 'windows');
expect($result['status'])->toBe('ok');
expect($result['settings'])->toBeArray()->not->toBeEmpty();
expect($result['settings'][0]['type'])->toBe('keyValue');
});
it('summarizes script content by default', function () {
config([
'tenantpilot.display.show_script_content' => false,
]);
$normalizer = app(PolicyNormalizer::class);
$snapshot = [
'@odata.type' => '#microsoft.graph.deviceManagementScript',
'displayName' => 'My PS script',
'scriptContent' => 'ABC',
];
$result = $normalizer->normalize($snapshot, 'deviceManagementScript', 'windows');
$entries = collect($result['settings'][0]['entries']);
expect($entries->firstWhere('key', 'scriptContent')['value'])->toBe('[content: 3 chars]');
});
it('shows script content when enabled', function () {
config([
'tenantpilot.display.show_script_content' => true,
'tenantpilot.display.max_script_content_chars' => 100,
]);
$normalizer = app(PolicyNormalizer::class);
$snapshot = [
'@odata.type' => '#microsoft.graph.deviceManagementScript',
'displayName' => 'My PS script',
'scriptContent' => "line1\nline2",
];
$result = $normalizer->normalize($snapshot, 'deviceManagementScript', 'windows');
$entries = collect($result['settings'][0]['entries']);
expect($entries->firstWhere('key', 'scriptContent')['value'])->toBe("line1\nline2");
});
it('decodes scriptContentBase64 when enabled and scriptContent is missing', function () {
config([
'tenantpilot.display.show_script_content' => true,
'tenantpilot.display.max_script_content_chars' => 50,
]);
$normalizer = app(PolicyNormalizer::class);
$snapshot = [
'@odata.type' => '#microsoft.graph.deviceShellScript',
'displayName' => 'My macOS shell script',
'scriptContentBase64' => base64_encode('echo hello'),
];
$result = $normalizer->normalize($snapshot, 'deviceShellScript', 'macOS');
$entries = collect($result['settings'][0]['entries']);
expect($entries->firstWhere('key', 'scriptContent')['value'])->toBe('echo hello');
});
it('decodes base64-looking scriptContent when enabled', function () {
config([
'tenantpilot.display.show_script_content' => true,
'tenantpilot.display.max_script_content_chars' => 5000,
]);
$normalizer = app(PolicyNormalizer::class);
$plain = "# hello\nWrite-Host \"hi\"";
$snapshot = [
'@odata.type' => '#microsoft.graph.deviceManagementScript',
'displayName' => 'My PS script',
'scriptContent' => base64_encode($plain),
];
$result = $normalizer->normalize($snapshot, 'deviceManagementScript', 'windows');
$entries = collect($result['settings'][0]['entries']);
expect($entries->firstWhere('key', 'scriptContent')['value'])->toBe($plain);
});
it('decodes base64-looking detection/remediation script content when enabled', function () {
config([
'tenantpilot.display.show_script_content' => true,
'tenantpilot.display.max_script_content_chars' => 5000,
]);
$normalizer = app(PolicyNormalizer::class);
$detection = "# detection\nWrite-Host \"detect\"";
$remediation = "# remediation\nWrite-Host \"fix\"";
$snapshot = [
'@odata.type' => '#microsoft.graph.deviceHealthScript',
'displayName' => 'My remediation',
'detectionScriptContent' => base64_encode($detection),
'remediationScriptContent' => base64_encode($remediation),
];
$result = $normalizer->normalize($snapshot, 'deviceHealthScript', 'windows');
$entries = collect($result['settings'][0]['entries']);
expect($entries->firstWhere('key', 'detectionScriptContent')['value'])->toBe($detection);
expect($entries->firstWhere('key', 'remediationScriptContent')['value'])->toBe($remediation);
});