Skip to content

Commit

Permalink
Merge pull request #109 from PlagueHO/Issue-105
Browse files Browse the repository at this point in the history
Updated tests to meet Pester V4 guidelines - Fixes #105
  • Loading branch information
PlagueHO committed Nov 18, 2017
2 parents 30f4917 + ef6bc9b commit 9f3f387
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 205 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@
to correctly generate parameter documentation in Wiki - see [Issue #103](https://github.com/PowerShell/xCertificate/issues/103).
- Changed description in Credential parameter of xCertReq resource
to clarify that a PSCredential object should be used.
- Updated tests to meet Pester V4 guidelines - fixes [Issue #105](https://github.com/PowerShell/xCertificate/issues/105).

## 3.0.0.0

Expand Down
18 changes: 9 additions & 9 deletions Tests/Integration/MSFT_xCertReq.Integration.Tests.ps1
Expand Up @@ -103,11 +103,11 @@ try
-ConfigurationData $configData

Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
} | Should Not Throw
} | Should -Not -Throw
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not Throw
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw
}

It 'Should have set the resource and all the parameters should match' {
Expand All @@ -117,13 +117,13 @@ try
$_.Subject -eq "CN=$($subject)" -and `
$_.Issuer.split(',')[0] -eq "CN=$($caRootName)"
}
$CertificateNew.Subject | Should Be "CN=$($subject)"
$CertificateNew.Issuer.split(',')[0] | Should Be "CN=$($caRootName)"
$CertificateNew.Publickey.Key.KeySize | Should Be $keyLength
$CertificateNew.FriendlyName | Should Be $friendlyName
$CertificateNew.DnsNameList[0] | Should Be $dns1
$CertificateNew.DnsNameList[1] | Should Be $dns2
$CertificateNew.EnhancedKeyUsageList.ObjectId | Should Be $oid
$CertificateNew.Subject | Should -Be "CN=$($subject)"
$CertificateNew.Issuer.split(',')[0] | Should -Be "CN=$($caRootName)"
$CertificateNew.Publickey.Key.KeySize | Should -Be $keyLength
$CertificateNew.FriendlyName | Should -Be $friendlyName
$CertificateNew.DnsNameList[0] | Should -Be $dns1
$CertificateNew.DnsNameList[1] | Should -Be $dns2
$CertificateNew.EnhancedKeyUsageList.ObjectId | Should -Be $oid
}
}
#endregion
Expand Down
16 changes: 8 additions & 8 deletions Tests/Integration/MSFT_xCertificateExport.Integration.Tests.ps1
Expand Up @@ -86,22 +86,22 @@ try
-ConfigurationData $ConfigData

Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
} | Should Not Throw
} | Should -Not -Throw
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{ $script:currentCertificate = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not Throw
{ $script:currentCertificate = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw
}
#endregion

It 'Should have exported a Cert certificate' {
$script:currentCertificate.IsExported | Should Be $true
$script:currentCertificate.IsExported | Should -Be $true
}

It 'Should have set the resource and the thumbprint of the exported certificate should match' {
$exportedCertificate = New-Object -TypeName 'System.Security.Cryptography.X509Certificates.X509Certificate2Collection'
$exportedCertificate.Import($script:certificatePath)
$exportedCertificate[0].Thumbprint | Should Be $script:validCertificateThumbprint
$exportedCertificate[0].Thumbprint | Should -Be $script:validCertificateThumbprint
}
}

Expand Down Expand Up @@ -135,22 +135,22 @@ try
-ConfigurationData $ConfigData

Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
} | Should Not Throw
} | Should -Not -Throw
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{ $script:currentPFX = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not Throw
{ $script:currentPFX = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw
}
#endregion

It 'Should have exported a PFX certificate' {
$script:currentPFX.IsExported | Should Be $true
$script:currentPFX.IsExported | Should -Be $true
}

It 'Should have set the resource and the thumbprint of the exported certificate should match' {
$exportedCertificate = New-Object -TypeName 'System.Security.Cryptography.X509Certificates.X509Certificate2Collection'
$exportedCertificate.Import($script:certificatePath,$pfxPassword,[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::PersistKeySet)
$exportedCertificate[0].Thumbprint | Should Be $script:validCertificateThumbprint
$exportedCertificate[0].Thumbprint | Should -Be $script:validCertificateThumbprint
}
}

Expand Down
16 changes: 8 additions & 8 deletions Tests/Integration/MSFT_xCertificateImport.Integration.Tests.ps1
Expand Up @@ -52,21 +52,21 @@ try
-Thumbprint $Certificate.Thumbprint

Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
} | Should Not Throw
} | Should -Not -Throw
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not Throw
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw
}
#endregion

It 'Should have set the resource and all the parameters should match' {
# Get the Certificate details
$CertificateNew = Get-Item `
-Path "Cert:\LocalMachine\My\$($Certificate.Thumbprint)"
$CertificateNew | Should BeOfType System.Security.Cryptography.X509Certificates.X509Certificate2
$CertificateNew.Thumbprint | Should Be $Certificate.Thumbprint
$CertificateNew.Subject | Should Be $Certificate.Subject
$CertificateNew | Should -BeOfType System.Security.Cryptography.X509Certificates.X509Certificate2
$CertificateNew.Thumbprint | Should -Be $Certificate.Thumbprint
$CertificateNew.Subject | Should -Be $Certificate.Subject
}
}
#endregion
Expand All @@ -84,11 +84,11 @@ try
-Path $CertificatePath `
-Thumbprint $Certificate.Thumbprint
Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
} | Should not throw
} | Should -Not -Throw
}

It 'should be able to call Get-DscConfiguration without throwing' {
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not throw
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw
}
#endregion

Expand All @@ -97,7 +97,7 @@ try
$CertificateNew = Get-Item `
-Path "Cert:\LocalMachine\My\$($Certificate.Thumbprint)" `
-ErrorAction SilentlyContinue
$CertificateNew | Should BeNullOrEmpty
$CertificateNew | Should -BeNullOrEmpty
}
}
#endregion
Expand Down
16 changes: 8 additions & 8 deletions Tests/Integration/MSFT_xPfxImport.Integration.Tests.ps1
Expand Up @@ -68,21 +68,21 @@ try
-Credential $testCredential

Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
} | Should Not Throw
} | Should -Not -Throw
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not Throw
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw
}
#endregion

It 'Should have set the resource and all the parameters should match' {
# Get the Certificate details
$CertificateNew = Get-Item `
-Path "Cert:\LocalMachine\My\$($Certificate.Thumbprint)"
$CertificateNew | Should BeOfType System.Security.Cryptography.X509Certificates.X509Certificate2
$CertificateNew.Thumbprint | Should Be $Certificate.Thumbprint
$CertificateNew.Subject | Should Be $Certificate.Subject
$CertificateNew | Should -BeOfType System.Security.Cryptography.X509Certificates.X509Certificate2
$CertificateNew.Thumbprint | Should -Be $Certificate.Thumbprint
$CertificateNew.Subject | Should -Be $Certificate.Subject
}
}
#endregion
Expand All @@ -101,11 +101,11 @@ try
-Thumbprint $Certificate.Thumbprint

Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
} | Should Not Throw
} | Should -Not -Throw
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not Throw
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw
}
#endregion

Expand All @@ -114,7 +114,7 @@ try
$CertificateNew = Get-Item `
-Path "Cert:\LocalMachine\My\$($Certificate.Thumbprint)" `
-ErrorAction SilentlyContinue
$CertificateNew | Should BeNullOrEmpty
$CertificateNew | Should -BeNullOrEmpty
}
}
#endregion
Expand Down
Expand Up @@ -67,20 +67,20 @@ try
-ConfigurationData $configData

Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
} | Should Not Throw
} | Should -Not -Throw
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not Throw
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw
}

It 'Should have set the resource and all the parameters should match' {
$current = Get-DscConfiguration | Where-Object {
$_.ConfigurationName -eq "$($script:DSCResourceName)_Config"
}

$current.CAServerFQDN | Should Be $caServerFQDN
$current.CARootName | Should Be $caRootName
$current.CAServerFQDN | Should -Be $caServerFQDN
$current.CARootName | Should -Be $caRootName
}
}
#endregion
Expand Down Expand Up @@ -110,20 +110,20 @@ try
-ConfigurationData $configData

Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Wait -Verbose -Force
} | Should Not Throw
} | Should -Not -Throw
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should Not Throw
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw
}

It 'Should have set the resource and all the parameters should match' {
$current = Get-DscConfiguration | Where-Object {
$_.ConfigurationName -eq "$($script:DSCResourceName)_Config"
}

$current.CAServerFQDN | Should Be $caServerFQDN
$current.CARootName | Should Be $caRootName
$current.CAServerFQDN | Should -Be $caServerFQDN
$current.CARootName | Should -Be $caRootName
}
}
#endregion
Expand Down
2 changes: 1 addition & 1 deletion Tests/Integration/ModuleConflict.Tests.ps1
Expand Up @@ -34,7 +34,7 @@ try
It "Should be able to install DSC Resource module '$moduleToTest'" {
{
Install-Module -Name $moduleToTest -ErrorAction Stop
} | Should Not Throw
} | Should -Not -Throw
}
}
}
Expand Down

0 comments on commit 9f3f387

Please sign in to comment.