Skip to content
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

Tests | Remove hardcoded certificates from functional tests #3034

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

edwardneal
Copy link
Contributor

@edwardneal edwardneal commented Nov 24, 2024

This is a pre-requisite for #3014. I'm splitting this prereq in half though, it's already a little unwieldy to review.

There are a variety of hardcoded certificates (most with private keys, one without) in the test code. This PR lays out some simple enough infrastructure which helps to replace them, then replaces all the references I can see in the functional tests.

Key features here:

  • TDS.Servers and TDS.EndPoint have had some minor rework. I removed the hardcoded default certificate, it'll now throw an exception if one is missing and we try to use SSL connections.
  • Added a CertificateFixtureBase class to the TestUtilities project. This base class provides the infrastructure needed to generate an ad-hoc certificate. It'll use the CertificateRequest class in .NET Core, and it has to run PowerShell in .NET Framework (as per the current manual tests.) It also cleans up the certificates it leaves behind.
  • Added a ColumnEncryptionCertificateFixture class to TestUtilities. This is derived from the above, and it generates a set of basic certificates, adding them to the appropriate store.
  • Reworked the SqlColumnEncryptionCertificateStoreProviderShould tests, removing three hardcoded certificates (with private keys.) Switched this over to the above fixture class.
  • Started to work on ExceptionsCertStore to remove its references to Utility.CreateCertificate, then realised that both of its tests were special cases of the above test class and removed them. In the process, I was also able to enable the CertificateWithNoPrivateKey test on .NET Core.
  • Switched ExceptionsAlgorithmErrors to the ColumnEncryptionCertificateFixture fixture class, removing the remaining reference to Utility.CreateCertificate.
  • Removed Utility.CreateCertificate (which in reality, just returned the same certificate every time.)

There are other hardcoded credentials in the manual tests, but this is already a large PR at +428/-407.

Clients requiring a server certificate will need to generate their own.
* TestUtilities no longer targets netstandard2.0, so is now able to use CertificateRequest.
* Added a reference from Tests to TestUtilities.
* Added a base CertificateFixtureBase class. This provides basic infrastructure to generate a certificate and add it to a store (with cleanup on disposal.)
Removed multiple hardcoded references to three certificates.
Also removed references to TestCertificate12.
This test class covered similar ground to the existing SqlColumnEncryptionCertificateStoreProviderShould test class.
Removes the last reference to Utility.CreateCertificate, replacing it with one which is generated dynamically.
Accordingly, removes Utility.CreateCertificate.
Copy link

codecov bot commented Nov 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.61%. Comparing base (22ac587) to head (1ff8f1c).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3034      +/-   ##
==========================================
- Coverage   72.61%   72.61%   -0.01%     
==========================================
  Files         285      285              
  Lines       59162    59162              
==========================================
- Hits        42963    42958       -5     
- Misses      16199    16204       +5     
Flag Coverage Δ
addons 92.58% <ø> (ø)
netcore 75.42% <ø> (-0.01%) ⬇️
netfx 71.02% <ø> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mdaigle mdaigle added ➕ Code Health Issues/PRs that are targeted to source code quality improvements. Area\Tests Issues that are targeted to tests or test projects and removed ➕ Code Health Issues/PRs that are targeted to source code quality improvements. labels Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area\Tests Issues that are targeted to tests or test projects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants