From d1a5cb8d7382ab765c56ae719ab0098e90ccc5f7 Mon Sep 17 00:00:00 2001 From: DrIOS <58635327+DrIOSX@users.noreply.github.com> Date: Tue, 28 May 2024 14:26:38 -0500 Subject: [PATCH] fix: 2.1.4 aligned with test-template --- source/tests/Test-SafeAttachmentsPolicy.ps1 | 35 ++++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/source/tests/Test-SafeAttachmentsPolicy.ps1 b/source/tests/Test-SafeAttachmentsPolicy.ps1 index 588c932..7cf285f 100644 --- a/source/tests/Test-SafeAttachmentsPolicy.ps1 +++ b/source/tests/Test-SafeAttachmentsPolicy.ps1 @@ -1,28 +1,39 @@ function Test-SafeAttachmentsPolicy { [CmdletBinding()] param ( + # Aligned # Parameters can be added if needed ) begin { - - $auditResults = @() + # Dot source the class script if necessary + #. .\source\Classes\CISAuditResult.ps1 + # Initialization code, if needed } process { + # 2.1.4 (L2) Ensure Safe Attachments policy is enabled + # Retrieve all Safe Attachment policies where Enable is set to True $safeAttachmentPolicies = Get-SafeAttachmentPolicy | Where-Object { $_.Enable -eq $true } - # If there are any enabled policies, the result is Pass. If not, it's Fail. - $result = $safeAttachmentPolicies -ne $null -and $safeAttachmentPolicies.Count -gt 0 + # Determine result and details based on the presence of enabled policies + $result = $null -ne $safeAttachmentPolicies -and $safeAttachmentPolicies.Count -gt 0 $details = if ($result) { "Enabled Safe Attachments Policies: $($safeAttachmentPolicies.Name -join ', ')" - } else { + } + else { "No Safe Attachments Policies are enabled." } - $failureReason = if ($result) { "N/A" } else { "Safe Attachments policy is not enabled." } - # Create an instance of CISAuditResult and populate it + $failureReasons = if ($result) { + "N/A" + } + else { + "Safe Attachments policy is not enabled." + } + + # Create and populate the CISAuditResult object $auditResult = [CISAuditResult]::new() $auditResult.Status = if ($result) { "Pass" } else { "Fail" } $auditResult.ELevel = "E5" @@ -37,13 +48,13 @@ function Test-SafeAttachmentsPolicy { $auditResult.IG3 = $true $auditResult.Result = $result $auditResult.Details = $details - $auditResult.FailureReason = $failureReason - - $auditResults += $auditResult + $auditResult.FailureReason = $failureReasons } end { - # Return auditResults - return $auditResults + # Return the audit result + return $auditResult } } + +# Additional helper functions (if any)