-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xCertificateExport: Fixed bug causing pfx export with matchsource enabled to fail #117
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #117 +/- ##
==================================
Coverage 94% 94%
==================================
Files 5 5
Lines 517 517
Branches 2 2
==================================
Hits 488 488
Misses 27 27
Partials 2 2 |
Great job @hackjammer I'm a bit worried about this change though. All the documentation I can find as well as examining the So, with that in mind I'd suggest the following (and see all my other comments): Could you replace the Context 'Export PFX and then Export PFX again to ensure no errors' {
#region DEFAULT TESTS
It 'Should compile and apply the MOF without throwing' {
{
$ConfigData = @{
AllNodes = @(
@{
NodeName = 'localhost'
Path = $script:pfxPath
FriendlyName = $certFriendlyName
Subject = $certificateSubject
DNSName = $certificateDNSNames
Issuer = $certificateSubject
KeyUsage = $certificateKeyUsage
EnhancedKeyUsage = $certificateEKU
MatchSource = $true
Type = 'PFX'
ChainOption = 'BuildChain'
Password = $pfxCredential
PsDscAllowPlainTextPassword = $true
}
)
}
& "$($script:DSCResourceName)_Config" `
-OutputPath $TestDrive `
-ConfigurationData $ConfigData
Start-DscConfiguration `
-Path $TestDrive `
-ComputerName localhost `
-Wait `
-Verbose `
-Force `
-ErrorAction Stop
} | Should -Not -Throw
}
It 'Should be able to call Get-DscConfiguration without throwing' {
{ $script:currentPFX = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw
}
#endregion
It 'Should have exported a PFX certificate' {
$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
}
# Apply the MOF a second time to ensure no errors occur
It 'Should apply the MOF a second time without throwing' {
{
Start-DscConfiguration `
-Path $TestDrive `
-ComputerName localhost `
-Wait `
-Verbose `
-Force `
-ErrorAction Stop
} | Should -Not -Throw
}
It 'Should be able to call Get-DscConfiguration without throwing' {
{ $script:currentPFX = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw
}
#endregion
It 'Should have exported a PFX certificate' {
$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
}
} I actually started fixing this one before I saw you already had - so I'd updated the integration tests to catch this one (I like to practice test driven development wherever I can). So these are the tests I created that validate this. Reviewed 3 of 3 files at r1. CHANGELOG.md, line 6 at r1 (raw file):
Can you add link to issue as per other changes. E.g. Modules/xCertificate/DSCResources/MSFT_xCertificateExport/MSFT_xCertificateExport.psm1, line 446 at r1 (raw file):
You'll need to use Tests/Integration/MSFT_xCertificateExport.Integration.Tests.ps1, line 151 at r1 (raw file):
This won't work because the Comments from Reviewable |
Hi @hackjammer - this one now has some merge conflicts in it due to the previously merged PR. Can you resolve? |
@hackjammer - are you still planning on working on this one? |
Labeling this abandoned so that someone else can continue this work. |
I'm picking this one up now, so will close this and reopen a new PR. |
Pull Request (PR) description
Fixed pfx import check when matchsource is enabled to use a securestring instead of attempting to use a credential object.
Also updated integration test to make this less likely to happen again (now just creating a plaintext password and a credential variable as used in the DSC resource itself).
This Pull Request (PR) fixes the following issues:
#116
This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)