diff --git a/powershell/public/cis/Test-MtCisDkim.ps1 b/powershell/public/cis/Test-MtCisDkim.ps1 index 3fbf57653..f47970d47 100644 --- a/powershell/public/cis/Test-MtCisDkim.ps1 +++ b/powershell/public/cis/Test-MtCisDkim.ps1 @@ -42,6 +42,17 @@ $_.domain -eq $domain.domainname } + if (-not $dkimSigningConfig) { + $dkimRecord = [PSCustomObject]@{ + domain = $domain.DomainName + pass = if ($domain.SendingFromDomainDisabled) { 'Skipped' } elseif ($domain.InitialDomain -eq $true) { 'Passed' } else { 'Failed' } + reason = if ($domain.SendingFromDomainDisabled) { 'Parked domain' } elseif ($domain.InitialDomain -eq $true) { 'Microsoft auto-signs DKIM for the initial onmicrosoft.com domain' } else { 'No DkimSigningConfig found for domain' } + dkimRecord = $null + } + $dkimRecords += $dkimRecord + continue + } + if ((Get-Date) -gt $dkimSigningConfig.RotateOnDate) { if ($Selector -ne $dkimSigningConfig.SelectorAfterRotateOnDate) { Write-Verbose "Using DKIM $($dkimSigningConfig.SelectorAfterRotateOnDate) based on EXO config" diff --git a/powershell/public/cisa/exchange/Test-MtCisaDkim.ps1 b/powershell/public/cisa/exchange/Test-MtCisaDkim.ps1 index 8bc94b05b..d25901815 100644 --- a/powershell/public/cisa/exchange/Test-MtCisaDkim.ps1 +++ b/powershell/public/cisa/exchange/Test-MtCisaDkim.ps1 @@ -40,6 +40,17 @@ $dkimSigningConfig = $dkimSigningConfigs | Where-Object {` $_.domain -eq $domain.domainname } + + if (-not $dkimSigningConfig) { + $dkimRecord = [PSCustomObject]@{ + domain = $domain.DomainName + pass = if ($domain.SendingFromDomainDisabled) { 'Skipped' } elseif ($domain.InitialDomain -eq $true) { 'Passed' } else { 'Failed' } + reason = if ($domain.SendingFromDomainDisabled) { 'Parked domain' } elseif ($domain.InitialDomain -eq $true) { 'Microsoft auto-signs DKIM for the initial onmicrosoft.com domain' } else { 'No DkimSigningConfig found for domain' } + dkimRecord = $null + } + $dkimRecords += $dkimRecord + continue + } if ((Get-Date) -gt $dkimSigningConfig.RotateOnDate) { if ($Selector -ne $dkimSigningConfig.SelectorAfterRotateOnDate) { Write-Verbose "Using DKIM $($dkimSigningConfig.SelectorAfterRotateOnDate) based on EXO config" diff --git a/powershell/tests/functions/Test-MtDkim.Tests.ps1 b/powershell/tests/functions/Test-MtDkim.Tests.ps1 new file mode 100644 index 000000000..5e8c8498d --- /dev/null +++ b/powershell/tests/functions/Test-MtDkim.Tests.ps1 @@ -0,0 +1,88 @@ +BeforeAll { + Import-Module "$PSScriptRoot/../../Maester.psd1" -Force +} + +Describe 'DKIM checks with no signing configuration' -ForEach @( + @{ CommandName = 'Test-MtCisDkim' } + @{ CommandName = 'Test-MtCisaDkim' } +) { + BeforeEach { + Mock -ModuleName Maester Test-MtConnection { return $true } + Mock -ModuleName Maester Add-MtTestResultDetail { } + Mock -ModuleName Maester Get-MailAuthenticationRecord { + throw 'DNS lookup should not be attempted without a DKIM signing configuration' + } + } + + It ' returns for ' -ForEach @( + @{ + DomainName = 'contoso.onmicrosoft.com' + InitialDomain = $true + IsCoexistenceDomain = $false + SendingFromDomainDisabled = $false + ExpectedOutcome = 'passed' + ExpectedResult = $true + } + @{ + DomainName = 'secondary.onmicrosoft.com' + InitialDomain = $false + IsCoexistenceDomain = $false + SendingFromDomainDisabled = $false + ExpectedOutcome = 'failed' + ExpectedResult = $false + } + @{ + DomainName = 'parked.example' + InitialDomain = $false + IsCoexistenceDomain = $false + SendingFromDomainDisabled = $true + ExpectedOutcome = 'skipped' + ExpectedResult = $null + } + @{ + DomainName = 'contoso.mail.onmicrosoft.com' + InitialDomain = $false + IsCoexistenceDomain = $true + SendingFromDomainDisabled = $false + ExpectedOutcome = 'failed' + ExpectedResult = $false + } + @{ + DomainName = 'contoso.mail.onmicrosoft.com' + InitialDomain = $false + IsCoexistenceDomain = $true + SendingFromDomainDisabled = $true + ExpectedOutcome = 'skipped' + ExpectedResult = $null + } + @{ + DomainName = 'contoso.com' + InitialDomain = $false + IsCoexistenceDomain = $false + SendingFromDomainDisabled = $false + ExpectedOutcome = 'failed' + ExpectedResult = $false + } + ) { + Mock -ModuleName Maester Get-MtExo { + if ($Request -eq 'AcceptedDomain') { + return [PSCustomObject]@{ + DomainName = $DomainName + InitialDomain = $InitialDomain + IsCoexistenceDomain = $IsCoexistenceDomain + SendingFromDomainDisabled = $SendingFromDomainDisabled + } + } + + return @() + } + + $result = & $CommandName + if ($null -eq $ExpectedResult) { + $result | Should -BeNullOrEmpty + } else { + $result | Should -Be $ExpectedResult + } + Should -Invoke Get-MailAuthenticationRecord -ModuleName Maester -Exactly 0 + } +} diff --git a/website/contributors/contributors.yml b/website/contributors/contributors.yml index 327ff082f..c2e9caef9 100644 --- a/website/contributors/contributors.yml +++ b/website/contributors/contributors.yml @@ -30,6 +30,12 @@ alexandair: name: Aleksandar Nikolić title: Microsoft MVP +amlhive-tech: + name: Haris Habib + company: AMLHIVE + emails: + - tech@amlhive.com.au + amandaw33: andremieth: