Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingInvokeExpression', '', Justification = 'Pester testing file')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidOverwritingBuiltInCmdlets', '', Justification = 'Pester testing file')]
[CmdletBinding()]
param()
BeforeAll {
$Script:parentPath = (Split-Path -Parent $PSScriptRoot)
$Script:Server = $env:COMPUTERNAME
. $Script:parentPath\Get-ExchangeEmergencyMitigationServiceState.ps1

# We need to overwrite the existing 'Get-Service' function because it doesn't support
# the '-ComputerName' parameter on PowerShell 7
Function Get-Service {
param(
[Parameter(Mandatory = $false)]
[string]
$ComputerName,
[Parameter(Mandatory = $false)]
[string]
$Name
)
}
}

Describe "Testing Get-ExchangeEmergencyMitigationServiceState.ps1" {

BeforeAll {
Mock Invoke-WebRequest -MockWith { return Import-Clixml $Script:parentPath\Tests\InvokeWebRequestEEMS.xml }
Mock Get-Service -MockWith { return Import-Clixml $Script:parentPath\Tests\GetServiceMSExchangeMitigationRunning.xml } `
-ParameterFilter { $ComputerName -eq $Script:Server }

$Script:customObject = ([PSCustomObject]@{
ComputerName = $Script:Server
MitigationsEnabled = $true
GetExchangeServer = [PSCustomObject]@{
InternetWebProxy = $null
MitigationsEnabled = $true
MitigationsApplied = "PING01"
MitigationsBlocked = $null
DataCollectionEnabled = $true
}
})
}

Context "Exchange Emergency Mitigation Service Default State" {

BeforeAll {
$Script:results = Get-ExchangeEmergencyMitigationServiceState -RequiredInformation $customObject
}

It "Mitigation Service Enabled On Org Level" {
$results.MitigationServiceOrgState | Should -Be $true
}

It "Mitigation Service Enabled On Srv Level" {
$results.MitigationServiceSrvState | Should -Be $true
}

It "Mitigation Windows Service Enabled And Running" {
$results.MitigationWinServiceState | Should -Be "Running"
}

It "Mitigation Service Endpoint Reachable" {
$results.MitigationServiceEndpoint | Should -Be 200
}

It "PING Mitigation Applied" {
$results.MitigationsApplied | Should -Be "PING01"
}

It "Telemetry Enabled" {
$results.DataCollectionEnabled | Should -Be $true
}
}

Context "Exchange Emergency Mitigation Service Disabled State" {

BeforeAll {
Mock Get-Service -MockWith { return Import-Clixml $Script:parentPath\Tests\GetServiceMSExchangeMitigationDisabled.xml } `
-ParameterFilter { $ComputerName -eq $Script:Server }

$Script:customObject.MitigationsEnabled = $false
$Script:customObject.GetExchangeServer.MitigationsEnabled = $false
$Script:customObject.GetExchangeServer.DataCollectionEnabled = $false
$Script:results = Get-ExchangeEmergencyMitigationServiceState -RequiredInformation $customObject
}

It "Mitigation Service Disabled On Org Level" {
$results.MitigationServiceOrgState | Should -Be $false
}

It "Mitigation Service Disabled On Srv Level" {
$results.MitigationServiceSrvState | Should -Be $false
}

It "Mitigation Windows Service Disabled And Stopped" {
$results.MitigationWinServiceState | Should -Be "Investigate"
}

It "Mitigation Service Endpoint Reachable" {
$results.MitigationServiceEndpoint | Should -Be 200
}

It "PING Mitigation Applied" {
$results.MitigationsApplied | Should -Be "PING01"
}

It "Telemetry Disabled" {
$results.DataCollectionEnabled | Should -Be $false
}
}

Context "Exchange Emergency Mitigation Service OCS Not Reachable" {

BeforeAll {
Mock Invoke-WebRequest -MockWith { return $null }

$Script:customObject.GetExchangeServer.MitigationsApplied = $null
$Script:results = Get-ExchangeEmergencyMitigationServiceState -RequiredInformation $customObject
}

It "Mitigation Service Endpoint Not Reachable" {
$results.MitigationServiceEndpoint | Should -Be $null
}

It "No Mitigation Applied" {
$results.MitigationsApplied | Should -Be $null
}

It "No Mitigation Blocked" {
$results.MitigationsBlocked | Should -Be $null
}
}

Context "Exchange Emergency Mitigation Service Mitigations Applied/Blocked" {

BeforeAll {
Mock Invoke-WebRequest -MockWith { return $null }

$mitigationsAppliedArray = @("PING01", "M01", "M03")
$mitigationsBlockedArray = @("M02")
$Script:customObject.GetExchangeServer.MitigationsApplied = $mitigationsAppliedArray
$Script:customObject.GetExchangeServer.MitigationsBlocked = $mitigationsBlockedArray
$Script:results = Get-ExchangeEmergencyMitigationServiceState -RequiredInformation $customObject
}

It "3 Mitigations Applied" {
($results.MitigationsApplied).Count | Should -Be 3
$results.MitigationsApplied | Should -Be $mitigationsAppliedArray
}

It "1 Mitigation Blocked" {
($results.MitigationsBlocked).Count | Should -Be 1
$results.MitigationsBlocked | Should -Be "M02"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
<Obj RefId="0">
<TN RefId="0">
<T>System.ServiceProcess.ServiceController</T>
<T>System.ComponentModel.Component</T>
<T>System.MarshalByRefObject</T>
<T>System.Object</T>
</TN>
<ToString>MSExchangeMitigation</ToString>
<Props>
<B N="CanPauseAndContinue">false</B>
<B N="CanShutdown">false</B>
<B N="CanStop">false</B>
<S N="DisplayName">Microsoft Exchange Emergency Mitigation Service</S>
<Obj N="DependentServices" RefId="1">
<TN RefId="1">
<T>System.ServiceProcess.ServiceController[]</T>
<T>System.Array</T>
<T>System.Object</T>
</TN>
<LST />
</Obj>
<S N="MachineName">.</S>
<S N="ServiceName">MSExchangeMitigation</S>
<Obj N="ServicesDependedOn" RefId="2">
<TNRef RefId="1" />
<LST>
<Obj RefId="3">
<TNRef RefId="0" />
<ToString>MSExchangeADTopology</ToString>
<Props>
<B N="CanPauseAndContinue">false</B>
<B N="CanShutdown">true</B>
<B N="CanStop">true</B>
<S N="DisplayName">Microsoft Exchange Active Directory Topology</S>
<Obj N="DependentServices" RefId="4">
<TNRef RefId="1" />
<LST>
<S>MSExchangePOP3</S>
<S>MSExchangeIMAP4</S>
<S>MSExchangeFrontendTransport</S>
<S>MSExchangeCompliance</S>
<S>MSExchangeFastSearch</S>
<S>MSExchangeDagMgmt</S>
<S>MSExchangeRepl</S>
<S>MSExchangeThrottling</S>
<S>MSExchangeMailboxAssistants</S>
<S>MSExchangeMitigation</S>
<S>MSComplianceAudit</S>
<S>MSExchangeDelivery</S>
<S>MSExchangeSubmission</S>
<S>MSExchangeIS</S>
<S>MSExchangeRPC</S>
<S>MSExchangePOP3BE</S>
<S>MSExchangeIMAP4BE</S>
<S>MSExchangeMailboxReplication</S>
<S>MSExchangeServiceHost</S>
<S>MSExchangeTransportLogSearch</S>
<S>MSExchangeAntispamUpdate</S>
<S>MSExchangeEdgeSync</S>
<S>MSExchangeTransport</S>
</LST>
</Obj>
<S N="MachineName">.</S>
<S N="ServiceName">MSExchangeADTopology</S>
<Obj N="ServicesDependedOn" RefId="5">
<TNRef RefId="1" />
<LST>
<S>Netlogon</S>
<S>NetTcpPortSharing</S>
</LST>
</Obj>
<S N="ServiceHandle">SafeServiceHandle</S>
<S N="Status">Running</S>
<S N="ServiceType">Win32OwnProcess</S>
<S N="StartType">Automatic</S>
<Nil N="Site" />
<Nil N="Container" />
</Props>
<MS>
<S N="Name">MSExchangeADTopology</S>
<Ref N="RequiredServices" RefId="5" />
</MS>
</Obj>
</LST>
</Obj>
<Obj N="ServiceHandle" RefId="6">
<TN RefId="2">
<T>SafeServiceHandle</T>
<T>Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid</T>
<T>System.Runtime.InteropServices.SafeHandle</T>
<T>System.Runtime.ConstrainedExecution.CriticalFinalizerObject</T>
<T>System.Object</T>
</TN>
<ToString>SafeServiceHandle</ToString>
<Props>
<B N="IsInvalid">false</B>
<B N="IsClosed">false</B>
</Props>
</Obj>
<Obj N="Status" RefId="7">
<TN RefId="3">
<T>System.ServiceProcess.ServiceControllerStatus</T>
<T>System.Enum</T>
<T>System.ValueType</T>
<T>System.Object</T>
</TN>
<ToString>Stopped</ToString>
<I32>1</I32>
</Obj>
<Obj N="ServiceType" RefId="8">
<TN RefId="4">
<T>System.ServiceProcess.ServiceType</T>
<T>System.Enum</T>
<T>System.ValueType</T>
<T>System.Object</T>
</TN>
<ToString>Win32OwnProcess</ToString>
<I32>16</I32>
</Obj>
<Obj N="StartType" RefId="9">
<TN RefId="5">
<T>System.ServiceProcess.ServiceStartMode</T>
<T>System.Enum</T>
<T>System.ValueType</T>
<T>System.Object</T>
</TN>
<ToString>Disabled</ToString>
<I32>4</I32>
</Obj>
<Nil N="Site" />
<Nil N="Container" />
</Props>
<MS>
<S N="Name">MSExchangeMitigation</S>
<Ref N="RequiredServices" RefId="2" />
</MS>
</Obj>
</Objs>
Loading