diff --git a/source/Private/Get-CISExoOutput.ps1 b/source/Private/Get-CISExoOutput.ps1 index bc0de27..9d83b5c 100644 --- a/source/Private/Get-CISExoOutput.ps1 +++ b/source/Private/Get-CISExoOutput.ps1 @@ -288,6 +288,17 @@ function Get-CISExoOutput { # Retrieve the ATP policies for Office 365 and check Safe Attachments settings $atpPolicies = Get-AtpPolicyForO365 # Check if the required ATP policies are enabled + # $atpPolicyResult Mock Object: + <# + $atpPolicyResult = @( + [PSCustomObject]@{ + Name = "Default" + EnableATPForSPOTeamsODB = $true + EnableSafeDocs = $true + AllowSafeDocsOpen = $false + } + ) + #> $atpPolicyResult = $atpPolicies | Where-Object { $_.EnableATPForSPOTeamsODB -eq $true -and $_.EnableSafeDocs -eq $true -and diff --git a/source/tests/Test-SafeAttachmentsTeams.ps1 b/source/tests/Test-SafeAttachmentsTeams.ps1 index 5ae5f14..d274411 100644 --- a/source/tests/Test-SafeAttachmentsTeams.ps1 +++ b/source/tests/Test-SafeAttachmentsTeams.ps1 @@ -5,7 +5,6 @@ function Test-SafeAttachmentsTeams { # Aligned # Parameters can be added if needed ) - begin { # Dot source the class script if necessary #. .\source\Classes\CISAuditResult.ps1 @@ -28,32 +27,58 @@ function Test-SafeAttachmentsTeams { # Initialization code, if needed $recnum = "2.1.5" + Write-Verbose "Running Test-SafeAttachmentsTeams for $recnum..." } - process { + # $atpPolicyResult Mock Object + <# + $atpPolicyResult = @( + [PSCustomObject]@{ + Name = "Default" + EnableATPForSPOTeamsODB = $true + EnableSafeDocs = $true + AllowSafeDocsOpen = $false + } + ) + #> $atpPolicyResult = Get-CISExoOutput -Rec $recnum if ($atpPolicyResult -ne 1) { try { # Condition A: Check Safe Attachments for SharePoint # Condition B: Check Safe Attachments for OneDrive # Condition C: Check Safe Attachments for Microsoft Teams - # Determine the result based on the ATP policy settings $result = $null -ne $atpPolicyResult + $atpPolicyResult | Where-Object { $_.Identity -eq "Default" } + if ($result) { + $detailpass = [PSCustomObject]@{ + Name = $atpPolicyResult.Name + EnableATPForSPOTeamsODB = $atpPolicyResult.EnableATPForSPOTeamsODB + EnableSafeDocs = $atpPolicyResult.EnableSafeDocs + AllowSafeDocsOpen = $atpPolicyResult.AllowSafeDocsOpen + } + $detailsString = $detailpass | ForEach-Object { + @" +Name: $($_.Name) +EnableATPForSPOTeamsODB: $($_.EnableATPForSPOTeamsODB) +EnableSafeDocs: $($_.EnableSafeDocs) +AllowSafeDocsOpen: $($_.AllowSafeDocsOpen) +`n +"@ + } + } $details = if ($result) { - "ATP for SharePoint, OneDrive, and Teams is enabled with correct settings." + $detailsString } else { "ATP for SharePoint, OneDrive, and Teams is not enabled with correct settings." } - $failureReasons = if ($result) { "N/A" } else { "ATP policy for SharePoint, OneDrive, and Microsoft Teams is not correctly configured." } - # Create and populate the CISAuditResult object $params = @{ Rec = $recnum @@ -66,13 +91,10 @@ function Test-SafeAttachmentsTeams { } catch { Write-Error "An error occurred during the test: $_" - # Retrieve the description from the test definitions $testDefinition = $script:TestDefinitionsObject | Where-Object { $_.Rec -eq $recnum } $description = if ($testDefinition) { $testDefinition.RecDescription } else { "Description not found" } - $script:FailedTests.Add([PSCustomObject]@{ Rec = $recnum; Description = $description; Error = $_ }) - # Call Initialize-CISAuditResult with error parameters $auditResult = Initialize-CISAuditResult -Rec $recnum -Failure } @@ -88,7 +110,6 @@ function Test-SafeAttachmentsTeams { $auditResult = Initialize-CISAuditResult @params } } - end { # Return the audit result return $auditResult