Skip to content

Commit 1c71909

Browse files
committed
resolved copilot comment
1 parent a67fb35 commit 1c71909

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

src/powershell/tests/Test-Assessment.25412.ps1

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function Test-Assessment-25412 {
3333

3434
# Define constants
3535
[int]$BASELINE_PROFILE_PRIORITY = 65000
36+
[string]$THREAT_INTELLIGENCE_POLICY_LINK_TYPE = '#microsoft.graph.networkaccess.threatIntelligencePolicyLink'
3637

3738
#region Data Collection
3839
Write-PSFMessage '🟦 Start' -Tag Test -Level VeryVerbose
@@ -60,7 +61,7 @@ function Test-Assessment-25412 {
6061
# Q2: Get all filtering profiles with expanded policies
6162
Write-ZtProgress -Activity $activity -Status 'Getting filtering profiles'
6263
try {
63-
$filteringProfiles = Invoke-ZtGraphRequest -RelativeUri 'networkAccess/filteringProfiles' -QueryParameters @{ '$select' = 'id,name,description,state,version,priority'; '$expand' = 'policies($select=id,state;$expand=policy($select=id,name,version))' } -ApiVersion beta -ErrorAction Stop
64+
$filteringProfiles = Invoke-ZtGraphRequest -RelativeUri 'networkAccess/filteringProfiles' -QueryParameters @{ '$select' = 'id,name,description,state,version,priority'; '$expand' = 'policies($expand=policy)' } -ApiVersion beta -ErrorAction Stop
6465
Write-PSFMessage "Found $($filteringProfiles.Count) filtering profiles" -Level Verbose
6566
}
6667
catch {
@@ -89,23 +90,26 @@ function Test-Assessment-25412 {
8990
$investigateMessage = "⚠️ Unable to determine threat intelligence filtering status due to an API or access error. Re-run the assessment after verifying Microsoft Graph access and retrying the check.`n`n%TestResult%"
9091
$failMessage = "❌ No enabled threat intelligence policy link is enforced through the baseline profile or a security profile assigned by a Conditional Access policy.`n`n%TestResult%"
9192

92-
# Step 1: Verify settings.defaultAction equals 'allow' (blocks threats)
93-
$defaultActionValid = $false
93+
# Step 1: Verify at least one threat intelligence policy exists.
9494
$hasRequiredQueryError = ($null -ne $q1Error) -or ($null -ne $q2Error)
95-
96-
if ($threatIntelPolicies -and $threatIntelPolicies.Count -gt 0) {
97-
# At least one policy must have settings.defaultAction = allow.
98-
$defaultActionValid = @($threatIntelPolicies | Where-Object { $_.settings.defaultAction -eq 'allow' }).Count -gt 0
95+
$threatIntelPolicyIds = [System.Collections.Generic.HashSet[string]]::new()
96+
if ($threatIntelPolicies) {
97+
foreach ($threatIntelPolicy in $threatIntelPolicies) {
98+
if ($threatIntelPolicy.id) {
99+
[void]$threatIntelPolicyIds.Add($threatIntelPolicy.id)
100+
}
101+
}
99102
}
103+
$hasThreatIntelPolicies = $threatIntelPolicyIds.Count -gt 0
100104

101105
# Q1/Q2 failures are always investigate because they block prerequisite evaluation.
102106
if ($hasRequiredQueryError) {
103107
$passed = $false
104108
$customStatus = 'Investigate'
105109
$testResultMarkdown = $investigateMessage
106110
}
107-
# If defaultAction is not 'allow', test fails regardless of profile linkage.
108-
elseif (-not $defaultActionValid) {
111+
# If no threat intelligence policies exist, test fails regardless of profile linkage.
112+
elseif (-not $hasThreatIntelPolicies) {
109113
$passed = $false
110114
$testResultMarkdown = $failMessage
111115
}
@@ -116,7 +120,8 @@ function Test-Assessment-25412 {
116120

117121
if ($baselineProfile) {
118122
$tiPolicyLinks = @($baselineProfile.policies | Where-Object {
119-
$_.policy.'@odata.type' -eq '#microsoft.graph.networkaccess.threatIntelligencePolicy'
123+
$_.'@odata.type' -eq $THREAT_INTELLIGENCE_POLICY_LINK_TYPE -and
124+
$_.policy.id -and $threatIntelPolicyIds.Contains($_.policy.id)
120125
})
121126

122127
$enabledTiLinks = @($tiPolicyLinks | Where-Object { $_.state -eq 'enabled' })
@@ -152,7 +157,8 @@ function Test-Assessment-25412 {
152157
if ($linkedProfile) {
153158
# Check if this profile is enabled and has an enabled threat intelligence policy link
154159
$tiLinks = @($linkedProfile.policies | Where-Object {
155-
$_.policy.'@odata.type' -eq '#microsoft.graph.networkaccess.threatIntelligencePolicy'
160+
$_.'@odata.type' -eq $THREAT_INTELLIGENCE_POLICY_LINK_TYPE -and
161+
$_.policy.id -and $threatIntelPolicyIds.Contains($_.policy.id)
156162
})
157163
$enabledTiLinks = @($tiLinks | Where-Object { $_.state -eq 'enabled' })
158164

@@ -195,7 +201,8 @@ function Test-Assessment-25412 {
195201
$baselineNameWithLink = "[$baselineName]($baselineProfileLink)"
196202

197203
$tiPolicyLinks = @($baselineProfile.policies | Where-Object {
198-
$_.policy.'@odata.type' -eq '#microsoft.graph.networkaccess.threatIntelligencePolicy'
204+
$_.'@odata.type' -eq $THREAT_INTELLIGENCE_POLICY_LINK_TYPE -and
205+
$_.policy.id -and $threatIntelPolicyIds.Contains($_.policy.id)
199206
})
200207
$enabledTiLinks = @($tiPolicyLinks | Where-Object { $_.state -eq 'enabled' })
201208

@@ -277,7 +284,8 @@ Unable to retrieve Conditional Access policies from Microsoft Graph, so Conditio
277284
# Check if profile has TI policy
278285
$profileHasTI = if ($linkedProfile) {
279286
@($linkedProfile.policies | Where-Object {
280-
$_.policy.'@odata.type' -eq '#microsoft.graph.networkaccess.threatIntelligencePolicy'
287+
$_.'@odata.type' -eq $THREAT_INTELLIGENCE_POLICY_LINK_TYPE -and
288+
$_.policy.id -and $threatIntelPolicyIds.Contains($_.policy.id)
281289
}).Count -gt 0
282290
}
283291
else {
@@ -286,7 +294,8 @@ Unable to retrieve Conditional Access policies from Microsoft Graph, so Conditio
286294

287295
$profileTiLinks = if ($linkedProfile) {
288296
@($linkedProfile.policies | Where-Object {
289-
$_.policy.'@odata.type' -eq '#microsoft.graph.networkaccess.threatIntelligencePolicy'
297+
$_.'@odata.type' -eq $THREAT_INTELLIGENCE_POLICY_LINK_TYPE -and
298+
$_.policy.id -and $threatIntelPolicyIds.Contains($_.policy.id)
290299
})
291300
}
292301
else {

0 commit comments

Comments
 (0)