Repository navigation
Tests - Delete the private keys of the certificates that the certificate tests create - #10864
Open
andreasjordan wants to merge 2 commits into
Open
andreasjordan wants to merge 2 commits into
andreasjordan wants to merge 2 commits into
Conversation
…ate tests create New-DbaComputerCertificate.Tests.ps1, Test-DbaNetworkCertificate.Tests.ps1 and Set-DbaNetworkCertificate.Tests.ps1 removed the certificates they create without the private keys that the creation made, so every run left key files under Crypto\RSA\MachineKeys and Crypto\Keys, on the computer that runs the tests and on the computer of the instance. Since #10854, Remove-DbaComputerCertificate -DeleteKey deletes a key on a remote computer as well. The certificates of the tests are now removed with -DeleteKey. Set-DbaNetworkCertificate.Tests.ps1 did not record the two self-signed certificates it applies, so only its loop over every suitable certificate of that computer removed them. They are recorded now, and the AfterAll removes the certificates of the test with their keys before that loop, which keeps removing without -DeleteKey because it can find certificates the test did not create. Lab set03, instances on SQL03, tests on another computer, new key files after one run on development a4dcc88: New-DbaComputerCertificate 6 here and 1 on SQL03, Test-DbaNetworkCertificate 3 and Set-DbaNetworkCertificate 4 on SQL03. With this commit none, and the three files pass (38, 11, 11) on Windows PowerShell 5.1 and on PowerShell 7.6. (do New-DbaComputerCertificate, Test-DbaNetworkCertificate, Set-DbaNetworkCertificate) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
andreasjordan
marked this pull request as ready for review
November 22, 2026 17:45
(do New-DbaComputerCertificate, Set-DbaNetworkCertificate, Test-DbaNetworkCertificate)
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Three certificate test files remove the certificates they create, but not the private keys that the creation made. Each run leaves key files under
Crypto\RSA\MachineKeysandCrypto\Keys, on the computer that runs the tests and on the computer of the instance. A CI runner goes away with them, but in a lab, or on a computer that runs the tests again and again, they pile up. Before #10854,Remove-DbaComputerCertificate -DeleteKeycould not delete a key on a remote computer at all; now it can.Change
New-DbaComputerCertificate.Tests.ps1: the six certificates of this computer and the one of the remote computer are removed with-DeleteKey.Test-DbaNetworkCertificate.Tests.ps1: the certificate of "Way Two - testing a specific certificate by thumbprint" and the two of "Way Two - private key types" (a Key Storage Provider key and a legacy CSP signature key) are removed with-DeleteKey.Set-DbaNetworkCertificate.Tests.ps1: the two self-signed certificates of "Creates a first/second self-signed certificate and applies it" were not recorded, so only the loop over every suitable certificate of that computer removed them, without their keys. They are recorded now like the other certificates of the test, and theAfterAllremoves all certificates of the test with-DeleteKeybefore that loop.Not changed:
Set-DbaNetworkCertificate.Tests.ps1over every suitable certificate of the computer ofInstanceRestartkeep removing without-DeleteKey. They can find certificates that the test did not create, and a deleted key cannot be restored.localhost.crtremove it without-DeleteKey; that file has no private key.Tests
Lab set03 (instances on SQL03, tests on another computer). New key files after one run of each file, counted on both computers:
developmenta4dcc88, this computerdevelopment, SQL03New-DbaComputerCertificate.Tests.ps1Test-DbaNetworkCertificate.Tests.ps1Set-DbaNetworkCertificate.Tests.ps1With this branch,
New-DbaComputerCertificate.Tests.ps138 passed,Test-DbaNetworkCertificate.Tests.ps111 passed andSet-DbaNetworkCertificate.Tests.ps111 passed, on Windows PowerShell 5.1 and on PowerShell 7.6, each without a new key file. The counts ofdevelopmentare from PowerShell 7.6, where all three files pass as well. On CI the instance runs on the runner itself, so both columns are one computer there.🤖 Generated with Claude Code