add: Get-ExoOutput function and modified tests: '1.2.2', '1.3.3', '1.3.6', '2.1.1'
This commit is contained in:
103
source/Private/Get-ExoOutput.ps1
Normal file
103
source/Private/Get-ExoOutput.ps1
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
This is a sample Private function only visible within the module.
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
This sample function is not exported to the module and only return the data passed as parameter.
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
$null = Get-ExoOutput -PrivateData 'NOTHING TO SEE HERE'
|
||||||
|
|
||||||
|
.PARAMETER PrivateData
|
||||||
|
The PrivateData parameter is what will be returned without transformation.
|
||||||
|
|
||||||
|
#>
|
||||||
|
function Get-ExoOutput {
|
||||||
|
[cmdletBinding()]
|
||||||
|
[OutputType([string])]
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[String]
|
||||||
|
$Rec
|
||||||
|
)
|
||||||
|
|
||||||
|
begin {
|
||||||
|
# Begin Block #
|
||||||
|
}
|
||||||
|
process {
|
||||||
|
switch ($Rec) {
|
||||||
|
'1.2.2' {
|
||||||
|
$MBX = Get-EXOMailbox -RecipientTypeDetails SharedMailbox
|
||||||
|
return $MBX
|
||||||
|
}
|
||||||
|
'1.3.3' {
|
||||||
|
# Step: Retrieve sharing policies related to calendar sharing
|
||||||
|
$sharingPolicies = Get-SharingPolicy | Where-Object { $_.Domains -like '*CalendarSharing*' }
|
||||||
|
return $sharingPolicies
|
||||||
|
}
|
||||||
|
'1.3.6' {
|
||||||
|
# Step: Retrieve the organization configuration (Condition C: Pass/Fail)
|
||||||
|
$orgConfig = Get-OrganizationConfig | Select-Object CustomerLockBoxEnabled
|
||||||
|
$customerLockboxEnabled = $orgConfig.CustomerLockBoxEnabled
|
||||||
|
return $customerLockboxEnabled
|
||||||
|
}
|
||||||
|
'2.1.1' {
|
||||||
|
if (Get-Command Get-SafeLinksPolicy -ErrorAction SilentlyContinue) {
|
||||||
|
# 2.1.1 (L2) Ensure Safe Links for Office Applications is Enabled
|
||||||
|
# Retrieve all Safe Links policies
|
||||||
|
$policies = Get-SafeLinksPolicy
|
||||||
|
# Initialize the details collection
|
||||||
|
$misconfiguredDetails = @()
|
||||||
|
|
||||||
|
foreach ($policy in $policies) {
|
||||||
|
# Get the detailed configuration of each policy
|
||||||
|
$policyDetails = Get-SafeLinksPolicy -Identity $policy.Name
|
||||||
|
|
||||||
|
# Check each required property and record failures
|
||||||
|
# Condition A: Checking policy settings
|
||||||
|
$failures = @()
|
||||||
|
if ($policyDetails.EnableSafeLinksForEmail -ne $true) { $failures += "EnableSafeLinksForEmail: False" } # Email: On
|
||||||
|
if ($policyDetails.EnableSafeLinksForTeams -ne $true) { $failures += "EnableSafeLinksForTeams: False" } # Teams: On
|
||||||
|
if ($policyDetails.EnableSafeLinksForOffice -ne $true) { $failures += "EnableSafeLinksForOffice: False" } # Office 365 Apps: On
|
||||||
|
if ($policyDetails.TrackClicks -ne $true) { $failures += "TrackClicks: False" } # Click protection settings: On
|
||||||
|
if ($policyDetails.AllowClickThrough -ne $false) { $failures += "AllowClickThrough: True" } # Do not track when users click safe links: Off
|
||||||
|
|
||||||
|
# Only add details for policies that have misconfigurations
|
||||||
|
if ($failures.Count -gt 0) {
|
||||||
|
$misconfiguredDetails += "Policy: $($policy.Name); Failures: $($failures -join ', ')"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $misconfiguredDetails
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
'2.1.2' { Write-Output "Matched 2.1.2" }
|
||||||
|
'2.1.3' { Write-Output "Matched 2.1.3" }
|
||||||
|
'2.1.4' { Write-Output "Matched 2.1.4" }
|
||||||
|
'2.1.5' { Write-Output "Matched 2.1.5" }
|
||||||
|
'2.1.6' { Write-Output "Matched 2.1.6" }
|
||||||
|
'2.1.7' { Write-Output "Matched 2.1.7" }
|
||||||
|
'2.1.9' { Write-Output "Matched 2.1.9" }
|
||||||
|
'3.1.1' { Write-Output "Matched 3.1.1" }
|
||||||
|
'6.1.1' { Write-Output "Matched 6.1.1" }
|
||||||
|
'6.1.2' { Write-Output "Matched 6.1.2" }
|
||||||
|
'6.1.3' { Write-Output "Matched 6.1.3" }
|
||||||
|
'6.2.1' { Write-Output "Matched 6.2.1" }
|
||||||
|
'6.2.2' { Write-Output "Matched 6.2.2" }
|
||||||
|
'6.2.3' { Write-Output "Matched 6.2.3" }
|
||||||
|
'6.3.1' { Write-Output "Matched 6.3.1" }
|
||||||
|
'6.5.1' { Write-Output "Matched 6.5.1" }
|
||||||
|
'6.5.2' { Write-Output "Matched 6.5.2" }
|
||||||
|
'6.5.3' { Write-Output "Matched 6.5.3" }
|
||||||
|
'8.6.1' { Write-Output "Matched 8.6.1" }
|
||||||
|
default { Write-Output "No match found" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end {
|
||||||
|
Write-Verbose "Retuning data for Rec: $Rec"
|
||||||
|
}
|
||||||
|
} # end function Get-MgOutput
|
||||||
|
|
@@ -30,7 +30,7 @@ function Test-BlockSharedMailboxSignIn {
|
|||||||
process {
|
process {
|
||||||
try {
|
try {
|
||||||
# Step: Retrieve shared mailbox details
|
# Step: Retrieve shared mailbox details
|
||||||
$MBX = Get-EXOMailbox -RecipientTypeDetails SharedMailbox
|
$MBX = Get-ExoOutput -Rec $recnum
|
||||||
|
|
||||||
# Step: Retrieve details of shared mailboxes from Azure AD (Condition B: Pass/Fail)
|
# Step: Retrieve details of shared mailboxes from Azure AD (Condition B: Pass/Fail)
|
||||||
$sharedMailboxDetails = $MBX | ForEach-Object { Get-AzureADUser -ObjectId $_.ExternalDirectoryObjectId }
|
$sharedMailboxDetails = $MBX | ForEach-Object { Get-AzureADUser -ObjectId $_.ExternalDirectoryObjectId }
|
||||||
|
@@ -33,8 +33,7 @@ function Test-CustomerLockbox {
|
|||||||
process {
|
process {
|
||||||
try {
|
try {
|
||||||
# Step: Retrieve the organization configuration (Condition C: Pass/Fail)
|
# Step: Retrieve the organization configuration (Condition C: Pass/Fail)
|
||||||
$orgConfig = Get-OrganizationConfig | Select-Object CustomerLockBoxEnabled
|
$customerLockboxEnabled = Get-ExoOutput -Rec $recnum
|
||||||
$customerLockboxEnabled = $orgConfig.CustomerLockBoxEnabled
|
|
||||||
|
|
||||||
# Step: Prepare failure reasons and details based on compliance (Condition A, B, & C: Fail)
|
# Step: Prepare failure reasons and details based on compliance (Condition A, B, & C: Fail)
|
||||||
$failureReasons = if (-not $customerLockboxEnabled) {
|
$failureReasons = if (-not $customerLockboxEnabled) {
|
||||||
|
@@ -31,7 +31,7 @@ function Test-ExternalSharingCalendars {
|
|||||||
process {
|
process {
|
||||||
try {
|
try {
|
||||||
# Step: Retrieve sharing policies related to calendar sharing
|
# Step: Retrieve sharing policies related to calendar sharing
|
||||||
$sharingPolicies = Get-SharingPolicy | Where-Object { $_.Domains -like '*CalendarSharing*' }
|
$sharingPolicies = Get-ExoOutput -Rec $recnum
|
||||||
|
|
||||||
# Step (Condition A & B: Pass/Fail): Check if calendar sharing is disabled in all applicable policies
|
# Step (Condition A & B: Pass/Fail): Check if calendar sharing is disabled in all applicable policies
|
||||||
$isExternalSharingDisabled = $true
|
$isExternalSharingDisabled = $true
|
||||||
|
@@ -40,33 +40,12 @@ function Test-SafeLinksOfficeApps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
process {
|
process {
|
||||||
if (Get-Command Get-SafeLinksPolicy -ErrorAction SilentlyContinue) {
|
# 2.1.1 (L2) Ensure Safe Links for Office Applications is Enabled
|
||||||
|
# Retrieve all Safe Links policies
|
||||||
|
$misconfiguredDetails = Get-ExoOutput -Rec $recnum
|
||||||
|
# Misconfigured details returns 1 if EXO Commands needed for the test are not available
|
||||||
|
if ($misconfiguredDetails -ne 1) {
|
||||||
try {
|
try {
|
||||||
# 2.1.1 (L2) Ensure Safe Links for Office Applications is Enabled
|
|
||||||
# Retrieve all Safe Links policies
|
|
||||||
$policies = Get-SafeLinksPolicy
|
|
||||||
# Initialize the details collection
|
|
||||||
$misconfiguredDetails = @()
|
|
||||||
|
|
||||||
foreach ($policy in $policies) {
|
|
||||||
# Get the detailed configuration of each policy
|
|
||||||
$policyDetails = Get-SafeLinksPolicy -Identity $policy.Name
|
|
||||||
|
|
||||||
# Check each required property and record failures
|
|
||||||
# Condition A: Checking policy settings
|
|
||||||
$failures = @()
|
|
||||||
if ($policyDetails.EnableSafeLinksForEmail -ne $true) { $failures += "EnableSafeLinksForEmail: False" } # Email: On
|
|
||||||
if ($policyDetails.EnableSafeLinksForTeams -ne $true) { $failures += "EnableSafeLinksForTeams: False" } # Teams: On
|
|
||||||
if ($policyDetails.EnableSafeLinksForOffice -ne $true) { $failures += "EnableSafeLinksForOffice: False" } # Office 365 Apps: On
|
|
||||||
if ($policyDetails.TrackClicks -ne $true) { $failures += "TrackClicks: False" } # Click protection settings: On
|
|
||||||
if ($policyDetails.AllowClickThrough -ne $false) { $failures += "AllowClickThrough: True" } # Do not track when users click safe links: Off
|
|
||||||
|
|
||||||
# Only add details for policies that have misconfigurations
|
|
||||||
if ($failures.Count -gt 0) {
|
|
||||||
$misconfiguredDetails += "Policy: $($policy.Name); Failures: $($failures -join ', ')"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Prepare the final result
|
# Prepare the final result
|
||||||
# Condition B: Ensuring no misconfigurations
|
# Condition B: Ensuring no misconfigurations
|
||||||
$result = $misconfiguredDetails.Count -eq 0
|
$result = $misconfiguredDetails.Count -eq 0
|
||||||
|
27
tests/Unit/Private/Get-ExoOutput.tests.ps1
Normal file
27
tests/Unit/Private/Get-ExoOutput.tests.ps1
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
$ProjectPath = "$PSScriptRoot\..\..\.." | Convert-Path
|
||||||
|
$ProjectName = ((Get-ChildItem -Path $ProjectPath\*\*.psd1).Where{
|
||||||
|
($_.Directory.Name -match 'source|src' -or $_.Directory.Name -eq $_.BaseName) -and
|
||||||
|
$(try { Test-ModuleManifest $_.FullName -ErrorAction Stop } catch { $false } )
|
||||||
|
}).BaseName
|
||||||
|
|
||||||
|
|
||||||
|
Import-Module $ProjectName
|
||||||
|
|
||||||
|
InModuleScope $ProjectName {
|
||||||
|
Describe Get-PrivateFunction {
|
||||||
|
Context 'Default' {
|
||||||
|
BeforeEach {
|
||||||
|
$return = Get-PrivateFunction -PrivateData 'string'
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'Returns a single object' {
|
||||||
|
($return | Measure-Object).Count | Should -Be 1
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'Returns a string based on the parameter PrivateData' {
|
||||||
|
$return | Should -Be 'string'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user