fix: capture assignments and scope tags in policy versions
This commit is contained in:
parent
98915455b9
commit
db4b2e4dc7
@ -54,8 +54,9 @@ public function enrichWithAssignments(
|
||||
}
|
||||
|
||||
// Fetch assignments from Graph API
|
||||
$tenantId = $tenant->external_id ?? $tenant->tenant_id;
|
||||
$assignments = $this->assignmentFetcher->fetch($tenantId, $policyId);
|
||||
$graphOptions = $tenant->graphOptions();
|
||||
$tenantId = $graphOptions['tenant'] ?? $tenant->external_id ?? $tenant->tenant_id;
|
||||
$assignments = $this->assignmentFetcher->fetch($tenantId, $policyId, $graphOptions);
|
||||
|
||||
if (empty($assignments)) {
|
||||
// No assignments or fetch failed
|
||||
@ -82,7 +83,7 @@ public function enrichWithAssignments(
|
||||
$hasOrphanedGroups = false;
|
||||
|
||||
if (! empty($groupIds)) {
|
||||
$resolvedGroups = $this->groupResolver->resolveGroupIds($groupIds, $tenantId);
|
||||
$resolvedGroups = $this->groupResolver->resolveGroupIds($groupIds, $tenantId, $graphOptions);
|
||||
$hasOrphanedGroups = collect($resolvedGroups)->contains('orphaned', true);
|
||||
}
|
||||
|
||||
|
||||
@ -18,11 +18,13 @@ public function __construct(
|
||||
*
|
||||
* @return array Returns assignment array or empty array on failure
|
||||
*/
|
||||
public function fetch(string $tenantId, string $policyId): array
|
||||
public function fetch(string $tenantId, string $policyId, array $options = []): array
|
||||
{
|
||||
try {
|
||||
$requestOptions = array_merge($options, ['tenant' => $tenantId]);
|
||||
|
||||
// Try primary endpoint
|
||||
$assignments = $this->fetchPrimary($tenantId, $policyId);
|
||||
$assignments = $this->fetchPrimary($policyId, $requestOptions);
|
||||
|
||||
if (! empty($assignments)) {
|
||||
Log::debug('Fetched assignments via primary endpoint', [
|
||||
@ -40,7 +42,7 @@ public function fetch(string $tenantId, string $policyId): array
|
||||
'policy_id' => $policyId,
|
||||
]);
|
||||
|
||||
$assignments = $this->fetchWithExpand($tenantId, $policyId);
|
||||
$assignments = $this->fetchWithExpand($policyId, $requestOptions);
|
||||
|
||||
if (! empty($assignments)) {
|
||||
Log::debug('Fetched assignments via fallback endpoint', [
|
||||
@ -74,13 +76,11 @@ public function fetch(string $tenantId, string $policyId): array
|
||||
/**
|
||||
* Fetch assignments using primary endpoint.
|
||||
*/
|
||||
private function fetchPrimary(string $tenantId, string $policyId): array
|
||||
private function fetchPrimary(string $policyId, array $options): array
|
||||
{
|
||||
$path = "/deviceManagement/configurationPolicies/{$policyId}/assignments";
|
||||
|
||||
$response = $this->graphClient->request('GET', $path, [
|
||||
'tenant' => $tenantId,
|
||||
]);
|
||||
$response = $this->graphClient->request('GET', $path, $options);
|
||||
|
||||
return $response->data['value'] ?? [];
|
||||
}
|
||||
@ -88,7 +88,7 @@ private function fetchPrimary(string $tenantId, string $policyId): array
|
||||
/**
|
||||
* Fetch assignments using $expand fallback.
|
||||
*/
|
||||
private function fetchWithExpand(string $tenantId, string $policyId): array
|
||||
private function fetchWithExpand(string $policyId, array $options): array
|
||||
{
|
||||
$path = '/deviceManagement/configurationPolicies';
|
||||
$params = [
|
||||
@ -96,10 +96,9 @@ private function fetchWithExpand(string $tenantId, string $policyId): array
|
||||
'$filter' => "id eq '{$policyId}'",
|
||||
];
|
||||
|
||||
$response = $this->graphClient->request('GET', $path, [
|
||||
'tenant' => $tenantId,
|
||||
$response = $this->graphClient->request('GET', $path, array_merge($options, [
|
||||
'query' => $params,
|
||||
]);
|
||||
]));
|
||||
|
||||
$policies = $response->data['value'] ?? [];
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ public function __construct(
|
||||
* @param string $tenantId Target tenant ID
|
||||
* @return array Keyed array: ['group-id' => ['id' => ..., 'displayName' => ..., 'orphaned' => bool]]
|
||||
*/
|
||||
public function resolveGroupIds(array $groupIds, string $tenantId): array
|
||||
public function resolveGroupIds(array $groupIds, string $tenantId, array $options = []): array
|
||||
{
|
||||
if (empty($groupIds)) {
|
||||
return [];
|
||||
@ -30,27 +30,27 @@ public function resolveGroupIds(array $groupIds, string $tenantId): array
|
||||
// Create cache key
|
||||
$cacheKey = $this->getCacheKey($groupIds, $tenantId);
|
||||
|
||||
return Cache::remember($cacheKey, 300, function () use ($groupIds, $tenantId) {
|
||||
return $this->fetchAndResolveGroups($groupIds, $tenantId);
|
||||
return Cache::remember($cacheKey, 300, function () use ($groupIds, $tenantId, $options) {
|
||||
return $this->fetchAndResolveGroups($groupIds, $tenantId, $options);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch groups from Graph API and resolve orphaned IDs.
|
||||
*/
|
||||
private function fetchAndResolveGroups(array $groupIds, string $tenantId): array
|
||||
private function fetchAndResolveGroups(array $groupIds, string $tenantId, array $options = []): array
|
||||
{
|
||||
try {
|
||||
$response = $this->graphClient->request(
|
||||
'POST',
|
||||
'/directoryObjects/getByIds',
|
||||
[
|
||||
array_merge($options, [
|
||||
'tenant' => $tenantId,
|
||||
'json' => [
|
||||
'ids' => array_values($groupIds),
|
||||
'types' => ['group'],
|
||||
],
|
||||
]
|
||||
])
|
||||
);
|
||||
|
||||
$resolvedGroups = $response->data['value'] ?? [];
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
use App\Models\Tenant;
|
||||
use App\Services\Graph\AssignmentFetcher;
|
||||
use App\Services\Graph\GroupResolver;
|
||||
use App\Services\Graph\ScopeTagResolver;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
@ -21,17 +22,12 @@ public function __construct(
|
||||
private readonly PolicySnapshotService $snapshotService,
|
||||
private readonly AssignmentFetcher $assignmentFetcher,
|
||||
private readonly GroupResolver $groupResolver,
|
||||
private readonly ScopeTagResolver $scopeTagResolver,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Capture policy snapshot with optional assignments/scope tags.
|
||||
*
|
||||
* @param Policy $policy
|
||||
* @param Tenant $tenant
|
||||
* @param bool $includeAssignments
|
||||
* @param bool $includeScopeTags
|
||||
* @param string|null $createdBy
|
||||
* @param array $metadata
|
||||
* @return array ['version' => PolicyVersion, 'captured' => array]
|
||||
*/
|
||||
public function capture(
|
||||
@ -42,6 +38,9 @@ public function capture(
|
||||
?string $createdBy = null,
|
||||
array $metadata = []
|
||||
): array {
|
||||
$graphOptions = $tenant->graphOptions();
|
||||
$tenantIdentifier = $graphOptions['tenant'] ?? $tenant->graphTenantId() ?? (string) $tenant->getKey();
|
||||
|
||||
// 1. Fetch policy snapshot
|
||||
$snapshot = $this->snapshotService->fetch($tenant, $policy, $createdBy);
|
||||
|
||||
@ -57,7 +56,7 @@ public function capture(
|
||||
// 2. Fetch assignments if requested
|
||||
if ($includeAssignments) {
|
||||
try {
|
||||
$rawAssignments = $this->assignmentFetcher->fetch($tenant->id, $policy->external_id);
|
||||
$rawAssignments = $this->assignmentFetcher->fetch($tenantIdentifier, $policy->external_id, $graphOptions);
|
||||
|
||||
if (! empty($rawAssignments)) {
|
||||
$assignments = $rawAssignments;
|
||||
@ -71,8 +70,9 @@ public function capture(
|
||||
->toArray();
|
||||
|
||||
if (! empty($groupIds)) {
|
||||
$resolvedGroups = $this->groupResolver->resolve($tenant->id, $groupIds);
|
||||
$captureMetadata['has_orphaned_assignments'] = !empty($resolvedGroups['orphaned']);
|
||||
$resolvedGroups = $this->groupResolver->resolveGroupIds($groupIds, $tenantIdentifier, $graphOptions);
|
||||
$captureMetadata['has_orphaned_assignments'] = collect($resolvedGroups)
|
||||
->contains(fn (array $group) => $group['orphaned'] ?? false);
|
||||
}
|
||||
|
||||
$captureMetadata['assignments_count'] = count($rawAssignments);
|
||||
@ -91,10 +91,8 @@ public function capture(
|
||||
|
||||
// 3. Fetch scope tags if requested
|
||||
if ($includeScopeTags) {
|
||||
$scopeTags = [
|
||||
'ids' => $payload['roleScopeTagIds'] ?? ['0'],
|
||||
'names' => ['Default'], // Could fetch from Graph if needed
|
||||
];
|
||||
$scopeTagIds = $payload['roleScopeTagIds'] ?? ['0'];
|
||||
$scopeTags = $this->resolveScopeTags($tenant, $scopeTagIds);
|
||||
}
|
||||
|
||||
// 4. Check if PolicyVersion with same snapshot already exists
|
||||
@ -107,20 +105,29 @@ public function capture(
|
||||
return hash('sha256', json_encode($version->snapshot)) === $snapshotHash;
|
||||
});
|
||||
|
||||
if ($existingVersion && $includeAssignments && is_null($existingVersion->assignments)) {
|
||||
// Backfill existing version with assignments (idempotent)
|
||||
$existingVersion->update([
|
||||
'assignments' => $assignments,
|
||||
'scope_tags' => $scopeTags,
|
||||
'assignments_hash' => $assignments ? hash('sha256', json_encode($assignments)) : null,
|
||||
'scope_tags_hash' => $scopeTags ? hash('sha256', json_encode($scopeTags)) : null,
|
||||
]);
|
||||
if ($existingVersion) {
|
||||
$updates = [];
|
||||
|
||||
Log::info('Backfilled existing PolicyVersion with assignments', [
|
||||
if ($includeAssignments && $existingVersion->assignments === null) {
|
||||
$updates['assignments'] = $assignments;
|
||||
$updates['assignments_hash'] = $assignments ? hash('sha256', json_encode($assignments)) : null;
|
||||
}
|
||||
|
||||
if ($includeScopeTags && $existingVersion->scope_tags === null) {
|
||||
$updates['scope_tags'] = $scopeTags;
|
||||
$updates['scope_tags_hash'] = $scopeTags ? hash('sha256', json_encode($scopeTags)) : null;
|
||||
}
|
||||
|
||||
if (! empty($updates)) {
|
||||
$existingVersion->update($updates);
|
||||
|
||||
Log::info('Backfilled existing PolicyVersion with capture data', [
|
||||
'tenant_id' => $tenant->id,
|
||||
'policy_id' => $policy->id,
|
||||
'version_id' => $existingVersion->id,
|
||||
'version_number' => $existingVersion->version_number,
|
||||
'assignments_backfilled' => array_key_exists('assignments', $updates),
|
||||
'scope_tags_backfilled' => array_key_exists('scope_tags', $updates),
|
||||
]);
|
||||
|
||||
return [
|
||||
@ -134,8 +141,6 @@ public function capture(
|
||||
];
|
||||
}
|
||||
|
||||
if ($existingVersion) {
|
||||
// Reuse existing version without modification
|
||||
Log::info('Reusing existing PolicyVersion', [
|
||||
'tenant_id' => $tenant->id,
|
||||
'policy_id' => $policy->id,
|
||||
@ -192,13 +197,6 @@ public function capture(
|
||||
|
||||
/**
|
||||
* Ensure existing PolicyVersion has assignments if missing.
|
||||
*
|
||||
* @param PolicyVersion $version
|
||||
* @param Tenant $tenant
|
||||
* @param Policy $policy
|
||||
* @param bool $includeAssignments
|
||||
* @param bool $includeScopeTags
|
||||
* @return PolicyVersion
|
||||
*/
|
||||
public function ensureVersionHasAssignments(
|
||||
PolicyVersion $version,
|
||||
@ -207,8 +205,10 @@ public function ensureVersionHasAssignments(
|
||||
bool $includeAssignments = false,
|
||||
bool $includeScopeTags = false
|
||||
): PolicyVersion {
|
||||
// If version already has assignments, don't overwrite (idempotent)
|
||||
if ($version->assignments !== null) {
|
||||
$graphOptions = $tenant->graphOptions();
|
||||
$tenantIdentifier = $graphOptions['tenant'] ?? $tenant->graphTenantId() ?? (string) $tenant->getKey();
|
||||
|
||||
if ($version->assignments !== null && $version->scope_tags !== null) {
|
||||
Log::debug('Version already has assignments, skipping', [
|
||||
'version_id' => $version->id,
|
||||
]);
|
||||
@ -225,10 +225,9 @@ public function ensureVersionHasAssignments(
|
||||
$scopeTags = null;
|
||||
$metadata = $version->metadata ?? [];
|
||||
|
||||
// Fetch assignments
|
||||
if ($includeAssignments) {
|
||||
if ($includeAssignments && $version->assignments === null) {
|
||||
try {
|
||||
$rawAssignments = $this->assignmentFetcher->fetch($tenant->id, $policy->external_id);
|
||||
$rawAssignments = $this->assignmentFetcher->fetch($tenantIdentifier, $policy->external_id, $graphOptions);
|
||||
|
||||
if (! empty($rawAssignments)) {
|
||||
$assignments = $rawAssignments;
|
||||
@ -242,8 +241,9 @@ public function ensureVersionHasAssignments(
|
||||
->toArray();
|
||||
|
||||
if (! empty($groupIds)) {
|
||||
$resolvedGroups = $this->groupResolver->resolve($tenant->id, $groupIds);
|
||||
$metadata['has_orphaned_assignments'] = !empty($resolvedGroups['orphaned']);
|
||||
$resolvedGroups = $this->groupResolver->resolveGroupIds($groupIds, $tenantIdentifier, $graphOptions);
|
||||
$metadata['has_orphaned_assignments'] = collect($resolvedGroups)
|
||||
->contains(fn (array $group) => $group['orphaned'] ?? false);
|
||||
}
|
||||
|
||||
$metadata['assignments_count'] = count($rawAssignments);
|
||||
@ -261,23 +261,28 @@ public function ensureVersionHasAssignments(
|
||||
|
||||
// Fetch scope tags
|
||||
if ($includeScopeTags && $version->scope_tags === null) {
|
||||
// Try to get from snapshot
|
||||
$scopeTags = [
|
||||
'ids' => $version->snapshot['roleScopeTagIds'] ?? ['0'],
|
||||
'names' => ['Default'],
|
||||
];
|
||||
$scopeTagIds = $version->snapshot['roleScopeTagIds'] ?? ['0'];
|
||||
$scopeTags = $this->resolveScopeTags($tenant, $scopeTagIds);
|
||||
}
|
||||
|
||||
// Update version
|
||||
$version->update([
|
||||
'assignments' => $assignments,
|
||||
'scope_tags' => $scopeTags,
|
||||
'assignments_hash' => $assignments ? hash('sha256', json_encode($assignments)) : null,
|
||||
'scope_tags_hash' => $scopeTags ? hash('sha256', json_encode($scopeTags)) : null,
|
||||
'metadata' => $metadata,
|
||||
]);
|
||||
$updates = [];
|
||||
|
||||
Log::info('Version backfilled with assignments', [
|
||||
if ($includeAssignments && $version->assignments === null) {
|
||||
$updates['assignments'] = $assignments;
|
||||
$updates['assignments_hash'] = $assignments ? hash('sha256', json_encode($assignments)) : null;
|
||||
}
|
||||
|
||||
if ($includeScopeTags && $version->scope_tags === null) {
|
||||
$updates['scope_tags'] = $scopeTags;
|
||||
$updates['scope_tags_hash'] = $scopeTags ? hash('sha256', json_encode($scopeTags)) : null;
|
||||
}
|
||||
|
||||
if (! empty($updates)) {
|
||||
$updates['metadata'] = $metadata;
|
||||
$version->update($updates);
|
||||
}
|
||||
|
||||
Log::info('Version backfilled with capture data', [
|
||||
'version_id' => $version->id,
|
||||
'has_assignments' => ! is_null($assignments),
|
||||
'has_scope_tags' => ! is_null($scopeTags),
|
||||
@ -285,4 +290,24 @@ public function ensureVersionHasAssignments(
|
||||
|
||||
return $version->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $scopeTagIds
|
||||
* @return array{ids:array<int, string>,names:array<int, string>}
|
||||
*/
|
||||
private function resolveScopeTags(Tenant $tenant, array $scopeTagIds): array
|
||||
{
|
||||
$scopeTags = $this->scopeTagResolver->resolve($scopeTagIds, $tenant);
|
||||
|
||||
$names = [];
|
||||
foreach ($scopeTagIds as $id) {
|
||||
$scopeTag = collect($scopeTags)->firstWhere('id', $id);
|
||||
$names[] = $scopeTag['displayName'] ?? ($id === '0' ? 'Default' : "Unknown (ID: {$id})");
|
||||
}
|
||||
|
||||
return [
|
||||
'ids' => $scopeTagIds,
|
||||
'names' => $names,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
use App\Models\Tenant;
|
||||
use App\Services\Graph\AssignmentFetcher;
|
||||
use App\Services\Graph\GroupResolver;
|
||||
use App\Services\Graph\ScopeTagResolver;
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
class VersionService
|
||||
@ -16,6 +17,7 @@ public function __construct(
|
||||
private readonly PolicySnapshotService $snapshotService,
|
||||
private readonly AssignmentFetcher $assignmentFetcher,
|
||||
private readonly GroupResolver $groupResolver,
|
||||
private readonly ScopeTagResolver $scopeTagResolver,
|
||||
) {}
|
||||
|
||||
public function captureVersion(
|
||||
@ -69,6 +71,9 @@ public function captureFromGraph(
|
||||
bool $includeAssignments = true,
|
||||
bool $includeScopeTags = true,
|
||||
): PolicyVersion {
|
||||
$graphOptions = $tenant->graphOptions();
|
||||
$tenantIdentifier = $graphOptions['tenant'] ?? $tenant->graphTenantId() ?? (string) $tenant->getKey();
|
||||
|
||||
$snapshot = $this->snapshotService->fetch($tenant, $policy, $createdBy);
|
||||
|
||||
if (isset($snapshot['failure'])) {
|
||||
@ -84,7 +89,7 @@ public function captureFromGraph(
|
||||
|
||||
if ($includeAssignments) {
|
||||
try {
|
||||
$rawAssignments = $this->assignmentFetcher->fetch($tenant->id, $policy->external_id);
|
||||
$rawAssignments = $this->assignmentFetcher->fetch($tenantIdentifier, $policy->external_id, $graphOptions);
|
||||
|
||||
if (! empty($rawAssignments)) {
|
||||
$assignments = $rawAssignments;
|
||||
@ -97,9 +102,10 @@ public function captureFromGraph(
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
$resolvedGroups = $this->groupResolver->resolve($tenant->id, $groupIds);
|
||||
$resolvedGroups = $this->groupResolver->resolveGroupIds($groupIds, $tenantIdentifier, $graphOptions);
|
||||
|
||||
$assignmentMetadata['has_orphaned_assignments'] = ! empty($resolvedGroups['orphaned']);
|
||||
$assignmentMetadata['has_orphaned_assignments'] = collect($resolvedGroups)
|
||||
->contains(fn (array $group) => $group['orphaned'] ?? false);
|
||||
$assignmentMetadata['assignments_count'] = count($rawAssignments);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
@ -109,10 +115,8 @@ public function captureFromGraph(
|
||||
}
|
||||
|
||||
if ($includeScopeTags) {
|
||||
$scopeTags = [
|
||||
'ids' => $payload['roleScopeTagIds'] ?? ['0'],
|
||||
'names' => ['Default'], // Could be fetched from Graph if needed
|
||||
];
|
||||
$scopeTagIds = $payload['roleScopeTagIds'] ?? ['0'];
|
||||
$scopeTags = $this->resolveScopeTags($tenant, $scopeTagIds);
|
||||
}
|
||||
|
||||
$metadata = array_merge(
|
||||
@ -131,6 +135,26 @@ public function captureFromGraph(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $scopeTagIds
|
||||
* @return array{ids:array<int, string>,names:array<int, string>}
|
||||
*/
|
||||
private function resolveScopeTags(Tenant $tenant, array $scopeTagIds): array
|
||||
{
|
||||
$scopeTags = $this->scopeTagResolver->resolve($scopeTagIds, $tenant);
|
||||
|
||||
$names = [];
|
||||
foreach ($scopeTagIds as $id) {
|
||||
$scopeTag = collect($scopeTags)->firstWhere('id', $id);
|
||||
$names[] = $scopeTag['displayName'] ?? ($id === '0' ? 'Default' : "Unknown (ID: {$id})");
|
||||
}
|
||||
|
||||
return [
|
||||
'ids' => $scopeTagIds,
|
||||
'names' => $names,
|
||||
];
|
||||
}
|
||||
|
||||
private function nextVersionNumber(Policy $policy): int
|
||||
{
|
||||
$current = PolicyVersion::query()
|
||||
|
||||
@ -5,9 +5,8 @@
|
||||
use App\Models\PolicyVersion;
|
||||
use App\Models\Tenant;
|
||||
use App\Services\Graph\AssignmentFetcher;
|
||||
use App\Services\Graph\MicrosoftGraphClient;
|
||||
use App\Services\Graph\GroupResolver;
|
||||
use App\Services\Intune\BackupService;
|
||||
use App\Services\Intune\GroupResolver;
|
||||
use App\Services\Intune\PolicySnapshotService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Mockery\MockInterface;
|
||||
@ -86,10 +85,13 @@
|
||||
|
||||
// Mock GroupResolver
|
||||
$this->mock(GroupResolver::class, function (MockInterface $mock) {
|
||||
$mock->shouldReceive('resolve')
|
||||
$mock->shouldReceive('resolveGroupIds')
|
||||
->andReturn([
|
||||
'resolved' => ['group-123' => 'Test Group'],
|
||||
'orphaned' => [],
|
||||
'group-123' => [
|
||||
'id' => 'group-123',
|
||||
'displayName' => 'Test Group',
|
||||
'orphaned' => false,
|
||||
],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
use App\Services\Graph\AssignmentFetcher;
|
||||
use App\Services\Graph\ScopeTagResolver;
|
||||
use App\Services\Intune\PolicySnapshotService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
@ -38,6 +39,14 @@
|
||||
$mock->shouldReceive('fetch')->never();
|
||||
});
|
||||
|
||||
$this->mock(ScopeTagResolver::class, function (MockInterface $mock) {
|
||||
$mock->shouldReceive('resolve')
|
||||
->once()
|
||||
->andReturn([
|
||||
['id' => '0', 'displayName' => 'Default'],
|
||||
]);
|
||||
});
|
||||
|
||||
Livewire::test(ViewPolicy::class, ['record' => $policy->getRouteKey()])
|
||||
->callAction('capture_snapshot', data: [
|
||||
'include_assignments' => false,
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
use App\Models\Tenant;
|
||||
use App\Services\Graph\AssignmentFetcher;
|
||||
use App\Services\Graph\GroupResolver;
|
||||
use App\Services\Graph\ScopeTagResolver;
|
||||
use App\Services\Intune\PolicySnapshotService;
|
||||
use App\Services\Intune\VersionService;
|
||||
|
||||
@ -13,6 +14,13 @@
|
||||
'tenant_id' => $this->tenant->id,
|
||||
'external_id' => 'test-policy-id',
|
||||
]);
|
||||
|
||||
$this->mock(ScopeTagResolver::class, function ($mock) {
|
||||
$mock->shouldReceive('resolve')
|
||||
->andReturn([
|
||||
['id' => '0', 'displayName' => 'Default'],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('captures policy version with assignments from graph', function () {
|
||||
@ -45,13 +53,14 @@
|
||||
});
|
||||
|
||||
$this->mock(GroupResolver::class, function ($mock) {
|
||||
$mock->shouldReceive('resolve')
|
||||
$mock->shouldReceive('resolveGroupIds')
|
||||
->once()
|
||||
->andReturn([
|
||||
'resolved' => [
|
||||
'group-123' => ['id' => 'group-123', 'displayName' => 'Test Group'],
|
||||
'group-123' => [
|
||||
'id' => 'group-123',
|
||||
'displayName' => 'Test Group',
|
||||
'orphaned' => false,
|
||||
],
|
||||
'orphaned' => [],
|
||||
]);
|
||||
});
|
||||
|
||||
@ -68,7 +77,11 @@
|
||||
->and($version->assignments[0]['target']['groupId'])->toBe('group-123')
|
||||
->and($version->assignments_hash)->not->toBeNull()
|
||||
->and($version->metadata['assignments_count'])->toBe(1)
|
||||
->and($version->metadata['has_orphaned_assignments'])->toBeFalse();
|
||||
->and($version->metadata['has_orphaned_assignments'])->toBeFalse()
|
||||
->and($version->scope_tags)->toBe([
|
||||
'ids' => ['0'],
|
||||
'names' => ['Default'],
|
||||
]);
|
||||
});
|
||||
|
||||
it('captures policy version without assignments when none exist', function () {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user