NuGet / NuGetGallery

NuGet Gallery is a package repository that powers https://www.nuget.org. Use this repo for reporting NuGet.org issues.
https://www.nuget.org/
Apache License 2.0
1.55k stars 641 forks source link

Test: fix removal of test certificate from root store #10260

Closed dtivel closed 1 week ago

dtivel commented 1 week ago

Summary of the changes (in less than 80 characters):

This change ensures that test certificates are removed from the root store.

Addresses https://github.com/NuGet/NuGetGallery/issues/10259

Details

This change fixes a bug where the disposal of an X509Certificate2 instance causes the subsequent disposal (removal) of that certificate's trust because the TrustedTestCert<X509Certificate2> instance references the same certificate instance. When the X509Certificate2 instance is disposed, TrustedTestCert<X509Certificate2> cannot remove the certificate from the root store because its certificate reference is disposed.

The fix is to only dispose the TrustedTestCert<X509Certificate2> instance.