From f13f85d26473a5215c4d5c663a790cf0840e8aa5 Mon Sep 17 00:00:00 2001 From: mario Date: Tue, 2 Jan 2024 18:50:01 +0100 Subject: [PATCH 01/12] new resource --- CHANGELOG.md | 3 + .../MSFT_EXOReportSubmissionPolicy.psm1 | 735 ++++++++++++++++++ .../MSFT_EXOReportSubmissionPolicy.schema.mof | 39 + .../MSFT_EXOReportSubmissionPolicy/readme.md | 5 + .../settings.json | 33 + .../1-ConfigureReportSubmissionPolicy.ps1 | 36 + ...365DSC.EXOReportSubmissionPolicy.Tests.ps1 | 267 +++++++ 7 files changed, 1118 insertions(+) create mode 100644 Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.psm1 create mode 100644 Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.schema.mof create mode 100644 Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/readme.md create mode 100644 Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/settings.json create mode 100644 Modules/Microsoft365DSC/Examples/Resources/EXOReportSubmissionPolicy/1-ConfigureReportSubmissionPolicy.ps1 create mode 100644 Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index d49b1cbffe..056c7fe2eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ * TeamsChannel * Add error handling if GroupId of a team is null FIXES [#3943](https://github.com/microsoft/Microsoft365DSC/issues/3943) +* EXOReportSubmissionPolicy + * Initial release + FIXES [#3690](https://github.com/microsoft/Microsoft365DSC/issues/3690) # 1.23.1227.1 diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.psm1 new file mode 100644 index 0000000000..9f3ade5ba2 --- /dev/null +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.psm1 @@ -0,0 +1,735 @@ +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [ValidateSet('Yes')] + [System.String] + $IsSingleInstance, + + [Parameter(Mandatory = $true)] + [System.String] + $Identity, + + [Parameter()] + [System.Boolean] + $DisableQuarantineReportingOption, + + [Parameter()] + [System.Boolean] + $EnableCustomNotificationSender, + + [Parameter()] + [System.Boolean] + $EnableOrganizationBranding, + + [Parameter()] + [System.Boolean] + $EnableReportToMicrosoft, + + [Parameter()] + [System.Boolean] + $EnableThirdPartyAddress, + + [Parameter()] + [System.Boolean] + $EnableUserEmailNotification, + + [Parameter()] + [System.String] + $JunkReviewResultMessage, + + [Parameter()] + [System.String] + $NotJunkReviewResultMessage, + + [Parameter()] + [System.String] + $NotificationFooterMessage, + + [Parameter()] + [System.String] + $NotificationSenderAddress, + + [Parameter()] + [System.String] + $PhishingReviewResultMessage, + + [Parameter()] + [System.String] + $PostSubmitMessage, + + [Parameter()] + [System.Boolean] + $PostSubmitMessageEnabled, + + [Parameter()] + [System.String] + $PostSubmitMessageTitle, + + [Parameter()] + [System.String] + $PreSubmitMessage, + + [Parameter()] + [System.Boolean] + $PreSubmitMessageEnabled, + + [Parameter()] + [System.String] + $PreSubmitMessageTitle, + + [Parameter()] + [System.String[]] + $ReportJunkAddresses = @(), + + [Parameter()] + [System.Boolean] + $ReportJunkToCustomizedAddress, + + [Parameter()] + [System.String[]] + $ReportNotJunkAddresses = @(), + + [Parameter()] + [System.Boolean] + $ReportNotJunkToCustomizedAddress, + + [Parameter()] + [System.String[]] + $ReportPhishAddresses = @(), + + [Parameter()] + [System.Boolean] + $ReportPhishToCustomizedAddress, + + [Parameter()] + [System.String[]] + $ThirdPartyReportAddresses = @(), + + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.Management.Automation.PSCredential] + $Credential, + + [Parameter()] + [System.String] + $ApplicationId, + + [Parameter()] + [System.String] + $TenantId, + + [Parameter()] + [System.String] + $CertificateThumbprint, + + [Parameter()] + [System.String] + $CertificatePath, + + [Parameter()] + [System.Management.Automation.PSCredential] + $CertificatePassword, + + [Parameter()] + [Switch] + $ManagedIdentity + ) + + Write-Verbose -Message "Getting configuration of ReportSubmissionPolicy for $($Identity)" + if ($Global:CurrentModeIsExport) + { + $ConnectionMode = New-M365DSCConnection -Workload 'ExchangeOnline' ` + -InboundParameters $PSBoundParameters ` + -SkipModuleReload $true + } + else + { + $ConnectionMode = New-M365DSCConnection -Workload 'ExchangeOnline' ` + -InboundParameters $PSBoundParameters + } + + #Ensure the proper dependencies are installed in the current environment. + Confirm-M365DSCDependencies + + #region Telemetry + $ResourceName = $MyInvocation.MyCommand.ModuleName -replace 'MSFT_', '' + $CommandName = $MyInvocation.MyCommand + $data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName ` + -CommandName $CommandName ` + -Parameters $PSBoundParameters + Add-M365DSCTelemetryEvent -Data $data + #endregion + + $nullReturn = $PSBoundParameters + $nullReturn.Ensure = 'Absent' + $nullReturn.IsSingleInstance = 'Yes' + + try + { + $ReportSubmissionPolicies = Get-ReportSubmissionPolicy -ErrorAction Stop + + $ReportSubmissionPolicy = $ReportSubmissionPolicies | Where-Object -FilterScript { $_.Identity -eq $Identity } + if ($null -eq $ReportSubmissionPolicy) + { + Write-Verbose -Message "ReportSubmissionPolicy $($Identity) does not exist." + return $nullReturn + } + else + { + $result = @{ + IsSingleInstance = 'Yes' + Identity = $Identity + DisableQuarantineReportingOption = $ReportSubmissionPolicy.DisableQuarantineReportingOption + EnableCustomNotificationSender = $ReportSubmissionPolicy.EnableCustomNotificationSender + EnableOrganizationBranding = $ReportSubmissionPolicy.EnableOrganizationBranding + EnableReportToMicrosoft = $ReportSubmissionPolicy.EnableReportToMicrosoft + EnableThirdPartyAddress = $ReportSubmissionPolicy.EnableThirdPartyAddress + EnableUserEmailNotification = $ReportSubmissionPolicy.EnableUserEmailNotification + JunkReviewResultMessage = $ReportSubmissionPolicy.JunkReviewResultMessage + NotJunkReviewResultMessage = $ReportSubmissionPolicy.NotJunkReviewResultMessage + NotificationFooterMessage = $ReportSubmissionPolicy.NotificationFooterMessage + NotificationSenderAddress = $ReportSubmissionPolicy.NotificationSenderAddress + PhishingReviewResultMessage = $ReportSubmissionPolicy.PhishingReviewResultMessage + PostSubmitMessage = $ReportSubmissionPolicy.PostSubmitMessage + PostSubmitMessageEnabled = $ReportSubmissionPolicy.PostSubmitMessageEnabled + PostSubmitMessageTitle = $ReportSubmissionPolicy.PostSubmitMessageTitle + PreSubmitMessage = $ReportSubmissionPolicy.PreSubmitMessage + PreSubmitMessageEnabled = $ReportSubmissionPolicy.PreSubmitMessageEnabled + PreSubmitMessageTitle = $ReportSubmissionPolicy.PreSubmitMessageTitle + ReportJunkAddresses = $ReportSubmissionPolicy.ReportJunkAddresses + ReportJunkToCustomizedAddress = $ReportSubmissionPolicy.ReportJunkToCustomizedAddress + ReportNotJunkAddresses = $ReportSubmissionPolicy.ReportNotJunkAddresses + ReportNotJunkToCustomizedAddress = $ReportSubmissionPolicy.ReportNotJunkToCustomizedAddress + ReportPhishAddresses = $ReportSubmissionPolicy.ReportPhishAddresses + ReportPhishToCustomizedAddress = $ReportSubmissionPolicy.ReportPhishToCustomizedAddress + ThirdPartyReportAddresses = $ReportSubmissionPolicy.ThirdPartyReportAddresses + Credential = $Credential + Ensure = 'Present' + ApplicationId = $ApplicationId + CertificateThumbprint = $CertificateThumbprint + CertificatePath = $CertificatePath + CertificatePassword = $CertificatePassword + Managedidentity = $ManagedIdentity.IsPresent + TenantId = $TenantId + } + + Write-Verbose -Message "Found ReportSubmissionPolicy $($Identity)" + Write-Verbose -Message "Get-TargetResource Result: `n $(Convert-M365DscHashtableToString -Hashtable $result)" + return $result + } + } + catch + { + New-M365DSCLogEntry -Message 'Error retrieving data:' ` + -Exception $_ ` + -Source $($MyInvocation.MyCommand.Source) ` + -TenantId $TenantId ` + -Credential $Credential + + return $nullReturn + } +} + +function Set-TargetResource +{ + [CmdletBinding()] + + param + ( + [Parameter(Mandatory = $true)] + [ValidateSet('Yes')] + [System.String] + $IsSingleInstance, + + [Parameter(Mandatory = $true)] + [System.String] + $Identity, + + [Parameter()] + [System.Boolean] + $DisableQuarantineReportingOption, + + [Parameter()] + [System.Boolean] + $EnableCustomNotificationSender, + + [Parameter()] + [System.Boolean] + $EnableOrganizationBranding, + + [Parameter()] + [System.Boolean] + $EnableReportToMicrosoft, + + [Parameter()] + [System.Boolean] + $EnableThirdPartyAddress, + + [Parameter()] + [System.Boolean] + $EnableUserEmailNotification, + + [Parameter()] + [System.String] + $JunkReviewResultMessage, + + [Parameter()] + [System.String] + $NotJunkReviewResultMessage, + + [Parameter()] + [System.String] + $NotificationFooterMessage, + + [Parameter()] + [System.String] + $NotificationSenderAddress, + + [Parameter()] + [System.String] + $PhishingReviewResultMessage, + + [Parameter()] + [System.String] + $PostSubmitMessage, + + [Parameter()] + [System.Boolean] + $PostSubmitMessageEnabled, + + [Parameter()] + [System.String] + $PostSubmitMessageTitle, + + [Parameter()] + [System.String] + $PreSubmitMessage, + + [Parameter()] + [System.Boolean] + $PreSubmitMessageEnabled, + + [Parameter()] + [System.String] + $PreSubmitMessageTitle, + + [Parameter()] + [System.String[]] + $ReportJunkAddresses = @(), + + [Parameter()] + [System.Boolean] + $ReportJunkToCustomizedAddress, + + [Parameter()] + [System.String[]] + $ReportNotJunkAddresses = @(), + + [Parameter()] + [System.Boolean] + $ReportNotJunkToCustomizedAddress, + + [Parameter()] + [System.String[]] + $ReportPhishAddresses = @(), + + [Parameter()] + [System.Boolean] + $ReportPhishToCustomizedAddress, + + [Parameter()] + [System.String[]] + $ThirdPartyReportAddresses = @(), + + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.Management.Automation.PSCredential] + $Credential, + + [Parameter()] + [System.String] + $ApplicationId, + + [Parameter()] + [System.String] + $TenantId, + + [Parameter()] + [System.String] + $CertificateThumbprint, + + [Parameter()] + [System.String] + $CertificatePath, + + [Parameter()] + [System.Management.Automation.PSCredential] + $CertificatePassword, + + [Parameter()] + [Switch] + $ManagedIdentity + ) + #Ensure the proper dependencies are installed in the current environment. + Confirm-M365DSCDependencies + + #region Telemetry + $ResourceName = $MyInvocation.MyCommand.ModuleName -replace 'MSFT_', '' + $CommandName = $MyInvocation.MyCommand + $data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName ` + -CommandName $CommandName ` + -Parameters $PSBoundParameters + Add-M365DSCTelemetryEvent -Data $data + #endregion + Write-Verbose -Message "Setting configuration of ReportSubmissionPolicy for $($Identity)" + + $ConnectionMode = New-M365DSCConnection -Workload 'ExchangeOnline' ` + -InboundParameters $PSBoundParameters + + $currentReportSubmissionPolicy = Get-TargetResource @PSBoundParameters + + $ReportSubmissionPolicyParams = [System.Collections.Hashtable]($PSBoundParameters) + $ReportSubmissionPolicyParams.Remove('Ensure') | Out-Null + $ReportSubmissionPolicyParams.Remove('IsSingleInstance') | Out-Null + $ReportSubmissionPolicyParams.Remove('Credential') | Out-Null + $ReportSubmissionPolicyParams.Remove('ApplicationId') | Out-Null + $ReportSubmissionPolicyParams.Remove('TenantId') | Out-Null + $ReportSubmissionPolicyParams.Remove('CertificateThumbprint') | Out-Null + $ReportSubmissionPolicyParams.Remove('CertificatePath') | Out-Null + $ReportSubmissionPolicyParams.Remove('CertificatePassword') | Out-Null + $ReportSubmissionPolicyParams.Remove('ManagedIdentity') | Out-Null + + if ($Ensure -eq 'Present' -and $currentReportSubmissionPolicy.Ensure -eq 'Absent') + { + Write-Verbose -Message "Creating ReportSubmissionPolicy $($Identity)." + + New-ReportSubmissionPolicy + Set-ReportSubmissionPolicy @ReportSubmissionPolicyParams -Confirm:$false + } + elseif ($Ensure -eq 'Present' -and $currentReportSubmissionPolicy.Ensure -eq 'Present') + { + Write-Verbose -Message "Setting ReportSubmissionPolicy $($Identity) with values: $(Convert-M365DscHashtableToString -Hashtable $ReportSubmissionPolicyParams)" + Set-ReportSubmissionPolicy @ReportSubmissionPolicyParams -Confirm:$false + } + elseif ($Ensure -eq 'Absent' -and $currentReportSubmissionPolicy.Ensure -eq 'Present') + { + Write-Verbose -Message "Removing ReportSubmissionPolicy $($Identity)" + Remove-ReportSubmissionPolicy -Identity $Identity + } +} + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [ValidateSet('Yes')] + [System.String] + $IsSingleInstance, + + [Parameter(Mandatory = $true)] + [System.String] + $Identity, + + [Parameter()] + [System.Boolean] + $DisableQuarantineReportingOption, + + [Parameter()] + [System.Boolean] + $EnableCustomNotificationSender, + + [Parameter()] + [System.Boolean] + $EnableOrganizationBranding, + + [Parameter()] + [System.Boolean] + $EnableReportToMicrosoft, + + [Parameter()] + [System.Boolean] + $EnableThirdPartyAddress, + + [Parameter()] + [System.Boolean] + $EnableUserEmailNotification, + + [Parameter()] + [System.String] + $JunkReviewResultMessage, + + [Parameter()] + [System.String] + $NotJunkReviewResultMessage, + + [Parameter()] + [System.String] + $NotificationFooterMessage, + + [Parameter()] + [System.String] + $NotificationSenderAddress, + + [Parameter()] + [System.String] + $PhishingReviewResultMessage, + + [Parameter()] + [System.String] + $PostSubmitMessage, + + [Parameter()] + [System.Boolean] + $PostSubmitMessageEnabled, + + [Parameter()] + [System.String] + $PostSubmitMessageTitle, + + [Parameter()] + [System.String] + $PreSubmitMessage, + + [Parameter()] + [System.Boolean] + $PreSubmitMessageEnabled, + + [Parameter()] + [System.String] + $PreSubmitMessageTitle, + + [Parameter()] + [System.String[]] + $ReportJunkAddresses = @(), + + [Parameter()] + [System.Boolean] + $ReportJunkToCustomizedAddress, + + [Parameter()] + [System.String[]] + $ReportNotJunkAddresses = @(), + + [Parameter()] + [System.Boolean] + $ReportNotJunkToCustomizedAddress, + + [Parameter()] + [System.String[]] + $ReportPhishAddresses = @(), + + [Parameter()] + [System.Boolean] + $ReportPhishToCustomizedAddress, + + [Parameter()] + [System.String[]] + $ThirdPartyReportAddresses = @(), + + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.Management.Automation.PSCredential] + $Credential, + + [Parameter()] + [System.String] + $ApplicationId, + + [Parameter()] + [System.String] + $TenantId, + + [Parameter()] + [System.String] + $CertificateThumbprint, + + [Parameter()] + [System.String] + $CertificatePath, + + [Parameter()] + [System.Management.Automation.PSCredential] + $CertificatePassword, + + [Parameter()] + [Switch] + $ManagedIdentity + ) + #Ensure the proper dependencies are installed in the current environment. + Confirm-M365DSCDependencies + + #region Telemetry + $ResourceName = $MyInvocation.MyCommand.ModuleName -replace 'MSFT_', '' + $CommandName = $MyInvocation.MyCommand + $data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName ` + -CommandName $CommandName ` + -Parameters $PSBoundParameters + Add-M365DSCTelemetryEvent -Data $data + #endregion + + Write-Verbose -Message "Testing configuration of ReportSubmissionPolicy for $($Identity)" + + $CurrentValues = Get-TargetResource @PSBoundParameters + + Write-Verbose -Message "Current Values: $(Convert-M365DscHashtableToString -Hashtable $CurrentValues)" + Write-Verbose -Message "Target Values: $(Convert-M365DscHashtableToString -Hashtable $PSBoundParameters)" + + $ValuesToCheck = $PSBoundParameters + $ValuesToCheck.Remove('Credential') | Out-Null + $ValuesToCheck.Remove('ApplicationId') | Out-Null + $ValuesToCheck.Remove('TenantId') | Out-Null + $ValuesToCheck.Remove('CertificateThumbprint') | Out-Null + $ValuesToCheck.Remove('CertificatePath') | Out-Null + $ValuesToCheck.Remove('CertificatePassword') | Out-Null + $ValuesToCheck.Remove('ManagedIdentity') | Out-Null + + $TestResult = Test-M365DSCParameterState -CurrentValues $CurrentValues ` + -Source $($MyInvocation.MyCommand.Source) ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck $ValuesToCheck.Keys + + Write-Verbose -Message "Test-TargetResource returned $($TestResult)" + + return $TestResult +} + +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param + ( + [Parameter()] + [System.Management.Automation.PSCredential] + $Credential, + + [Parameter()] + [System.String] + $ApplicationId, + + [Parameter()] + [System.String] + $TenantId, + + [Parameter()] + [System.String] + $CertificateThumbprint, + + [Parameter()] + [System.String] + $CertificatePath, + + [Parameter()] + [System.Management.Automation.PSCredential] + $CertificatePassword, + + [Parameter()] + [Switch] + $ManagedIdentity + ) + $ConnectionMode = New-M365DSCConnection -Workload 'ExchangeOnline' ` + -InboundParameters $PSBoundParameters ` + -SkipModuleReload $true + + #Ensure the proper dependencies are installed in the current environment. + Confirm-M365DSCDependencies + + #region Telemetry + $ResourceName = $MyInvocation.MyCommand.ModuleName -replace 'MSFT_', '' + $CommandName = $MyInvocation.MyCommand + $data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName ` + -CommandName $CommandName ` + -Parameters $PSBoundParameters + Add-M365DSCTelemetryEvent -Data $data + #endregion + + try + { + [array]$ReportSubmissionPolicies = Get-ReportSubmissionPolicy -ErrorAction Stop + if ($ReportSubmissionPolicies.Length -eq 0) + { + Write-Host $Global:M365DSCEmojiGreenCheckMark + } + else + { + Write-Host "`r`n" -NoNewline + } + $dscContent = '' + $i = 1 + foreach ($ReportSubmissionPolicy in $ReportSubmissionPolicies) + { + Write-Host " |---[$i/$($ReportSubmissionPolicies.length)] $($ReportSubmissionPolicy.Identity)" -NoNewline + + $Params = @{ + Identity = $ReportSubmissionPolicy.Identity + Credential = $Credential + ApplicationId = $ApplicationId + TenantId = $TenantId + CertificateThumbprint = $CertificateThumbprint + CertificatePassword = $CertificatePassword + Managedidentity = $ManagedIdentity.IsPresent + CertificatePath = $CertificatePath + } + + $Results = Get-TargetResource @Params + + $keysToRemove = @() + foreach ($key in $Results.Keys) + { + if ([System.String]::IsNullOrEmpty($Results.$key)) + { + $keysToRemove += $key + } + } + foreach ($key in $keysToRemove) + { + $Results.Remove($key) | Out-Null + } + $Results = Update-M365DSCExportAuthenticationResults -ConnectionMode $ConnectionMode ` + -Results $Results + $currentDSCBlock = Get-M365DSCExportContentForResource -ResourceName $ResourceName ` + -ConnectionMode $ConnectionMode ` + -ModulePath $PSScriptRoot ` + -Results $Results ` + -Credential $Credential + $dscContent += $currentDSCBlock + Save-M365DSCPartialExport -Content $currentDSCBlock ` + -FileName $Global:PartialExportFileName + Write-Host $Global:M365DSCEmojiGreenCheckMark + $i++ + } + return $dscContent + } + catch + { + Write-Host $Global:M365DSCEmojiRedX + + New-M365DSCLogEntry -Message 'Error during Export:' ` + -Exception $_ ` + -Source $($MyInvocation.MyCommand.Source) ` + -TenantId $TenantId ` + -Credential $Credential + + return '' + } +} +Export-ModuleMember -Function *-TargetResource diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.schema.mof b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.schema.mof new file mode 100644 index 0000000000..a315d20b27 --- /dev/null +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.schema.mof @@ -0,0 +1,39 @@ + +[ClassVersion("1.0.0.0"), FriendlyName("EXOReportSubmissionPolicy")] +class MSFT_EXOReportSubmissionPolicy : OMI_BaseResource +{ + [Key, Description("Specifies the resource is a single instance, the value must be 'Yes'."), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance; + [Write, Description("The Identity parameter specifies the report submission policy you want to modify. There can be only one policy.")] String Identity; + [Write, Description("The DisableQuarantineReportingOption parameter allows or prevents users from reporting messages in quarantine.")] Boolean DisableQuarantineReportingOption; + [Write, Description("The EnableCustomNotificationSender parameter specifies whether a custom sender email address is used for result messages after an admin reviews and marks the reported messages as junk, not junk, or phishing.")] Boolean EnableCustomNotificationSender; + [Write, Description("The EnableOrganizationBranding parameter specifies whether to show the company logo in the footer of result messages that users receive after an admin reviews and marks the reported messages as junk, not junk, or phishing.")] Boolean EnableOrganizationBranding; + [Write, Description("The EnableReportToMicrosoft parameter specifies whether Microsoft integrated reporting experience is enabled or disabled.")] Boolean EnableReportToMicrosoft; + [Write, Description("The EnableThirdPartyAddress parameter specifies whether you're using third-party reporting tools in Outlook instead of Microsoft tools to send messages to the reporting mailbox in Exchange Online.")] Boolean EnableThirdPartyAddress; + [Write, Description("The EnableUserEmailNotification parameter species whether users receive result messages after an admin reviews and marks the reported messages as junk, not junk, or phishing.")] Boolean EnableUserEmailNotification; + [Write, Description("The JunkReviewResultMessage parameter specifies the custom text to use in result messages after an admin reviews and marks the reported messages as junk.")] String JunkReviewResultMessage; + [Write, Description("The NotJunkReviewResultMessage parameter specifies the custom text to use in result messages after an admin reviews and marks the reported messages as not junk.")] String NotJunkReviewResultMessage; + [Write, Description("The NotificationFooterMessage parameter specifies the custom footer text to use in email notifications after an admin reviews and marks the reported messages as junk, not junk, or phishing.")] String NotificationFooterMessage; + [Write, Description("The NotificationSenderAddress parameter specifies the sender email address to use in result messages after an admin reviews and marks the reported messages as junk, not junk, or phishing.")] String NotificationSenderAddress; + [Write, Description("The PhishingReviewResultMessage parameter specifies the custom text to use in result messages after an admin reviews and marks the reported messages as phishing.")] String PhishingReviewResultMessage; + [Write, Description("The PostSubmitMessage parameter specifies the custom pop-up message text to use in Outlook notifications after users report messages.")] String PostSubmitMessage; + [Write, Description("The PostSubmitMessageEnabled parameter enables or disables the pop-up Outlook notifications that users see after they report messages using Microsoft reporting tools.")] Boolean PostSubmitMessageEnabled; + [Write, Description("The PostSubmitMessage parameter parameter specifies the custom pop-up message title to use in Outlook notifications after users report messages.")] String PostSubmitMessageTitle; + [Write, Description("The PreSubmitMessage parameter specifies the custom pop-up message text to use in Outlook notifications before users report messages. ")] String PreSubmitMessage; + [Write, Description("The PreSubmitMessageEnabled parameter enables or disables the pop-up Outlook notifications that users see before they report messages using Microsoft reporting tools.")] Boolean PreSubmitMessageEnabled; + [Write, Description("The PreSubmitMessage parameter parameter specifies the custom pop-up message title to use in Outlook notifications before users report messages.")] String PreSubmitMessageTitle; + [Write, Description("The ReportJunkAddresses parameter specifies the email address of the reporting mailbox in Exchange Online to receive user reported messages in reporting in Outlook using Microsoft or third-party reporting tools in Outlook.")] String ReportJunkAddresses[]; + [Write, Description("The ReportJunkToCustomizedAddress parameter specifies whether to send user reported messages from Outlook (using Microsoft or third-party reporting tools) to the reporting mailbox as part of reporting in Outlook. ")] Boolean ReportJunkToCustomizedAddress; + [Write, Description("The ReportNotJunkAddresses parameter specifies the email address of the reporting mailbox in Exchange Online to receive user reported messages in reporting in Outlook using Microsoft or third-party reporting tools in Outlook.")] String ReportNotJunkAddresses[]; + [Write, Description("The ReportNotJunkToCustomizedAddress parameter specifies whether to send user reported messages from Outlook (using Microsoft or third-party reporting tools) to the reporting mailbox as part of reporting in Outlook.")] Boolean ReportNotJunkToCustomizedAddress; + [Write, Description("The ReportPhishAddresses parameter specifies the email address of the reporting mailbox in Exchange Online to receive user reported messages in reporting in Outlook using Microsoft or third-party reporting tools in Outlook.")] String ReportPhishAddresses[]; + [Write, Description("he ReportPhishToCustomizedAddress parameter specifies whether to send user reported messages from Outlook (using Microsoft or third-party reporting tools) to the reporting mailbox as part of reporting in Outlook.")] Boolean ReportPhishToCustomizedAddress; + [Write, Description("Use the ThirdPartyReportAddresses parameter to specify the email address of the reporting mailbox when you're using a third-party product for user submissions instead of reporting in Outlook.")] String ThirdPartyReportAddresses[]; + [Write, Description("Specifies if this report submission policy should exist."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; + [Write, Description("Credentials of the Exchange Global Admin"), EmbeddedInstance("MSFT_Credential")] string Credential; + [Write, Description("Id of the Azure Active Directory application to authenticate with.")] String ApplicationId; + [Write, Description("Id of the Azure Active Directory tenant used for authentication.")] String TenantId; + [Write, Description("Thumbprint of the Azure Active Directory application's authentication certificate to use for authentication.")] String CertificateThumbprint; + [Write, Description("Username can be made up to anything but password will be used for CertificatePassword"), EmbeddedInstance("MSFT_Credential")] String CertificatePassword; + [Write, Description("Path to certificate used in service principal usually a PFX file.")] String CertificatePath; + [Write, Description("Managed ID being used for authentication.")] Boolean ManagedIdentity; +}; diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/readme.md b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/readme.md new file mode 100644 index 0000000000..6c01768780 --- /dev/null +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/readme.md @@ -0,0 +1,5 @@ +# EXOReportSubmissionPolicy + +## Description + +Create or modify a EXOReportSubmissionPolicy in your cloud-based organization. diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/settings.json b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/settings.json new file mode 100644 index 0000000000..53824b15a2 --- /dev/null +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/settings.json @@ -0,0 +1,33 @@ +{ + "resourceName": "EXOReportSubmissionPolicy", + "description": "", + "roles": { + "read": [ + "Security Reader" + ], + "update": [ + "Security Administrator" + ] + }, + "permissions": { + "graph": { + "delegated": { + "read": [], + "update": [] + }, + "application": { + "read": [], + "update": [] + } + }, + "exchange": { + "requiredroles": [ + "Transport Hygiene", + "Security Admin", + "View-Only Configuration", + "Security Reader" + ], + "requiredrolegroups": "Organization Management" + } + } +} diff --git a/Modules/Microsoft365DSC/Examples/Resources/EXOReportSubmissionPolicy/1-ConfigureReportSubmissionPolicy.ps1 b/Modules/Microsoft365DSC/Examples/Resources/EXOReportSubmissionPolicy/1-ConfigureReportSubmissionPolicy.ps1 new file mode 100644 index 0000000000..f4ee4bca2e --- /dev/null +++ b/Modules/Microsoft365DSC/Examples/Resources/EXOReportSubmissionPolicy/1-ConfigureReportSubmissionPolicy.ps1 @@ -0,0 +1,36 @@ +<# +This example is used to test new resources and showcase the usage of new resources being worked on. +It is not meant to use as a production baseline. +#> + +Configuration Example +{ + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $Credscredential + ) + Import-DscResource -ModuleName Microsoft365DSC + + node localhost + { + EXOReportSubmissionPolicy 'ConfigureReportSubmissionPolicy' + { + IsSingleInstance = 'Yes'; + Identity = "DefaultReportSubmissionPolicy" + DisableQuarantineReportingOption = $False; + EnableCustomNotificationSender = $False; + EnableOrganizationBranding = $False; + EnableReportToMicrosoft = $True; + EnableThirdPartyAddress = $False; + EnableUserEmailNotification = $False; + PostSubmitMessageEnabled = $True; + PreSubmitMessageEnabled = $True; + ReportJunkToCustomizedAddress = $False; + ReportNotJunkToCustomizedAddress = $False; + ReportPhishToCustomizedAddress = $False; + Ensure = "Present" + Credential = $Credscredential + } + } +} diff --git a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 new file mode 100644 index 0000000000..9825f3b746 --- /dev/null +++ b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 @@ -0,0 +1,267 @@ +[CmdletBinding()] +param( +) +$M365DSCTestFolder = Join-Path -Path $PSScriptRoot ` + -ChildPath '..\..\Unit' ` + -Resolve +$CmdletModule = (Join-Path -Path $M365DSCTestFolder ` + -ChildPath '\Stubs\Microsoft365.psm1' ` + -Resolve) +$GenericStubPath = (Join-Path -Path $M365DSCTestFolder ` + -ChildPath '\Stubs\Generic.psm1' ` + -Resolve) +Import-Module -Name (Join-Path -Path $M365DSCTestFolder ` + -ChildPath '\UnitTestHelper.psm1' ` + -Resolve) + +$Global:DscHelper = New-M365DscUnitTestHelper -StubModule $CmdletModule ` + -DscResource 'EXOReportSubmissionPolicy' -GenericStubModule $GenericStubPath +Describe -Name $Global:DscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:DscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:DscHelper.InitializeScript -NoNewScope + + BeforeAll { + $secpasswd = ConvertTo-SecureString 'test@password1' -AsPlainText -Force + $Credential = New-Object System.Management.Automation.PSCredential ('tenantadmin@mydomain.com', $secpasswd) + + Mock -CommandName Confirm-M365DSCDependencies -MockWith { + } + + Mock -CommandName New-M365DSCConnection -MockWith { + return 'Credentials' + } + + Mock -CommandName Get-PSSession -MockWith { + } + + Mock -CommandName Remove-PSSession -MockWith { + } + + Mock -CommandName New-ReportSubmissionPolicy -MockWith { + } + + Mock -CommandName Set-ReportSubmissionPolicy -MockWith { + } + + Mock -CommandName Remove-ReportSubmissionPolicy -MockWith { + } + + # Mock Write-Host to hide output during the tests + Mock -CommandName Write-Host -MockWith { + } + + Mock -CommandName Write-Warning -MockWith { + } + } + + # Test contexts + Context -Name 'ReportSubmissionPolicy creation.' -Fixture { + BeforeAll { + $testParams = @{ + Ensure = 'Present' + Credential = $Credential + IsSingleInstance = 'Yes'; + Identity = "DefaultReportSubmissionPolicy" + DisableQuarantineReportingOption = $False; + EnableCustomNotificationSender = $False; + EnableOrganizationBranding = $False; + EnableReportToMicrosoft = $True; + EnableThirdPartyAddress = $False; + EnableUserEmailNotification = $False; + PostSubmitMessageEnabled = $True; + PreSubmitMessageEnabled = $True; + ReportJunkToCustomizedAddress = $False; + ReportNotJunkToCustomizedAddress = $False; + ReportPhishToCustomizedAddress = $False; + } + + + Mock -CommandName Get-ReportSubmissionPolicy -MockWith { + return @{ + + } + } + } + + It 'Should return Absent from the Get method' { + (Get-TargetResource @testParams).Ensure | Should -Be 'Absent' + } + + It 'Should return false from the Test method' { + Test-TargetResource @testParams | Should -Be $false + } + + It 'Should call the Set method' { + Set-TargetResource @testParams + } + + } + + Context -Name 'ReportSubmissionPolicy update not required.' -Fixture { + BeforeAll { + $testParams = @{ + Ensure = 'Present' + Credential = $Credential + IsSingleInstance = 'Yes'; + Identity = "DefaultReportSubmissionPolicy" + DisableQuarantineReportingOption = $False; + EnableCustomNotificationSender = $False; + EnableOrganizationBranding = $False; + EnableReportToMicrosoft = $True; + EnableThirdPartyAddress = $False; + EnableUserEmailNotification = $False; + PostSubmitMessageEnabled = $True; + PreSubmitMessageEnabled = $True; + ReportJunkToCustomizedAddress = $False; + ReportNotJunkToCustomizedAddress = $False; + ReportPhishToCustomizedAddress = $False; + } + + Mock -CommandName Get-ReportSubmissionPolicy -MockWith { + return @{ + Ensure = 'Present' + Credential = $Credential + IsSingleInstance = 'Yes'; + Identity = "DefaultReportSubmissionPolicy" + DisableQuarantineReportingOption = $False; + EnableCustomNotificationSender = $False; + EnableOrganizationBranding = $False; + EnableReportToMicrosoft = $True; + EnableThirdPartyAddress = $False; + EnableUserEmailNotification = $False; + PostSubmitMessageEnabled = $True; + PreSubmitMessageEnabled = $True; + ReportJunkToCustomizedAddress = $False; + ReportNotJunkToCustomizedAddress = $False; + ReportPhishToCustomizedAddress = $False; + } + } + } + + It 'Should return true from the Test method' { + Test-TargetResource @testParams | Should -Be $true + } + } + + Context -Name 'ReportSubmissionPolicy update needed.' -Fixture { + BeforeAll { + $testParams = @{ + Ensure = 'Present' + Credential = $Credential + IsSingleInstance = 'Yes'; + Identity = "DefaultReportSubmissionPolicy" + DisableQuarantineReportingOption = $False; + EnableCustomNotificationSender = $False; + EnableOrganizationBranding = $False; + EnableReportToMicrosoft = $True; + EnableThirdPartyAddress = $False; + EnableUserEmailNotification = $False; + PostSubmitMessageEnabled = $True; + PreSubmitMessageEnabled = $True; + ReportJunkToCustomizedAddress = $False; + ReportNotJunkToCustomizedAddress = $False; + ReportPhishToCustomizedAddress = $False; + } + + Mock -CommandName Get-ReportSubmissionPolicy -MockWith { + return @{ + Ensure = 'Present' + Credential = $Credential + IsSingleInstance = 'Yes'; + Identity = "DefaultReportSubmissionPolicy" + DisableQuarantineReportingOption = $False; + EnableCustomNotificationSender = $False; + EnableOrganizationBranding = $False; + EnableReportToMicrosoft = $False; + EnableThirdPartyAddress = $False; + EnableUserEmailNotification = $False; + PostSubmitMessageEnabled = $False; + PreSubmitMessageEnabled = $False; + ReportJunkToCustomizedAddress = $False; + ReportNotJunkToCustomizedAddress = $False; + ReportPhishToCustomizedAddress = $False; + } + } + + Mock -CommandName Set-ReportSubmissionPolicy -MockWith { + return @{ + + } + } + } + + It 'Should return false from the Test method' { + Test-TargetResource @testParams | Should -Be $false + } + + It 'Should Successfully call the Set method' { + Set-TargetResource @testParams + } + } + + Context -Name 'ReportSubmissionPolicy removal.' -Fixture { + BeforeAll { + $testParams = @{ + Ensure = 'Absent' + Credential = $Credential + Identity = 'DefaultReportSubmissionPolicy' + } + + Mock -CommandName Get-ReportSubmissionPolicy -MockWith { + return @{ + Identity = 'DefaultReportSubmissionPolicy' + } + } + + Mock -CommandName Remove-ReportSubmissionPolicy -MockWith { + return @{ + + } + } + } + + It 'Should return false from the Test method' { + Test-TargetResource @testParams | Should -Be $false + } + + It 'Should Remove the Policy in the Set method' { + Set-TargetResource @testParams + } + } + + Context -Name 'ReverseDSC Tests' -Fixture { + BeforeAll { + $Global:CurrentModeIsExport = $true + $Global:PartialExportFileName = "$(New-Guid).partial.ps1" + $testParams = @{ + Credential = $Credential + } + + Mock -CommandName Get-ReportSubmissionPolicy -MockWith { + return @{ + IsSingleInstance = 'Yes'; + Identity = "DefaultReportSubmissionPolicy" + DisableQuarantineReportingOption = $False; + EnableCustomNotificationSender = $False; + EnableOrganizationBranding = $False; + EnableReportToMicrosoft = $True; + EnableThirdPartyAddress = $False; + EnableUserEmailNotification = $False; + PostSubmitMessageEnabled = $True; + PreSubmitMessageEnabled = $True; + ReportJunkToCustomizedAddress = $False; + ReportNotJunkToCustomizedAddress = $False; + ReportPhishToCustomizedAddress = $False; + } + } + } + + It 'Should Reverse Engineer resource from the Export method' { + $result = Export-TargetResource @testParams + $result | Should -Not -BeNullOrEmpty + } + } + } +} + +Invoke-Command -ScriptBlock $Global:DscHelper.CleanupScript -NoNewScope From b382d73ab264ffdaac117ff8608d6ae422142381 Mon Sep 17 00:00:00 2001 From: mario Date: Tue, 2 Jan 2024 20:05:08 +0100 Subject: [PATCH 02/12] update stubs --- CHANGELOG.md | 3 - Tests/Unit/Stubs/Microsoft365.psm1 | 134 +++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7017ff4bed..dfa162cd1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,18 +18,15 @@ * TeamsChannel * Add error handling if GroupId of a team is null FIXES [#3943](https://github.com/microsoft/Microsoft365DSC/issues/3943) -<<<<<<< HEAD * EXOReportSubmissionPolicy * Initial release FIXES [#3690](https://github.com/microsoft/Microsoft365DSC/issues/3690) -======= * TeamsFeedbackPolicy * Added parameter descriptions for better documentation * TeamsMobilityPolicy * Added parameter descriptions for better documentation * TeamsNetworkRoamingPolicy * Added parameter descriptions for better documentation ->>>>>>> Dev # 1.23.1227.1 diff --git a/Tests/Unit/Stubs/Microsoft365.psm1 b/Tests/Unit/Stubs/Microsoft365.psm1 index a8b6d85644..3484e5c5c5 100644 --- a/Tests/Unit/Stubs/Microsoft365.psm1 +++ b/Tests/Unit/Stubs/Microsoft365.psm1 @@ -1353,6 +1353,15 @@ function Get-RemoteDomain $ResultSize ) } +function Get-ReportSubmissionPolicy +{ + [CmdletBinding()] + param( + [Parameter()] + [System.Object] + $Identity + ) +} function Get-ResourceConfig { [CmdletBinding()] @@ -4331,6 +4340,13 @@ function New-RemoteDomain $DomainName ) } +function New-ReportSubmissionPolicy +{ + [CmdletBinding()] + param( + + ) +} function New-RoleAssignmentPolicy { [CmdletBinding()] @@ -6044,6 +6060,15 @@ function Remove-RemoteDomain $Identity ) } +function Remove-ReportSubmissionPolicy +{ + [CmdletBinding()] + param( + [Parameter()] + [System.Object] + $Identity + ) +} function Remove-RoleAssignmentPolicy { [CmdletBinding()] @@ -11356,6 +11381,115 @@ function Set-RemoteDomain $UseSimpleDisplayName ) } +function Set-ReportSubmissionPolicy +{ + [CmdletBinding()] + param( + [Parameter()] + [System.String] + $Identity, + + [Parameter()] + [System.Boolean] + $DisableQuarantineReportingOption, + + [Parameter()] + [System.Boolean] + $EnableCustomNotificationSender, + + [Parameter()] + [System.Boolean] + $EnableOrganizationBranding, + + [Parameter()] + [System.Boolean] + $EnableReportToMicrosoft, + + [Parameter()] + [System.Boolean] + $EnableThirdPartyAddress, + + [Parameter()] + [System.Boolean] + $EnableUserEmailNotification, + + [Parameter()] + [System.String] + $JunkReviewResultMessage, + + [Parameter()] + [System.String] + $NotJunkReviewResultMessage, + + [Parameter()] + [System.String] + $NotificationFooterMessage, + + [Parameter()] + [System.String] + $NotificationSenderAddress, + + [Parameter()] + [System.String] + $PhishingReviewResultMessage, + + [Parameter()] + [System.String] + $PostSubmitMessage, + + [Parameter()] + [System.Boolean] + $PostSubmitMessageEnabled, + + [Parameter()] + [System.String] + $PostSubmitMessageTitle, + + [Parameter()] + [System.String] + $PreSubmitMessage, + + [Parameter()] + [System.Boolean] + $PreSubmitMessageEnabled, + + [Parameter()] + [System.String] + $PreSubmitMessageTitle, + + [Parameter()] + [System.String[]] + $ReportJunkAddresses = @(), + + [Parameter()] + [System.Boolean] + $ReportJunkToCustomizedAddress, + + [Parameter()] + [System.String[]] + $ReportNotJunkAddresses = @(), + + [Parameter()] + [System.Boolean] + $ReportNotJunkToCustomizedAddress, + + [Parameter()] + [System.String[]] + $ReportPhishAddresses = @(), + + [Parameter()] + [System.Boolean] + $ReportPhishToCustomizedAddress, + + [Parameter()] + [System.String[]] + $ThirdPartyReportAddresses = @(), + + [Parameter()] + [System.Management.Automation.SwitchParameter] + $Confirm + ) +} function Set-ResourceConfig { [CmdletBinding()] From cdd35e6ba622f7ca4d3f7e2ea83f0966b26524a8 Mon Sep 17 00:00:00 2001 From: mario Date: Tue, 2 Jan 2024 20:19:55 +0100 Subject: [PATCH 03/12] fix tests --- .../Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 index 9825f3b746..7d33ff8f48 100644 --- a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 +++ b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 @@ -202,9 +202,10 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { Context -Name 'ReportSubmissionPolicy removal.' -Fixture { BeforeAll { $testParams = @{ - Ensure = 'Absent' - Credential = $Credential - Identity = 'DefaultReportSubmissionPolicy' + Ensure = 'Absent' + Credential = $Credential + Identity = 'DefaultReportSubmissionPolicy' + IsSingleInstance = 'Yes'; } Mock -CommandName Get-ReportSubmissionPolicy -MockWith { @@ -239,7 +240,6 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { Mock -CommandName Get-ReportSubmissionPolicy -MockWith { return @{ - IsSingleInstance = 'Yes'; Identity = "DefaultReportSubmissionPolicy" DisableQuarantineReportingOption = $False; EnableCustomNotificationSender = $False; From edf5a54badfc99c5495f197e924c07c6e3a0d727 Mon Sep 17 00:00:00 2001 From: mario Date: Tue, 2 Jan 2024 20:40:36 +0100 Subject: [PATCH 04/12] fix export --- .../MSFT_EXOReportSubmissionPolicy.psm1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.psm1 index 9f3ade5ba2..288722f959 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.psm1 @@ -688,6 +688,7 @@ function Export-TargetResource CertificatePassword = $CertificatePassword Managedidentity = $ManagedIdentity.IsPresent CertificatePath = $CertificatePath + IsSingleInstance = 'Yes' } $Results = Get-TargetResource @Params From 09d656fe03201c53d4b93d98f72ee88eaed33d1b Mon Sep 17 00:00:00 2001 From: mario Date: Wed, 3 Jan 2024 12:11:33 +0100 Subject: [PATCH 05/12] Adjustments after review --- CHANGELOG.md | 6 +- .../MSFT_EXOReportSubmissionPolicy.psm1 | 101 +++++------- .../MSFT_EXOReportSubmissionPolicy.schema.mof | 1 - .../MSFT_EXOReportSubmissionPolicy/readme.md | 2 +- .../1-ConfigureReportSubmissionPolicy.ps1 | 25 ++- ...365DSC.EXOReportSubmissionPolicy.Tests.ps1 | 153 +++++++++--------- 6 files changed, 133 insertions(+), 155 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfa162cd1e..ea38c030df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ * Added parameter descriptions for better documentation * EXOOutboundConnector * Corrected parameter descriptions, so the documentation on microsoft365dsc.com is generated correctly. +* EXOReportSubmissionPolicy + * Initial release + FIXES [#3690](https://github.com/microsoft/Microsoft365DSC/issues/3690) * EXOTransportRule * Stop supporting DLP-related rules, conditions, and actions (https://techcommunity.microsoft.com/t5/exchange-team-blog/exchange-online-mail-flow-rules-to-stop-supporting-dlp-related/ba-p/3959870) FIXES [#3929](https://github.com/microsoft/Microsoft365DSC/issues/3929) @@ -18,9 +21,6 @@ * TeamsChannel * Add error handling if GroupId of a team is null FIXES [#3943](https://github.com/microsoft/Microsoft365DSC/issues/3943) -* EXOReportSubmissionPolicy - * Initial release - FIXES [#3690](https://github.com/microsoft/Microsoft365DSC/issues/3690) * TeamsFeedbackPolicy * Added parameter descriptions for better documentation * TeamsMobilityPolicy diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.psm1 index 288722f959..b6bdad9273 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.psm1 @@ -9,10 +9,6 @@ function Get-TargetResource [System.String] $IsSingleInstance, - [Parameter(Mandatory = $true)] - [System.String] - $Identity, - [Parameter()] [System.Boolean] $DisableQuarantineReportingOption, @@ -174,19 +170,17 @@ function Get-TargetResource try { - $ReportSubmissionPolicies = Get-ReportSubmissionPolicy -ErrorAction Stop + $ReportSubmissionPolicy = Get-ReportSubmissionPolicy -ErrorAction Stop - $ReportSubmissionPolicy = $ReportSubmissionPolicies | Where-Object -FilterScript { $_.Identity -eq $Identity } if ($null -eq $ReportSubmissionPolicy) { - Write-Verbose -Message "ReportSubmissionPolicy $($Identity) does not exist." + Write-Verbose -Message "ReportSubmissionPolicy does not exist." return $nullReturn } else { $result = @{ IsSingleInstance = 'Yes' - Identity = $Identity DisableQuarantineReportingOption = $ReportSubmissionPolicy.DisableQuarantineReportingOption EnableCustomNotificationSender = $ReportSubmissionPolicy.EnableCustomNotificationSender EnableOrganizationBranding = $ReportSubmissionPolicy.EnableOrganizationBranding @@ -221,7 +215,7 @@ function Get-TargetResource TenantId = $TenantId } - Write-Verbose -Message "Found ReportSubmissionPolicy $($Identity)" + Write-Verbose -Message "Found ReportSubmissionPolicy" Write-Verbose -Message "Get-TargetResource Result: `n $(Convert-M365DscHashtableToString -Hashtable $result)" return $result } @@ -249,10 +243,6 @@ function Set-TargetResource [System.String] $IsSingleInstance, - [Parameter(Mandatory = $true)] - [System.String] - $Identity, - [Parameter()] [System.Boolean] $DisableQuarantineReportingOption, @@ -410,6 +400,7 @@ function Set-TargetResource $ReportSubmissionPolicyParams.Remove('CertificatePath') | Out-Null $ReportSubmissionPolicyParams.Remove('CertificatePassword') | Out-Null $ReportSubmissionPolicyParams.Remove('ManagedIdentity') | Out-Null + $ReportSubmissionPolicyParams.Add('Identity', 'DefaultReportSubmissionPolicy') | Out-Null if ($Ensure -eq 'Present' -and $currentReportSubmissionPolicy.Ensure -eq 'Absent') { @@ -426,7 +417,7 @@ function Set-TargetResource elseif ($Ensure -eq 'Absent' -and $currentReportSubmissionPolicy.Ensure -eq 'Present') { Write-Verbose -Message "Removing ReportSubmissionPolicy $($Identity)" - Remove-ReportSubmissionPolicy -Identity $Identity + Remove-ReportSubmissionPolicy -Identity "DefaultReportSubmissionPolicy" } } @@ -441,10 +432,6 @@ function Test-TargetResource [System.String] $IsSingleInstance, - [Parameter(Mandatory = $true)] - [System.String] - $Identity, - [Parameter()] [System.Boolean] $DisableQuarantineReportingOption, @@ -664,8 +651,8 @@ function Export-TargetResource try { - [array]$ReportSubmissionPolicies = Get-ReportSubmissionPolicy -ErrorAction Stop - if ($ReportSubmissionPolicies.Length -eq 0) + $ReportSubmissionPolicy = Get-ReportSubmissionPolicy -ErrorAction Stop + if ($ReportSubmissionPolicy.Length -eq 0) { Write-Host $Global:M365DSCEmojiGreenCheckMark } @@ -674,50 +661,46 @@ function Export-TargetResource Write-Host "`r`n" -NoNewline } $dscContent = '' - $i = 1 - foreach ($ReportSubmissionPolicy in $ReportSubmissionPolicies) - { - Write-Host " |---[$i/$($ReportSubmissionPolicies.length)] $($ReportSubmissionPolicy.Identity)" -NoNewline - - $Params = @{ - Identity = $ReportSubmissionPolicy.Identity - Credential = $Credential - ApplicationId = $ApplicationId - TenantId = $TenantId - CertificateThumbprint = $CertificateThumbprint - CertificatePassword = $CertificatePassword - Managedidentity = $ManagedIdentity.IsPresent - CertificatePath = $CertificatePath - IsSingleInstance = 'Yes' - } - $Results = Get-TargetResource @Params + Write-Host " |---Export Default ReportSubmissionPolicy" -NoNewline + + $Params = @{ + Credential = $Credential + ApplicationId = $ApplicationId + TenantId = $TenantId + CertificateThumbprint = $CertificateThumbprint + CertificatePassword = $CertificatePassword + Managedidentity = $ManagedIdentity.IsPresent + CertificatePath = $CertificatePath + IsSingleInstance = 'Yes' + } - $keysToRemove = @() - foreach ($key in $Results.Keys) - { - if ([System.String]::IsNullOrEmpty($Results.$key)) - { - $keysToRemove += $key - } - } - foreach ($key in $keysToRemove) + $Results = Get-TargetResource @Params + + $keysToRemove = @() + foreach ($key in $Results.Keys) + { + if ([System.String]::IsNullOrEmpty($Results.$key)) { - $Results.Remove($key) | Out-Null + $keysToRemove += $key } - $Results = Update-M365DSCExportAuthenticationResults -ConnectionMode $ConnectionMode ` - -Results $Results - $currentDSCBlock = Get-M365DSCExportContentForResource -ResourceName $ResourceName ` - -ConnectionMode $ConnectionMode ` - -ModulePath $PSScriptRoot ` - -Results $Results ` - -Credential $Credential - $dscContent += $currentDSCBlock - Save-M365DSCPartialExport -Content $currentDSCBlock ` - -FileName $Global:PartialExportFileName - Write-Host $Global:M365DSCEmojiGreenCheckMark - $i++ } + foreach ($key in $keysToRemove) + { + $Results.Remove($key) | Out-Null + } + $Results = Update-M365DSCExportAuthenticationResults -ConnectionMode $ConnectionMode ` + -Results $Results + $currentDSCBlock = Get-M365DSCExportContentForResource -ResourceName $ResourceName ` + -ConnectionMode $ConnectionMode ` + -ModulePath $PSScriptRoot ` + -Results $Results ` + -Credential $Credential + $dscContent += $currentDSCBlock + Save-M365DSCPartialExport -Content $currentDSCBlock ` + -FileName $Global:PartialExportFileName + Write-Host $Global:M365DSCEmojiGreenCheckMark + return $dscContent } catch diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.schema.mof b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.schema.mof index a315d20b27..81d8e3a7d6 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.schema.mof +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.schema.mof @@ -3,7 +3,6 @@ class MSFT_EXOReportSubmissionPolicy : OMI_BaseResource { [Key, Description("Specifies the resource is a single instance, the value must be 'Yes'."), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance; - [Write, Description("The Identity parameter specifies the report submission policy you want to modify. There can be only one policy.")] String Identity; [Write, Description("The DisableQuarantineReportingOption parameter allows or prevents users from reporting messages in quarantine.")] Boolean DisableQuarantineReportingOption; [Write, Description("The EnableCustomNotificationSender parameter specifies whether a custom sender email address is used for result messages after an admin reviews and marks the reported messages as junk, not junk, or phishing.")] Boolean EnableCustomNotificationSender; [Write, Description("The EnableOrganizationBranding parameter specifies whether to show the company logo in the footer of result messages that users receive after an admin reviews and marks the reported messages as junk, not junk, or phishing.")] Boolean EnableOrganizationBranding; diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/readme.md b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/readme.md index 6c01768780..7541b9ecf4 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/readme.md +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/readme.md @@ -2,4 +2,4 @@ ## Description -Create or modify a EXOReportSubmissionPolicy in your cloud-based organization. +Create or modify an EXOReportSubmissionPolicy in your cloud-based organization. diff --git a/Modules/Microsoft365DSC/Examples/Resources/EXOReportSubmissionPolicy/1-ConfigureReportSubmissionPolicy.ps1 b/Modules/Microsoft365DSC/Examples/Resources/EXOReportSubmissionPolicy/1-ConfigureReportSubmissionPolicy.ps1 index f4ee4bca2e..1698bb7de0 100644 --- a/Modules/Microsoft365DSC/Examples/Resources/EXOReportSubmissionPolicy/1-ConfigureReportSubmissionPolicy.ps1 +++ b/Modules/Microsoft365DSC/Examples/Resources/EXOReportSubmissionPolicy/1-ConfigureReportSubmissionPolicy.ps1 @@ -16,19 +16,18 @@ Configuration Example { EXOReportSubmissionPolicy 'ConfigureReportSubmissionPolicy' { - IsSingleInstance = 'Yes'; - Identity = "DefaultReportSubmissionPolicy" - DisableQuarantineReportingOption = $False; - EnableCustomNotificationSender = $False; - EnableOrganizationBranding = $False; - EnableReportToMicrosoft = $True; - EnableThirdPartyAddress = $False; - EnableUserEmailNotification = $False; - PostSubmitMessageEnabled = $True; - PreSubmitMessageEnabled = $True; - ReportJunkToCustomizedAddress = $False; - ReportNotJunkToCustomizedAddress = $False; - ReportPhishToCustomizedAddress = $False; + IsSingleInstance = 'Yes' + DisableQuarantineReportingOption = $False + EnableCustomNotificationSender = $False + EnableOrganizationBranding = $False + EnableReportToMicrosoft = $True + EnableThirdPartyAddress = $False + EnableUserEmailNotification = $False + PostSubmitMessageEnabled = $True + PreSubmitMessageEnabled = $True + ReportJunkToCustomizedAddress = $False + ReportNotJunkToCustomizedAddress = $False + ReportPhishToCustomizedAddress = $False Ensure = "Present" Credential = $Credscredential } diff --git a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 index 7d33ff8f48..4514c22524 100644 --- a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 +++ b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 @@ -60,19 +60,18 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $testParams = @{ Ensure = 'Present' Credential = $Credential - IsSingleInstance = 'Yes'; - Identity = "DefaultReportSubmissionPolicy" - DisableQuarantineReportingOption = $False; - EnableCustomNotificationSender = $False; - EnableOrganizationBranding = $False; - EnableReportToMicrosoft = $True; - EnableThirdPartyAddress = $False; - EnableUserEmailNotification = $False; - PostSubmitMessageEnabled = $True; - PreSubmitMessageEnabled = $True; - ReportJunkToCustomizedAddress = $False; - ReportNotJunkToCustomizedAddress = $False; - ReportPhishToCustomizedAddress = $False; + IsSingleInstance = 'Yes' + DisableQuarantineReportingOption = $False + EnableCustomNotificationSender = $False + EnableOrganizationBranding = $False + EnableReportToMicrosoft = $True + EnableThirdPartyAddress = $False + EnableUserEmailNotification = $False + PostSubmitMessageEnabled = $True + PreSubmitMessageEnabled = $True + ReportJunkToCustomizedAddress = $False + ReportNotJunkToCustomizedAddress = $False + ReportPhishToCustomizedAddress = $False } @@ -93,6 +92,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { It 'Should call the Set method' { Set-TargetResource @testParams + Should -Invoke -CommandName 'New-ReportSubmissionPolicy' -Exactly 1 } } @@ -102,38 +102,36 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $testParams = @{ Ensure = 'Present' Credential = $Credential - IsSingleInstance = 'Yes'; - Identity = "DefaultReportSubmissionPolicy" - DisableQuarantineReportingOption = $False; - EnableCustomNotificationSender = $False; - EnableOrganizationBranding = $False; - EnableReportToMicrosoft = $True; - EnableThirdPartyAddress = $False; - EnableUserEmailNotification = $False; - PostSubmitMessageEnabled = $True; - PreSubmitMessageEnabled = $True; - ReportJunkToCustomizedAddress = $False; - ReportNotJunkToCustomizedAddress = $False; - ReportPhishToCustomizedAddress = $False; + IsSingleInstance = 'Yes' + DisableQuarantineReportingOption = $False + EnableCustomNotificationSender = $False + EnableOrganizationBranding = $False + EnableReportToMicrosoft = $True + EnableThirdPartyAddress = $False + EnableUserEmailNotification = $False + PostSubmitMessageEnabled = $True + PreSubmitMessageEnabled = $True + ReportJunkToCustomizedAddress = $False + ReportNotJunkToCustomizedAddress = $False + ReportPhishToCustomizedAddress = $False } Mock -CommandName Get-ReportSubmissionPolicy -MockWith { return @{ Ensure = 'Present' Credential = $Credential - IsSingleInstance = 'Yes'; - Identity = "DefaultReportSubmissionPolicy" - DisableQuarantineReportingOption = $False; - EnableCustomNotificationSender = $False; - EnableOrganizationBranding = $False; - EnableReportToMicrosoft = $True; - EnableThirdPartyAddress = $False; - EnableUserEmailNotification = $False; - PostSubmitMessageEnabled = $True; - PreSubmitMessageEnabled = $True; - ReportJunkToCustomizedAddress = $False; - ReportNotJunkToCustomizedAddress = $False; - ReportPhishToCustomizedAddress = $False; + IsSingleInstance = 'Yes' + DisableQuarantineReportingOption = $False + EnableCustomNotificationSender = $False + EnableOrganizationBranding = $False + EnableReportToMicrosoft = $True + EnableThirdPartyAddress = $False + EnableUserEmailNotification = $False + PostSubmitMessageEnabled = $True + PreSubmitMessageEnabled = $True + ReportJunkToCustomizedAddress = $False + ReportNotJunkToCustomizedAddress = $False + ReportPhishToCustomizedAddress = $False } } } @@ -148,38 +146,36 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { $testParams = @{ Ensure = 'Present' Credential = $Credential - IsSingleInstance = 'Yes'; - Identity = "DefaultReportSubmissionPolicy" - DisableQuarantineReportingOption = $False; - EnableCustomNotificationSender = $False; - EnableOrganizationBranding = $False; - EnableReportToMicrosoft = $True; - EnableThirdPartyAddress = $False; - EnableUserEmailNotification = $False; - PostSubmitMessageEnabled = $True; - PreSubmitMessageEnabled = $True; - ReportJunkToCustomizedAddress = $False; - ReportNotJunkToCustomizedAddress = $False; - ReportPhishToCustomizedAddress = $False; + IsSingleInstance = 'Yes' + DisableQuarantineReportingOption = $False + EnableCustomNotificationSender = $False + EnableOrganizationBranding = $False + EnableReportToMicrosoft = $True + EnableThirdPartyAddress = $False + EnableUserEmailNotification = $False + PostSubmitMessageEnabled = $True + PreSubmitMessageEnabled = $True + ReportJunkToCustomizedAddress = $False + ReportNotJunkToCustomizedAddress = $False + ReportPhishToCustomizedAddress = $False } Mock -CommandName Get-ReportSubmissionPolicy -MockWith { return @{ Ensure = 'Present' Credential = $Credential - IsSingleInstance = 'Yes'; - Identity = "DefaultReportSubmissionPolicy" - DisableQuarantineReportingOption = $False; - EnableCustomNotificationSender = $False; - EnableOrganizationBranding = $False; - EnableReportToMicrosoft = $False; - EnableThirdPartyAddress = $False; - EnableUserEmailNotification = $False; - PostSubmitMessageEnabled = $False; - PreSubmitMessageEnabled = $False; - ReportJunkToCustomizedAddress = $False; - ReportNotJunkToCustomizedAddress = $False; - ReportPhishToCustomizedAddress = $False; + IsSingleInstance = 'Yes' + DisableQuarantineReportingOption = $False + EnableCustomNotificationSender = $False + EnableOrganizationBranding = $False + EnableReportToMicrosoft = $False + EnableThirdPartyAddress = $False + EnableUserEmailNotification = $False + PostSubmitMessageEnabled = $False + PreSubmitMessageEnabled = $False + ReportJunkToCustomizedAddress = $False + ReportNotJunkToCustomizedAddress = $False + ReportPhishToCustomizedAddress = $False } } @@ -196,6 +192,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { It 'Should Successfully call the Set method' { Set-TargetResource @testParams + Should -Invoke -CommandName 'Set-ReportSubmissionPolicy' -Exactly 1 } } @@ -205,7 +202,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { Ensure = 'Absent' Credential = $Credential Identity = 'DefaultReportSubmissionPolicy' - IsSingleInstance = 'Yes'; + IsSingleInstance = 'Yes' } Mock -CommandName Get-ReportSubmissionPolicy -MockWith { @@ -227,6 +224,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { It 'Should Remove the Policy in the Set method' { Set-TargetResource @testParams + Should -Invoke -CommandName 'Remove-ReportSubmissionPolicy' -Exactly 1 } } @@ -240,18 +238,17 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { Mock -CommandName Get-ReportSubmissionPolicy -MockWith { return @{ - Identity = "DefaultReportSubmissionPolicy" - DisableQuarantineReportingOption = $False; - EnableCustomNotificationSender = $False; - EnableOrganizationBranding = $False; - EnableReportToMicrosoft = $True; - EnableThirdPartyAddress = $False; - EnableUserEmailNotification = $False; - PostSubmitMessageEnabled = $True; - PreSubmitMessageEnabled = $True; - ReportJunkToCustomizedAddress = $False; - ReportNotJunkToCustomizedAddress = $False; - ReportPhishToCustomizedAddress = $False; + DisableQuarantineReportingOption = $False + EnableCustomNotificationSender = $False + EnableOrganizationBranding = $False + EnableReportToMicrosoft = $True + EnableThirdPartyAddress = $False + EnableUserEmailNotification = $False + PostSubmitMessageEnabled = $True + PreSubmitMessageEnabled = $True + ReportJunkToCustomizedAddress = $False + ReportNotJunkToCustomizedAddress = $False + ReportPhishToCustomizedAddress = $False } } } From 8fa924335f26600ab2f2c1683b51ce8ec31cc3fd Mon Sep 17 00:00:00 2001 From: mario Date: Wed, 3 Jan 2024 12:27:19 +0100 Subject: [PATCH 06/12] fix tests --- ...osoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 index 4514c22524..fbc8b1287f 100644 --- a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 +++ b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 @@ -76,9 +76,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { Mock -CommandName Get-ReportSubmissionPolicy -MockWith { - return @{ - - } + return $null } } @@ -199,15 +197,15 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { Context -Name 'ReportSubmissionPolicy removal.' -Fixture { BeforeAll { $testParams = @{ - Ensure = 'Absent' - Credential = $Credential - Identity = 'DefaultReportSubmissionPolicy' - IsSingleInstance = 'Yes' + Ensure = 'Absent' + Credential = $Credential + IsSingleInstance = 'Yes' + EnableReportToMicrosoft = $True } Mock -CommandName Get-ReportSubmissionPolicy -MockWith { return @{ - Identity = 'DefaultReportSubmissionPolicy' + EnableReportToMicrosoft = $True } } From c3d8497ea1daf23d8a1f67343f45b382b2dcdfa3 Mon Sep 17 00:00:00 2001 From: mario Date: Wed, 3 Jan 2024 13:12:25 +0100 Subject: [PATCH 07/12] add resource for EXOReportSubmissionRule --- CHANGELOG.md | 3 + .../MSFT_EXOReportSubmissionPolicy.psm1 | 12 +- .../MSFT_EXOReportSubmissionRule.psm1 | 450 ++++++++++++++++++ .../MSFT_EXOReportSubmissionRule.schema.mof | 17 + .../MSFT_EXOReportSubmissionRule/readme.md | 5 + .../settings.json | 33 ++ .../1-ConfigureReportSubmissionRule.ps1 | 27 ++ ...ft365DSC.EXOReportSubmissionRule.Tests.ps1 | 216 +++++++++ Tests/Unit/Stubs/Microsoft365.psm1 | 42 ++ 9 files changed, 799 insertions(+), 6 deletions(-) create mode 100644 Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/MSFT_EXOReportSubmissionRule.psm1 create mode 100644 Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/MSFT_EXOReportSubmissionRule.schema.mof create mode 100644 Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/readme.md create mode 100644 Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/settings.json create mode 100644 Modules/Microsoft365DSC/Examples/Resources/EXOReportSubmissionRule/1-ConfigureReportSubmissionRule.ps1 create mode 100644 Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index ea38c030df..0d3251262a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ * EXOReportSubmissionPolicy * Initial release FIXES [#3690](https://github.com/microsoft/Microsoft365DSC/issues/3690) +* EXOReportSubmissionRule + * Initial release + FIXES [#3690](https://github.com/microsoft/Microsoft365DSC/issues/3690) * EXOTransportRule * Stop supporting DLP-related rules, conditions, and actions (https://techcommunity.microsoft.com/t5/exchange-team-blog/exchange-online-mail-flow-rules-to-stop-supporting-dlp-related/ba-p/3959870) FIXES [#3929](https://github.com/microsoft/Microsoft365DSC/issues/3929) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.psm1 index b6bdad9273..32003b72a4 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.psm1 @@ -139,7 +139,7 @@ function Get-TargetResource $ManagedIdentity ) - Write-Verbose -Message "Getting configuration of ReportSubmissionPolicy for $($Identity)" + Write-Verbose -Message "Getting configuration of ReportSubmissionPolicy" if ($Global:CurrentModeIsExport) { $ConnectionMode = New-M365DSCConnection -Workload 'ExchangeOnline' ` @@ -383,7 +383,7 @@ function Set-TargetResource -Parameters $PSBoundParameters Add-M365DSCTelemetryEvent -Data $data #endregion - Write-Verbose -Message "Setting configuration of ReportSubmissionPolicy for $($Identity)" + Write-Verbose -Message "Setting configuration of ReportSubmissionPolicy" $ConnectionMode = New-M365DSCConnection -Workload 'ExchangeOnline' ` -InboundParameters $PSBoundParameters @@ -404,19 +404,19 @@ function Set-TargetResource if ($Ensure -eq 'Present' -and $currentReportSubmissionPolicy.Ensure -eq 'Absent') { - Write-Verbose -Message "Creating ReportSubmissionPolicy $($Identity)." + Write-Verbose -Message "Creating ReportSubmissionPolicy" New-ReportSubmissionPolicy Set-ReportSubmissionPolicy @ReportSubmissionPolicyParams -Confirm:$false } elseif ($Ensure -eq 'Present' -and $currentReportSubmissionPolicy.Ensure -eq 'Present') { - Write-Verbose -Message "Setting ReportSubmissionPolicy $($Identity) with values: $(Convert-M365DscHashtableToString -Hashtable $ReportSubmissionPolicyParams)" + Write-Verbose -Message "Setting ReportSubmissionPolicy with values: $(Convert-M365DscHashtableToString -Hashtable $ReportSubmissionPolicyParams)" Set-ReportSubmissionPolicy @ReportSubmissionPolicyParams -Confirm:$false } elseif ($Ensure -eq 'Absent' -and $currentReportSubmissionPolicy.Ensure -eq 'Present') { - Write-Verbose -Message "Removing ReportSubmissionPolicy $($Identity)" + Write-Verbose -Message "Removing ReportSubmissionPolicy" Remove-ReportSubmissionPolicy -Identity "DefaultReportSubmissionPolicy" } } @@ -573,7 +573,7 @@ function Test-TargetResource Add-M365DSCTelemetryEvent -Data $data #endregion - Write-Verbose -Message "Testing configuration of ReportSubmissionPolicy for $($Identity)" + Write-Verbose -Message "Testing configuration of ReportSubmissionPolicy" $CurrentValues = Get-TargetResource @PSBoundParameters diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/MSFT_EXOReportSubmissionRule.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/MSFT_EXOReportSubmissionRule.psm1 new file mode 100644 index 0000000000..6bf4f22c9e --- /dev/null +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/MSFT_EXOReportSubmissionRule.psm1 @@ -0,0 +1,450 @@ +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [ValidateSet('Yes')] + [System.String] + $IsSingleInstance, + + [Parameter(Mandatory = $true)] + [System.String] + $Identity, + + [Parameter()] + [System.String] + $Comments, + + [Parameter()] + [System.String] + $SentTo, + + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.Management.Automation.PSCredential] + $Credential, + + [Parameter()] + [System.String] + $ApplicationId, + + [Parameter()] + [System.String] + $TenantId, + + [Parameter()] + [System.String] + $CertificateThumbprint, + + [Parameter()] + [System.String] + $CertificatePath, + + [Parameter()] + [System.Management.Automation.PSCredential] + $CertificatePassword, + + [Parameter()] + [Switch] + $ManagedIdentity + ) + + Write-Verbose -Message "Getting configuration of ReportSubmissionRule" + if ($Global:CurrentModeIsExport) + { + $ConnectionMode = New-M365DSCConnection -Workload 'ExchangeOnline' ` + -InboundParameters $PSBoundParameters ` + -SkipModuleReload $true + } + else + { + $ConnectionMode = New-M365DSCConnection -Workload 'ExchangeOnline' ` + -InboundParameters $PSBoundParameters + } + + #Ensure the proper dependencies are installed in the current environment. + Confirm-M365DSCDependencies + + #region Telemetry + $ResourceName = $MyInvocation.MyCommand.ModuleName -replace 'MSFT_', '' + $CommandName = $MyInvocation.MyCommand + $data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName ` + -CommandName $CommandName ` + -Parameters $PSBoundParameters + Add-M365DSCTelemetryEvent -Data $data + #endregion + + $nullReturn = $PSBoundParameters + $nullReturn.Ensure = 'Absent' + $nullReturn.IsSingleInstance = 'Yes' + + try + { + $ReportSubmissionRule = Get-ReportSubmissionRule -ErrorAction Stop + + if ($null -eq $ReportSubmissionRule) + { + Write-Verbose -Message "ReportSubmissionRule does not exist." + return $nullReturn + } + else + { + $result = @{ + IsSingleInstance = 'Yes' + Identity = $ReportSubmissionRule.Identity + Comments = $ReportSubmissionRule.Comments + SentTo = $ReportSubmissionRule.SentTo + Credential = $Credential + Ensure = 'Present' + ApplicationId = $ApplicationId + CertificateThumbprint = $CertificateThumbprint + CertificatePath = $CertificatePath + CertificatePassword = $CertificatePassword + Managedidentity = $ManagedIdentity.IsPresent + TenantId = $TenantId + } + + Write-Verbose -Message "Found ReportSubmissionRule" + Write-Verbose -Message "Get-TargetResource Result: `n $(Convert-M365DscHashtableToString -Hashtable $result)" + return $result + } + } + catch + { + New-M365DSCLogEntry -Message 'Error retrieving data:' ` + -Exception $_ ` + -Source $($MyInvocation.MyCommand.Source) ` + -TenantId $TenantId ` + -Credential $Credential + + return $nullReturn + } +} + +function Set-TargetResource +{ + [CmdletBinding()] + + param + ( + [Parameter(Mandatory = $true)] + [ValidateSet('Yes')] + [System.String] + $IsSingleInstance, + + [Parameter(Mandatory = $true)] + [System.String] + $Identity, + + [Parameter()] + [System.String] + $Comments, + + [Parameter()] + [System.String] + $SentTo, + + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.Management.Automation.PSCredential] + $Credential, + + [Parameter()] + [System.String] + $ApplicationId, + + [Parameter()] + [System.String] + $TenantId, + + [Parameter()] + [System.String] + $CertificateThumbprint, + + [Parameter()] + [System.String] + $CertificatePath, + + [Parameter()] + [System.Management.Automation.PSCredential] + $CertificatePassword, + + [Parameter()] + [Switch] + $ManagedIdentity + ) + #Ensure the proper dependencies are installed in the current environment. + Confirm-M365DSCDependencies + + #region Telemetry + $ResourceName = $MyInvocation.MyCommand.ModuleName -replace 'MSFT_', '' + $CommandName = $MyInvocation.MyCommand + $data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName ` + -CommandName $CommandName ` + -Parameters $PSBoundParameters + Add-M365DSCTelemetryEvent -Data $data + #endregion + Write-Verbose -Message "Setting configuration of ReportSubmissionRule" + + $ConnectionMode = New-M365DSCConnection -Workload 'ExchangeOnline' ` + -InboundParameters $PSBoundParameters + + $currentReportSubmissionRule = Get-TargetResource @PSBoundParameters + + $ReportSubmissionRuleParams = [System.Collections.Hashtable]($PSBoundParameters) + $ReportSubmissionRuleParams.Remove('Ensure') | Out-Null + $ReportSubmissionRuleParams.Remove('IsSingleInstance') | Out-Null + $ReportSubmissionRuleParams.Remove('Credential') | Out-Null + $ReportSubmissionRuleParams.Remove('ApplicationId') | Out-Null + $ReportSubmissionRuleParams.Remove('TenantId') | Out-Null + $ReportSubmissionRuleParams.Remove('CertificateThumbprint') | Out-Null + $ReportSubmissionRuleParams.Remove('CertificatePath') | Out-Null + $ReportSubmissionRuleParams.Remove('CertificatePassword') | Out-Null + $ReportSubmissionRuleParams.Remove('ManagedIdentity') | Out-Null + # There is only one ReportSubmissionPolicy, so we can hardcode the identity. + $ReportSubmissionRuleParams.Add('ReportSubmissionPolicy', 'DefaultReportSubmissionPolicy') | Out-Null + + if ($Ensure -eq 'Present' -and $currentReportSubmissionRule.Ensure -eq 'Absent') + { + Write-Verbose -Message "Creating ReportSubmissionRule" + + $ReportSubmissionRuleParams.Add('Name', $Identity) | Out-Null + $ReportSubmissionRuleParams.Remove('Identity') | Out-Null + + New-ReportSubmissionRule @ReportSubmissionRuleParams + } + elseif ($Ensure -eq 'Present' -and $currentReportSubmissionRule.Ensure -eq 'Present') + { + Write-Verbose -Message "Setting ReportSubmissionRule with values: $(Convert-M365DscHashtableToString -Hashtable $ReportSubmissionRuleParams)" + Set-ReportSubmissionRule @ReportSubmissionRuleParams -Confirm:$false + } + elseif ($Ensure -eq 'Absent' -and $currentReportSubmissionRule.Ensure -eq 'Present') + { + Write-Verbose -Message "Removing ReportSubmissionRule" + Remove-ReportSubmissionRule -Identity $Identity -Confirm:$false + } +} + +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [ValidateSet('Yes')] + [System.String] + $IsSingleInstance, + + [Parameter(Mandatory = $true)] + [System.String] + $Identity, + + [Parameter()] + [System.String] + $Comments, + + [Parameter()] + [System.String] + $SentTo, + + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.Management.Automation.PSCredential] + $Credential, + + [Parameter()] + [System.String] + $ApplicationId, + + [Parameter()] + [System.String] + $TenantId, + + [Parameter()] + [System.String] + $CertificateThumbprint, + + [Parameter()] + [System.String] + $CertificatePath, + + [Parameter()] + [System.Management.Automation.PSCredential] + $CertificatePassword, + + [Parameter()] + [Switch] + $ManagedIdentity + ) + #Ensure the proper dependencies are installed in the current environment. + Confirm-M365DSCDependencies + + #region Telemetry + $ResourceName = $MyInvocation.MyCommand.ModuleName -replace 'MSFT_', '' + $CommandName = $MyInvocation.MyCommand + $data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName ` + -CommandName $CommandName ` + -Parameters $PSBoundParameters + Add-M365DSCTelemetryEvent -Data $data + #endregion + + Write-Verbose -Message "Testing configuration of ReportSubmissionRule" + + $CurrentValues = Get-TargetResource @PSBoundParameters + + Write-Verbose -Message "Current Values: $(Convert-M365DscHashtableToString -Hashtable $CurrentValues)" + Write-Verbose -Message "Target Values: $(Convert-M365DscHashtableToString -Hashtable $PSBoundParameters)" + + $ValuesToCheck = $PSBoundParameters + $ValuesToCheck.Remove('Credential') | Out-Null + $ValuesToCheck.Remove('ApplicationId') | Out-Null + $ValuesToCheck.Remove('TenantId') | Out-Null + $ValuesToCheck.Remove('CertificateThumbprint') | Out-Null + $ValuesToCheck.Remove('CertificatePath') | Out-Null + $ValuesToCheck.Remove('CertificatePassword') | Out-Null + $ValuesToCheck.Remove('ManagedIdentity') | Out-Null + + $TestResult = Test-M365DSCParameterState -CurrentValues $CurrentValues ` + -Source $($MyInvocation.MyCommand.Source) ` + -DesiredValues $PSBoundParameters ` + -ValuesToCheck $ValuesToCheck.Keys + + Write-Verbose -Message "Test-TargetResource returned $($TestResult)" + + return $TestResult +} + +function Export-TargetResource +{ + [CmdletBinding()] + [OutputType([System.String])] + param + ( + [Parameter()] + [System.Management.Automation.PSCredential] + $Credential, + + [Parameter()] + [System.String] + $ApplicationId, + + [Parameter()] + [System.String] + $TenantId, + + [Parameter()] + [System.String] + $CertificateThumbprint, + + [Parameter()] + [System.String] + $CertificatePath, + + [Parameter()] + [System.Management.Automation.PSCredential] + $CertificatePassword, + + [Parameter()] + [Switch] + $ManagedIdentity + ) + $ConnectionMode = New-M365DSCConnection -Workload 'ExchangeOnline' ` + -InboundParameters $PSBoundParameters ` + -SkipModuleReload $true + + #Ensure the proper dependencies are installed in the current environment. + Confirm-M365DSCDependencies + + #region Telemetry + $ResourceName = $MyInvocation.MyCommand.ModuleName -replace 'MSFT_', '' + $CommandName = $MyInvocation.MyCommand + $data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName ` + -CommandName $CommandName ` + -Parameters $PSBoundParameters + Add-M365DSCTelemetryEvent -Data $data + #endregion + + try + { + $ReportSubmissionRule = Get-ReportSubmissionRule -ErrorAction Stop + if ($ReportSubmissionRule.Length -eq 0) + { + Write-Host $Global:M365DSCEmojiGreenCheckMark + } + else + { + Write-Host "`r`n" -NoNewline + } + $dscContent = '' + + Write-Host " |---Export ReportSubmissionRule" -NoNewline + + $Params = @{ + Identity = $ReportSubmissionRule.Identity + Credential = $Credential + ApplicationId = $ApplicationId + TenantId = $TenantId + CertificateThumbprint = $CertificateThumbprint + CertificatePassword = $CertificatePassword + Managedidentity = $ManagedIdentity.IsPresent + CertificatePath = $CertificatePath + IsSingleInstance = 'Yes' + } + + $Results = Get-TargetResource @Params + + $keysToRemove = @() + foreach ($key in $Results.Keys) + { + if ([System.String]::IsNullOrEmpty($Results.$key)) + { + $keysToRemove += $key + } + } + foreach ($key in $keysToRemove) + { + $Results.Remove($key) | Out-Null + } + $Results = Update-M365DSCExportAuthenticationResults -ConnectionMode $ConnectionMode ` + -Results $Results + $currentDSCBlock = Get-M365DSCExportContentForResource -ResourceName $ResourceName ` + -ConnectionMode $ConnectionMode ` + -ModulePath $PSScriptRoot ` + -Results $Results ` + -Credential $Credential + $dscContent += $currentDSCBlock + Save-M365DSCPartialExport -Content $currentDSCBlock ` + -FileName $Global:PartialExportFileName + Write-Host $Global:M365DSCEmojiGreenCheckMark + + return $dscContent + } + catch + { + Write-Host $Global:M365DSCEmojiRedX + + New-M365DSCLogEntry -Message 'Error during Export:' ` + -Exception $_ ` + -Source $($MyInvocation.MyCommand.Source) ` + -TenantId $TenantId ` + -Credential $Credential + + return '' + } +} +Export-ModuleMember -Function *-TargetResource diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/MSFT_EXOReportSubmissionRule.schema.mof b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/MSFT_EXOReportSubmissionRule.schema.mof new file mode 100644 index 0000000000..2e67040a27 --- /dev/null +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/MSFT_EXOReportSubmissionRule.schema.mof @@ -0,0 +1,17 @@ + +[ClassVersion("1.0.0.0"), FriendlyName("EXOReportSubmissionRule")] +class MSFT_EXOReportSubmissionRule : OMI_BaseResource +{ + [Key, Description("Specifies the resource is a single instance, the value must be 'Yes'."), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance; + [Write, Description("The Identity parameter specifies the report submission rule that you want to modify.")] String Identity; + [Write, Description("The Comments parameter specifies informative comments for the rule, such as what the rule is used for or how it has changed over time.")] String Comments; + [Write, Description("The SentTo parameter specifies the email address of the reporting mailbox in Exchange Online where user reported messages are sent.")] String SentTo; + [Write, Description("Specifies if this report submission rule should exist."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; + [Write, Description("Credentials of the Exchange Global Admin"), EmbeddedInstance("MSFT_Credential")] string Credential; + [Write, Description("Id of the Azure Active Directory application to authenticate with.")] String ApplicationId; + [Write, Description("Id of the Azure Active Directory tenant used for authentication.")] String TenantId; + [Write, Description("Thumbprint of the Azure Active Directory application's authentication certificate to use for authentication.")] String CertificateThumbprint; + [Write, Description("Username can be made up to anything but password will be used for CertificatePassword"), EmbeddedInstance("MSFT_Credential")] String CertificatePassword; + [Write, Description("Path to certificate used in service principal usually a PFX file.")] String CertificatePath; + [Write, Description("Managed ID being used for authentication.")] Boolean ManagedIdentity; +}; diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/readme.md b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/readme.md new file mode 100644 index 0000000000..c0186b1109 --- /dev/null +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/readme.md @@ -0,0 +1,5 @@ +# EXOReportSubmissionRule + +## Description + +Create or modify an EXOReportSubmissionRule in your cloud-based organization. diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/settings.json b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/settings.json new file mode 100644 index 0000000000..7991aee13b --- /dev/null +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/settings.json @@ -0,0 +1,33 @@ +{ + "resourceName": "EXOReportSubmissionRule", + "description": "", + "roles": { + "read": [ + "Security Reader" + ], + "update": [ + "Security Administrator" + ] + }, + "permissions": { + "graph": { + "delegated": { + "read": [], + "update": [] + }, + "application": { + "read": [], + "update": [] + } + }, + "exchange": { + "requiredroles": [ + "Transport Hygiene", + "Security Admin", + "View-Only Configuration", + "Security Reader" + ], + "requiredrolegroups": "Organization Management" + } + } +} diff --git a/Modules/Microsoft365DSC/Examples/Resources/EXOReportSubmissionRule/1-ConfigureReportSubmissionRule.ps1 b/Modules/Microsoft365DSC/Examples/Resources/EXOReportSubmissionRule/1-ConfigureReportSubmissionRule.ps1 new file mode 100644 index 0000000000..e1af0e2270 --- /dev/null +++ b/Modules/Microsoft365DSC/Examples/Resources/EXOReportSubmissionRule/1-ConfigureReportSubmissionRule.ps1 @@ -0,0 +1,27 @@ +<# +This example is used to test new resources and showcase the usage of new resources being worked on. +It is not meant to use as a production baseline. +#> + +Configuration Example +{ + param( + [Parameter(Mandatory = $true)] + [PSCredential] + $Credscredential + ) + Import-DscResource -ModuleName Microsoft365DSC + + node localhost + { + EXOReportSubmissionRule 'ConfigureReportSubmissionRule' + { + IsSingleInstance = 'Yes' + Identity = "DefaultReportSubmissionRule" + Comments = "This is my default rule" + SentTo = "submission@contoso.com" + Ensure = "Present" + Credential = $Credscredential + } + } +} diff --git a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 new file mode 100644 index 0000000000..0638ebd69b --- /dev/null +++ b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 @@ -0,0 +1,216 @@ +[CmdletBinding()] +param( +) +$M365DSCTestFolder = Join-Path -Path $PSScriptRoot ` + -ChildPath '..\..\Unit' ` + -Resolve +$CmdletModule = (Join-Path -Path $M365DSCTestFolder ` + -ChildPath '\Stubs\Microsoft365.psm1' ` + -Resolve) +$GenericStubPath = (Join-Path -Path $M365DSCTestFolder ` + -ChildPath '\Stubs\Generic.psm1' ` + -Resolve) +Import-Module -Name (Join-Path -Path $M365DSCTestFolder ` + -ChildPath '\UnitTestHelper.psm1' ` + -Resolve) + +$Global:DscHelper = New-M365DscUnitTestHelper -StubModule $CmdletModule ` + -DscResource 'EXOReportSubmissionRule' -GenericStubModule $GenericStubPath +Describe -Name $Global:DscHelper.DescribeHeader -Fixture { + InModuleScope -ModuleName $Global:DscHelper.ModuleName -ScriptBlock { + Invoke-Command -ScriptBlock $Global:DscHelper.InitializeScript -NoNewScope + + BeforeAll { + $secpasswd = ConvertTo-SecureString 'test@password1' -AsPlainText -Force + $Credential = New-Object System.Management.Automation.PSCredential ('tenantadmin@mydomain.com', $secpasswd) + + Mock -CommandName Confirm-M365DSCDependencies -MockWith { + } + + Mock -CommandName New-M365DSCConnection -MockWith { + return 'Credentials' + } + + Mock -CommandName Get-PSSession -MockWith { + } + + Mock -CommandName Remove-PSSession -MockWith { + } + + Mock -CommandName New-ReportSubmissionRule -MockWith { + } + + Mock -CommandName Set-ReportSubmissionRule -MockWith { + } + + Mock -CommandName Remove-ReportSubmissionRule -MockWith { + } + + # Mock Write-Host to hide output during the tests + Mock -CommandName Write-Host -MockWith { + } + + Mock -CommandName Write-Warning -MockWith { + } + } + + # Test contexts + Context -Name 'ReportSubmissionRule creation.' -Fixture { + BeforeAll { + $testParams = @{ + Ensure = 'Present' + Credential = $Credential + IsSingleInstance = 'Yes' + Identity = "DefaultReportSubmissionRule" + Comments = "This is my default rule" + SentTo = "submission@contoso.com" + } + + + Mock -CommandName Get-ReportSubmissionRule -MockWith { + return $null + } + } + + It 'Should return Absent from the Get method' { + (Get-TargetResource @testParams).Ensure | Should -Be 'Absent' + } + + It 'Should return false from the Test method' { + Test-TargetResource @testParams | Should -Be $false + } + + It 'Should call the Set method' { + Set-TargetResource @testParams + Should -Invoke -CommandName 'New-ReportSubmissionRule' -Exactly 1 + } + + } + + Context -Name 'ReportSubmissionRule update not required.' -Fixture { + BeforeAll { + $testParams = @{ + Ensure = 'Present' + Credential = $Credential + IsSingleInstance = 'Yes' + Identity = "DefaultReportSubmissionRule" + Comments = "This is my default rule" + SentTo = "submission@contoso.com" + } + + Mock -CommandName Get-ReportSubmissionRule -MockWith { + return @{ + Ensure = 'Present' + Credential = $Credential + IsSingleInstance = 'Yes' + Identity = "DefaultReportSubmissionRule" + Comments = "This is my default rule" + SentTo = "submission@contoso.com" + } + } + } + + It 'Should return true from the Test method' { + Test-TargetResource @testParams | Should -Be $true + } + } + + Context -Name 'ReportSubmissionRule update needed.' -Fixture { + BeforeAll { + $testParams = @{ + Ensure = 'Present' + Credential = $Credential + IsSingleInstance = 'Yes' + Identity = "DefaultReportSubmissionRule" + Comments = "This is my default rule" + SentTo = "submission@contoso.com" + } + + Mock -CommandName Get-ReportSubmissionRule -MockWith { + return @{ + Ensure = 'Present' + Credential = $Credential + IsSingleInstance = 'Yes' + Identity = "DefaultReportSubmissionRule" + Comments = "This is my default rule" + SentTo = "different@contoso.com" + } + } + + Mock -CommandName Set-ReportSubmissionRule -MockWith { + return @{ + + } + } + } + + It 'Should return false from the Test method' { + Test-TargetResource @testParams | Should -Be $false + } + + It 'Should Successfully call the Set method' { + Set-TargetResource @testParams + Should -Invoke -CommandName 'Set-ReportSubmissionRule' -Exactly 1 + } + } + + Context -Name 'ReportSubmissionRule removal.' -Fixture { + BeforeAll { + $testParams = @{ + Ensure = 'Absent' + Credential = $Credential + IsSingleInstance = 'Yes' + Identity = "DefaultReportSubmissionRule" + Comments = "This is my default rule" + SentTo = "submission@contoso.com" + } + + Mock -CommandName Get-ReportSubmissionRule -MockWith { + return @{ + Identity = "DefaultReportSubmissionRule" + } + } + + Mock -CommandName Remove-ReportSubmissionRule -MockWith { + return @{ + + } + } + } + + It 'Should return false from the Test method' { + Test-TargetResource @testParams | Should -Be $false + } + + It 'Should Remove the Policy in the Set method' { + Set-TargetResource @testParams + Should -Invoke -CommandName 'Remove-ReportSubmissionRule' -Exactly 1 + } + } + + Context -Name 'ReverseDSC Tests' -Fixture { + BeforeAll { + $Global:CurrentModeIsExport = $true + $Global:PartialExportFileName = "$(New-Guid).partial.ps1" + $testParams = @{ + Credential = $Credential + } + + Mock -CommandName Get-ReportSubmissionRule -MockWith { + return @{ + Identity = "DefaultReportSubmissionRule" + Comments = "This is my default rule" + SentTo = "submission@contoso.com" + } + } + } + + It 'Should Reverse Engineer resource from the Export method' { + $result = Export-TargetResource @testParams + $result | Should -Not -BeNullOrEmpty + } + } + } +} + +Invoke-Command -ScriptBlock $Global:DscHelper.CleanupScript -NoNewScope diff --git a/Tests/Unit/Stubs/Microsoft365.psm1 b/Tests/Unit/Stubs/Microsoft365.psm1 index 3484e5c5c5..39b7f0642c 100644 --- a/Tests/Unit/Stubs/Microsoft365.psm1 +++ b/Tests/Unit/Stubs/Microsoft365.psm1 @@ -1362,6 +1362,15 @@ function Get-ReportSubmissionPolicy $Identity ) } +function Get-ReportSubmissionRule +{ + [CmdletBinding()] + param( + [Parameter()] + [System.Object] + $Identity + ) +} function Get-ResourceConfig { [CmdletBinding()] @@ -4347,6 +4356,13 @@ function New-ReportSubmissionPolicy ) } +function New-ReportSubmissionRule +{ + [CmdletBinding()] + param( + + ) +} function New-RoleAssignmentPolicy { [CmdletBinding()] @@ -6069,6 +6085,15 @@ function Remove-ReportSubmissionPolicy $Identity ) } +function Remove-ReportSubmissionRule +{ + [CmdletBinding()] + param( + [Parameter()] + [System.Object] + $Identity + ) +} function Remove-RoleAssignmentPolicy { [CmdletBinding()] @@ -11490,6 +11515,23 @@ function Set-ReportSubmissionPolicy $Confirm ) } +function Set-ReportSubmissionRule +{ + [CmdletBinding()] + param( + [Parameter()] + [System.String] + $Identity, + + [Parameter()] + [System.String] + $Comments, + + [Parameter()] + [System.String] + $SentTo + ) +} function Set-ResourceConfig { [CmdletBinding()] From 36dc000f55ed9cdbc2d6bb31c1113fefe0c75020 Mon Sep 17 00:00:00 2001 From: mario Date: Wed, 3 Jan 2024 13:28:52 +0100 Subject: [PATCH 08/12] fix fixes --- .../MSFT_EXOReportSubmissionRule.psm1 | 16 ++++++++-------- .../MSFT_EXOReportSubmissionRule.schema.mof | 2 +- Tests/Unit/Stubs/Microsoft365.psm1 | 12 ++++++++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/MSFT_EXOReportSubmissionRule.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/MSFT_EXOReportSubmissionRule.psm1 index 6bf4f22c9e..775c1e0fc5 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/MSFT_EXOReportSubmissionRule.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/MSFT_EXOReportSubmissionRule.psm1 @@ -18,8 +18,8 @@ function Get-TargetResource $Comments, [Parameter()] - [System.String] - $SentTo, + [System.String[]] + $SentTo = @(), [Parameter()] [ValidateSet('Present', 'Absent')] @@ -147,8 +147,8 @@ function Set-TargetResource $Comments, [Parameter()] - [System.String] - $SentTo, + [System.String[]] + $SentTo = @(), [Parameter()] [ValidateSet('Present', 'Absent')] @@ -211,8 +211,6 @@ function Set-TargetResource $ReportSubmissionRuleParams.Remove('CertificatePath') | Out-Null $ReportSubmissionRuleParams.Remove('CertificatePassword') | Out-Null $ReportSubmissionRuleParams.Remove('ManagedIdentity') | Out-Null - # There is only one ReportSubmissionPolicy, so we can hardcode the identity. - $ReportSubmissionRuleParams.Add('ReportSubmissionPolicy', 'DefaultReportSubmissionPolicy') | Out-Null if ($Ensure -eq 'Present' -and $currentReportSubmissionRule.Ensure -eq 'Absent') { @@ -220,6 +218,8 @@ function Set-TargetResource $ReportSubmissionRuleParams.Add('Name', $Identity) | Out-Null $ReportSubmissionRuleParams.Remove('Identity') | Out-Null + # There is only one ReportSubmissionPolicy, so we can hardcode the identity. + $ReportSubmissionRuleParams.Add('ReportSubmissionPolicy', 'DefaultReportSubmissionPolicy') | Out-Null New-ReportSubmissionRule @ReportSubmissionRuleParams } @@ -255,8 +255,8 @@ function Test-TargetResource $Comments, [Parameter()] - [System.String] - $SentTo, + [System.String[]] + $SentTo = @(), [Parameter()] [ValidateSet('Present', 'Absent')] diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/MSFT_EXOReportSubmissionRule.schema.mof b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/MSFT_EXOReportSubmissionRule.schema.mof index 2e67040a27..f5f8d47198 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/MSFT_EXOReportSubmissionRule.schema.mof +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionRule/MSFT_EXOReportSubmissionRule.schema.mof @@ -5,7 +5,7 @@ class MSFT_EXOReportSubmissionRule : OMI_BaseResource [Key, Description("Specifies the resource is a single instance, the value must be 'Yes'."), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance; [Write, Description("The Identity parameter specifies the report submission rule that you want to modify.")] String Identity; [Write, Description("The Comments parameter specifies informative comments for the rule, such as what the rule is used for or how it has changed over time.")] String Comments; - [Write, Description("The SentTo parameter specifies the email address of the reporting mailbox in Exchange Online where user reported messages are sent.")] String SentTo; + [Write, Description("The SentTo parameter specifies the email address of the reporting mailbox in Exchange Online where user reported messages are sent.")] String SentTo[]; [Write, Description("Specifies if this report submission rule should exist."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Write, Description("Credentials of the Exchange Global Admin"), EmbeddedInstance("MSFT_Credential")] string Credential; [Write, Description("Id of the Azure Active Directory application to authenticate with.")] String ApplicationId; diff --git a/Tests/Unit/Stubs/Microsoft365.psm1 b/Tests/Unit/Stubs/Microsoft365.psm1 index 39b7f0642c..5e66f3f48c 100644 --- a/Tests/Unit/Stubs/Microsoft365.psm1 +++ b/Tests/Unit/Stubs/Microsoft365.psm1 @@ -6091,7 +6091,11 @@ function Remove-ReportSubmissionRule param( [Parameter()] [System.Object] - $Identity + $Identity, + + [Parameter()] + [System.Management.Automation.SwitchParameter] + $Confirm ) } function Remove-RoleAssignmentPolicy @@ -11529,7 +11533,11 @@ function Set-ReportSubmissionRule [Parameter()] [System.String] - $SentTo + $SentTo, + + [Parameter()] + [System.Management.Automation.SwitchParameter] + $Confirm ) } function Set-ResourceConfig From 227afce61fb0ad1bd68958cd53a4acea1589164e Mon Sep 17 00:00:00 2001 From: mario Date: Wed, 3 Jan 2024 13:46:21 +0100 Subject: [PATCH 09/12] fix tests again --- ...osoft365DSC.EXOReportSubmissionRule.Tests.ps1 | 14 +++++++------- Tests/Unit/Stubs/Microsoft365.psm1 | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 index 0638ebd69b..6dac6f96ce 100644 --- a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 +++ b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 @@ -63,7 +63,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { IsSingleInstance = 'Yes' Identity = "DefaultReportSubmissionRule" Comments = "This is my default rule" - SentTo = "submission@contoso.com" + SentTo = @("submission@contoso.com") } @@ -95,7 +95,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { IsSingleInstance = 'Yes' Identity = "DefaultReportSubmissionRule" Comments = "This is my default rule" - SentTo = "submission@contoso.com" + SentTo = @("submission@contoso.com") } Mock -CommandName Get-ReportSubmissionRule -MockWith { @@ -105,7 +105,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { IsSingleInstance = 'Yes' Identity = "DefaultReportSubmissionRule" Comments = "This is my default rule" - SentTo = "submission@contoso.com" + SentTo = @("submission@contoso.com") } } } @@ -123,7 +123,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { IsSingleInstance = 'Yes' Identity = "DefaultReportSubmissionRule" Comments = "This is my default rule" - SentTo = "submission@contoso.com" + SentTo = @("submission@contoso.com") } Mock -CommandName Get-ReportSubmissionRule -MockWith { @@ -133,7 +133,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { IsSingleInstance = 'Yes' Identity = "DefaultReportSubmissionRule" Comments = "This is my default rule" - SentTo = "different@contoso.com" + SentTo = @("different@contoso.com") } } @@ -162,7 +162,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { IsSingleInstance = 'Yes' Identity = "DefaultReportSubmissionRule" Comments = "This is my default rule" - SentTo = "submission@contoso.com" + SentTo = @("submission@contoso.com") } Mock -CommandName Get-ReportSubmissionRule -MockWith { @@ -200,7 +200,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { return @{ Identity = "DefaultReportSubmissionRule" Comments = "This is my default rule" - SentTo = "submission@contoso.com" + SentTo = @("submission@contoso.com") } } } diff --git a/Tests/Unit/Stubs/Microsoft365.psm1 b/Tests/Unit/Stubs/Microsoft365.psm1 index 5e66f3f48c..787981a87f 100644 --- a/Tests/Unit/Stubs/Microsoft365.psm1 +++ b/Tests/Unit/Stubs/Microsoft365.psm1 @@ -4360,7 +4360,21 @@ function New-ReportSubmissionRule { [CmdletBinding()] param( + [Parameter()] + [System.String] + $Name, + + [Parameter()] + [System.String] + $Comments, + [Parameter()] + [System.String[]] + $SentTo, + + [Parameter()] + [System.String] + $ReportSubmissionRule ) } function New-RoleAssignmentPolicy @@ -11532,7 +11546,7 @@ function Set-ReportSubmissionRule $Comments, [Parameter()] - [System.String] + [System.String[]] $SentTo, [Parameter()] From fb51b1c1cc70ab2d9f152c3f4b7c611e56ca341c Mon Sep 17 00:00:00 2001 From: mario Date: Wed, 3 Jan 2024 14:01:03 +0100 Subject: [PATCH 10/12] fix stub --- Tests/Unit/Stubs/Microsoft365.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/Stubs/Microsoft365.psm1 b/Tests/Unit/Stubs/Microsoft365.psm1 index 787981a87f..f5544b9f0f 100644 --- a/Tests/Unit/Stubs/Microsoft365.psm1 +++ b/Tests/Unit/Stubs/Microsoft365.psm1 @@ -4374,7 +4374,7 @@ function New-ReportSubmissionRule [Parameter()] [System.String] - $ReportSubmissionRule + $ReportSubmissionPolicy ) } function New-RoleAssignmentPolicy From 869274e7ee82090152e736777bd2082e61d129b3 Mon Sep 17 00:00:00 2001 From: mario Date: Wed, 3 Jan 2024 14:46:07 +0100 Subject: [PATCH 11/12] adjustments after review --- .../MSFT_EXOReportSubmissionPolicy.schema.mof | 2 +- .../Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 | 9 +++------ .../Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 | 9 +++------ 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.schema.mof b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.schema.mof index 81d8e3a7d6..b23f9eef75 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.schema.mof +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOReportSubmissionPolicy/MSFT_EXOReportSubmissionPolicy.schema.mof @@ -25,7 +25,7 @@ class MSFT_EXOReportSubmissionPolicy : OMI_BaseResource [Write, Description("The ReportNotJunkAddresses parameter specifies the email address of the reporting mailbox in Exchange Online to receive user reported messages in reporting in Outlook using Microsoft or third-party reporting tools in Outlook.")] String ReportNotJunkAddresses[]; [Write, Description("The ReportNotJunkToCustomizedAddress parameter specifies whether to send user reported messages from Outlook (using Microsoft or third-party reporting tools) to the reporting mailbox as part of reporting in Outlook.")] Boolean ReportNotJunkToCustomizedAddress; [Write, Description("The ReportPhishAddresses parameter specifies the email address of the reporting mailbox in Exchange Online to receive user reported messages in reporting in Outlook using Microsoft or third-party reporting tools in Outlook.")] String ReportPhishAddresses[]; - [Write, Description("he ReportPhishToCustomizedAddress parameter specifies whether to send user reported messages from Outlook (using Microsoft or third-party reporting tools) to the reporting mailbox as part of reporting in Outlook.")] Boolean ReportPhishToCustomizedAddress; + [Write, Description("The ReportPhishToCustomizedAddress parameter specifies whether to send user reported messages from Outlook (using Microsoft or third-party reporting tools) to the reporting mailbox as part of reporting in Outlook.")] Boolean ReportPhishToCustomizedAddress; [Write, Description("Use the ThirdPartyReportAddresses parameter to specify the email address of the reporting mailbox when you're using a third-party product for user submissions instead of reporting in Outlook.")] String ThirdPartyReportAddresses[]; [Write, Description("Specifies if this report submission policy should exist."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Write, Description("Credentials of the Exchange Global Admin"), EmbeddedInstance("MSFT_Credential")] string Credential; diff --git a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 index fbc8b1287f..2f26425189 100644 --- a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 +++ b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 @@ -89,8 +89,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } It 'Should call the Set method' { - Set-TargetResource @testParams - Should -Invoke -CommandName 'New-ReportSubmissionPolicy' -Exactly 1 + Set-TargetResource @testParams | Should -Invoke -CommandName 'New-ReportSubmissionPolicy' -Exactly 1 } } @@ -189,8 +188,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } It 'Should Successfully call the Set method' { - Set-TargetResource @testParams - Should -Invoke -CommandName 'Set-ReportSubmissionPolicy' -Exactly 1 + Set-TargetResource @testParams | Should -Invoke -CommandName 'Set-ReportSubmissionPolicy' -Exactly 1 } } @@ -221,8 +219,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } It 'Should Remove the Policy in the Set method' { - Set-TargetResource @testParams - Should -Invoke -CommandName 'Remove-ReportSubmissionPolicy' -Exactly 1 + Set-TargetResource @testParams | Should -Invoke -CommandName 'Remove-ReportSubmissionPolicy' -Exactly 1 } } diff --git a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 index 6dac6f96ce..0cc3c5e9c2 100644 --- a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 +++ b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 @@ -81,8 +81,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } It 'Should call the Set method' { - Set-TargetResource @testParams - Should -Invoke -CommandName 'New-ReportSubmissionRule' -Exactly 1 + Set-TargetResource @testParams | Should -Invoke -CommandName 'New-ReportSubmissionRule' -Exactly 1 } } @@ -149,8 +148,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } It 'Should Successfully call the Set method' { - Set-TargetResource @testParams - Should -Invoke -CommandName 'Set-ReportSubmissionRule' -Exactly 1 + Set-TargetResource @testParams | Should -Invoke -CommandName 'Set-ReportSubmissionRule' -Exactly 1 } } @@ -183,8 +181,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } It 'Should Remove the Policy in the Set method' { - Set-TargetResource @testParams - Should -Invoke -CommandName 'Remove-ReportSubmissionRule' -Exactly 1 + Set-TargetResource @testParams | Should -Invoke -CommandName 'Remove-ReportSubmissionRule' -Exactly 1 } } From ca9e01d541570fb2190446b1c25cee555985f39d Mon Sep 17 00:00:00 2001 From: mario Date: Wed, 3 Jan 2024 15:09:22 +0100 Subject: [PATCH 12/12] tests --- .../Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 | 9 ++++++--- .../Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 index 2f26425189..fbc8b1287f 100644 --- a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 +++ b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionPolicy.Tests.ps1 @@ -89,7 +89,8 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } It 'Should call the Set method' { - Set-TargetResource @testParams | Should -Invoke -CommandName 'New-ReportSubmissionPolicy' -Exactly 1 + Set-TargetResource @testParams + Should -Invoke -CommandName 'New-ReportSubmissionPolicy' -Exactly 1 } } @@ -188,7 +189,8 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } It 'Should Successfully call the Set method' { - Set-TargetResource @testParams | Should -Invoke -CommandName 'Set-ReportSubmissionPolicy' -Exactly 1 + Set-TargetResource @testParams + Should -Invoke -CommandName 'Set-ReportSubmissionPolicy' -Exactly 1 } } @@ -219,7 +221,8 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } It 'Should Remove the Policy in the Set method' { - Set-TargetResource @testParams | Should -Invoke -CommandName 'Remove-ReportSubmissionPolicy' -Exactly 1 + Set-TargetResource @testParams + Should -Invoke -CommandName 'Remove-ReportSubmissionPolicy' -Exactly 1 } } diff --git a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 index 0cc3c5e9c2..6dac6f96ce 100644 --- a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 +++ b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.EXOReportSubmissionRule.Tests.ps1 @@ -81,7 +81,8 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } It 'Should call the Set method' { - Set-TargetResource @testParams | Should -Invoke -CommandName 'New-ReportSubmissionRule' -Exactly 1 + Set-TargetResource @testParams + Should -Invoke -CommandName 'New-ReportSubmissionRule' -Exactly 1 } } @@ -148,7 +149,8 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } It 'Should Successfully call the Set method' { - Set-TargetResource @testParams | Should -Invoke -CommandName 'Set-ReportSubmissionRule' -Exactly 1 + Set-TargetResource @testParams + Should -Invoke -CommandName 'Set-ReportSubmissionRule' -Exactly 1 } } @@ -181,7 +183,8 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { } It 'Should Remove the Policy in the Set method' { - Set-TargetResource @testParams | Should -Invoke -CommandName 'Remove-ReportSubmissionRule' -Exactly 1 + Set-TargetResource @testParams + Should -Invoke -CommandName 'Remove-ReportSubmissionRule' -Exactly 1 } }