-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1437 from ChristophHannappel/fix/SPCertificateSet…
…tings Fixes Compare-Object Exception if there are currently no CertificateN…
- Loading branch information
Showing
3 changed files
with
83 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ function Invoke-TestSetup | |
|
||
$script:testEnvironment = Initialize-TestEnvironment ` | ||
-DSCModuleName $script:DSCModuleName ` | ||
-DSCResourceName $script:DSCResourceFullName ` | ||
-DscResourceName $script:DSCResourceFullName ` | ||
-ResourceType 'Mof' ` | ||
-TestType 'Unit' | ||
} | ||
|
@@ -260,7 +260,7 @@ try | |
CertificateExpirationWarningThresholdDays = 15 | ||
CertificateExpirationErrorThresholdDays = 15 | ||
CertificateNotificationContacts = @( | ||
@{ | ||
[PSCustomObject]@{ | ||
Address = '[email protected]' | ||
} | ||
) | ||
|
@@ -270,7 +270,7 @@ try | |
Mock -CommandName Get-SPFarm -MockWith { return @{ } } | ||
Mock -CommandName Get-SPCertificateNotificationContact -MockWith { | ||
return @( | ||
@{ | ||
[PSCustomObject]@{ | ||
Address = '[email protected]' | ||
} | ||
) | ||
|
@@ -295,6 +295,55 @@ try | |
} | ||
} | ||
|
||
Context -Name "The server is in a farm and zero contacts have been applied" -Fixture { | ||
BeforeAll { | ||
$testParams = @{ | ||
IsSingleInstance = 'Yes' | ||
CertificateNotificationContacts = '[email protected]' | ||
} | ||
|
||
Mock -CommandName Get-SPCertificateSettings -MockWith { | ||
$returnVal = @{ | ||
DefaultOrganizationalUnit = '' | ||
DefaultOrganization = '' | ||
DefaultLocality = '' | ||
DefaultState = '' | ||
DefaultCountry = '' | ||
DefaultKeyAlgorithm = 'RSA' | ||
DefaultRsaKeySize = 2048 | ||
DefaultEllipticCurve = 'nistP256' | ||
DefaultHashAlgorithm = 'SHA256' | ||
DefaultRsaSignaturePadding = 'Pkcs1' | ||
CertificateExpirationAttentionThresholdDays = 60 | ||
CertificateExpirationWarningThresholdDays = 15 | ||
CertificateExpirationErrorThresholdDays = 15 | ||
CertificateNotificationContacts = [System.Net.Mail.MailAddressCollection]::new() | ||
} | ||
return $returnVal | ||
} | ||
Mock -CommandName Get-SPFarm -MockWith { return @{ } } | ||
Mock -CommandName Get-SPCertificateNotificationContact -MockWith { | ||
return [System.Net.Mail.MailAddressCollection]::new() | ||
} | ||
Mock -CommandName Add-SPCertificateNotificationContact -MockWith {} | ||
Mock -CommandName Remove-SPCertificateNotificationContact -MockWith {} | ||
} | ||
|
||
It "Should return values from the get method" { | ||
$result = Get-TargetResource @testParams | ||
$result.CertificateNotificationContacts.Count | Should -Be 0 | ||
} | ||
|
||
It "Should return false from the test method" { | ||
Test-TargetResource @testParams | Should -Be $false | ||
} | ||
|
||
It "Should update the certificate settings" { | ||
Set-TargetResource @testParams | ||
Assert-MockCalled Add-SPCertificateNotificationContact | ||
} | ||
} | ||
|
||
Context -Name "The server is in a farm and the correct settings have been applied" -Fixture { | ||
BeforeAll { | ||
$testParams = @{ | ||
|