Skip to content

Commit

Permalink
fixing the pester tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SSvilen committed Apr 18, 2020
1 parent cbe6efc commit 8608980
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
41 changes: 23 additions & 18 deletions tests/Unit/MSFT_xExchReceiveConnector.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ try
$Identity
)
}
function Set-ADExtendedPermissions
{
param (
$ExtendedRightAllowEntries,
$ExtendedRightDenyEntries,
$Identity,
$NewObject
)
}
function New-ReceiveConnector
{
param (
Expand Down Expand Up @@ -189,11 +198,10 @@ try
value = 'ms-Exch-SMTP-Accept-Any-Recipient,ms-Exch-SMTP-Accept-Any-Sender'
} -ClientOnly

Mock -CommandName 'Add-ADPermission' -Verifiable -ParameterFilter {
Mock -CommandName 'Set-ADExtendedPermissions' -Verifiable -ParameterFilter {
$Identity -eq 'ReceiveConnector' -and
$User -eq 'User1Allow' -and
($ExtendedRights -eq 'ms-Exch-SMTP-Accept-Any-Recipient' -or
$ExtendedRights -eq 'ms-Exch-SMTP-Accept-Any-Sender')
$NewObject -eq $false -and
$ExtendedRightAllowEntries.Key -eq 'User1Allow'
}

Set-TargetResource @setTargetResourcePermissions
Expand All @@ -205,12 +213,10 @@ try
value = 'ms-Exch-SMTP-Accept-Any-Recipient,ms-Exch-SMTP-Accept-Any-Sender'
} -ClientOnly

Mock -CommandName 'Add-ADPermission' -Verifiable -ParameterFilter {
Mock -CommandName 'Set-ADExtendedPermissions' -Verifiable -ParameterFilter {
$Identity -eq 'ReceiveConnector' -and
$User -eq 'User2Deny' -and
$Deny -eq $true -and
($ExtendedRights -eq 'ms-Exch-SMTP-Accept-Any-Recipient' -or
$ExtendedRights -eq 'ms-Exch-SMTP-Accept-Any-Sender')
$NewObject -eq $false -and
$ExtendedRightDenyEntries.Key -eq 'User2Deny'
}

Set-TargetResource @setTargetResourcePermissions
Expand Down Expand Up @@ -241,7 +247,11 @@ try
value = 'ms-Exch-SMTP-Accept-Any-Recipient,ms-Exch-SMTP-Accept-Any-Sender'
} -ClientOnly

Mock -CommandName 'Set-ADExtendedPermissions ' -Verifiable -ParameterFilter { $Identity -eq 'ReceiveConnector'}
Mock -CommandName 'Set-ADExtendedPermissions' -Verifiable -ParameterFilter {
$Identity -eq 'ReceiveConnector' -and
$NewObject -eq $true -and
$ExtendedRightAllowEntries.Key -eq 'User1Allow'
}

Set-TargetResource @setTargetResourcePermissions
}
Expand All @@ -252,15 +262,10 @@ try
value = 'ms-Exch-SMTP-Accept-Any-Recipient,ms-Exch-SMTP-Accept-Any-Sender'
} -ClientOnly

Mock -CommandName 'Get-ADPermission' -Verifiable -ParameterFilter { $Identity -eq 'ReceiveConnector' } -MockWith {
$setTargetResourcePermissions['ExtendedRightDenyEntries']
}
Mock -CommandName 'Add-ADPermission' -Verifiable -ParameterFilter {
Mock -CommandName 'Set-ADExtendedPermissions' -Verifiable -ParameterFilter {
$Identity -eq 'ReceiveConnector' -and
$User -eq 'User2Deny' -and
$Deny -eq $true -and
($ExtendedRights -eq 'ms-Exch-SMTP-Accept-Any-Recipient' -or
$ExtendedRights -eq 'ms-Exch-SMTP-Accept-Any-Sender')
$NewObject -eq $true -and
$ExtendedRightDenyEntries.Key -eq 'User2Deny'
}

Set-TargetResource @setTargetResourcePermissions
Expand Down
6 changes: 1 addition & 5 deletions tests/Unit/xExchangeHelper.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3164,7 +3164,7 @@ try
It 'Should throw when the object is not found' {
Mock -CommandName 'Get-ADPermission' -Verifiable -ParameterFilter { $Identity -eq 'FakeADObject' }

{ Set-ADExtendedPermissions -Identity 'FakeADobject' -NewObject } | Should -Throw "The AD Object $Identity was not found after 2 minutes of wait time. Please check AD replication!"
{ Set-ADExtendedPermissions -Identity 'FakeADobject' -NewObject } | Should -Throw "The AD Object FakeADobject was not found after 2 minutes of wait time. Please check AD replication!"
}
It 'Should set the allow Permissions when specified' {
$ExtendedRightAllowEntries = New-CimInstance -ClassName MSFT_KeyValuePair -Property @{
Expand All @@ -3177,15 +3177,13 @@ try
}
Mock -CommandName 'Add-ADPermission' -Verifiable -ParameterFilter {
$Identity -eq 'FakeADObject' -and
$DomainController -eq 'FakeDC.local.com' -and
$User -eq 'User1Allow' -and
($ExtendedRights -eq 'ms-Exch-SMTP-Accept-Any-Recipient' -or
$ExtendedRights -eq 'ms-Exch-SMTP-Accept-Any-Sender')
}

$splat = @{
ExtendedRightAllowEntries = $ExtendedRightAllowEntries
DomainController = 'FakeDC.local.com'
Identity = 'FakeADObject'
NewObject = $true
}
Expand All @@ -3203,7 +3201,6 @@ try
}
Mock -CommandName 'Add-ADPermission' -Verifiable -ParameterFilter {
$Identity -eq 'FakeADObject' -and
$DomainController -eq 'FakeDC.local.com' -and
$User -eq 'User2Deny' -and
$Deny -eq $true -and
($ExtendedRights -eq 'ms-Exch-SMTP-Accept-Any-Recipient' -or
Expand All @@ -3212,7 +3209,6 @@ try

$splat = @{
ExtendedRightDenyEntries = $ExtendedRightDenyEntries
DomainController = 'FakeDC.local.com'
Identity = 'FakeADObject'
NewObject = $true
}
Expand Down

0 comments on commit 8608980

Please sign in to comment.