Skip to content

Tests - Delete the private keys of the certificates that the certificate tests create - #10864

Open
andreasjordan wants to merge 2 commits into
developmentfrom
tests-certificate-delete-key
Open

andreasjordan wants to merge 2 commits into
developmentfrom
tests-certificate-delete-key

Conversation

@andreasjordan

Copy link
Copy Markdown
Collaborator

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\MachineKeys and Crypto\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 -DeleteKey could 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 the AfterAll removes all certificates of the test with -DeleteKey before that loop.

Not changed:

Tests

Lab set03 (instances on SQL03, tests on another computer). New key files after one run of each file, counted on both computers:

Test file development a4dcc88, this computer development, SQL03 this branch, this computer this branch, SQL03
New-DbaComputerCertificate.Tests.ps1 6 (5 CSP, 1 KSP) 1 (KSP) 0 0
Test-DbaNetworkCertificate.Tests.ps1 0 3 (2 CSP, 1 KSP) 0 0
Set-DbaNetworkCertificate.Tests.ps1 0 4 (3 CSP, 1 KSP) 0 0

With this branch, New-DbaComputerCertificate.Tests.ps1 38 passed, Test-DbaNetworkCertificate.Tests.ps1 11 passed and Set-DbaNetworkCertificate.Tests.ps1 11 passed, on Windows PowerShell 5.1 and on PowerShell 7.6, each without a new key file. The counts of development are 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

…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>
(do New-DbaComputerCertificate, Set-DbaNetworkCertificate, Test-DbaNetworkCertificate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants