dotnet / dotnet/runtime

Restructure RSA tests to use generic fixtures

Open
#124,099 1 comment 1 reaction 2 assignees Claimed by @bartonjs View on GitHub
area-System.Security
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

The RSA tests should be restructured to facilitate test sharing across the multiple implementations but also to allow the tests to move into one test assembly (in a followup change).

Directives:
* Keep the number of file additions and removals low, and avoid unnecessary edits to existing files (clean diff, purposeful changes only)
* No test coverage loss.
* Only test code may change.

Approach:
* Any RSA test that is using RSAFactory should change from calling RSAFactory as a static to invoking a new static field, s_provider.
* Any methods on RSAFactory that are not on IRSAProvider should be moved to the new RSAProvider class, implemented appropriately.
* For any class that has a test method that needs to change away from using RSAFactory:
* Make the class generic, for example, `ImportExport` should become `ImportExport : where TProvider : IRSAProvider, new()`
* Introduce a new field, `private static readonly TProvider s_provider = new TProvider();`
* ConditionalFact or ConditionalMethod targets that defer to RSAFactory will require a new static property in the current class, and that static property should be initialized by invoking the correct member off of s_provider.
* In the file that defines implementing types of RSAProvider, declare a class directly in the main file namespace named appropriately for the provider being tested, for example, in `RSACryptoServiceProviderProvider.cs`, add `public class RSACryptoServiceProviderImportExport : ImportExport;`. These new classes don't need a body, as the whole purpose is to use methods from the inherited class.
* The RSAFactory static class will be unused at the end of this process, delete it. If the file is empty, delete the file. If the file it is in still has useful content but is simply misnamed, leave the file name as-is.
* If you need inspiration, look at HmacTests.cs, IRSAProvider will function similar to IHmacTrait, though we can use the static s_provider field in lieu of statics in interfaces.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.