From 69ffb19ec0c23505ad93f6ebac048bc2f8ba8105 Mon Sep 17 00:00:00 2001 From: Tho Ho Date: Mon, 18 Nov 2024 16:34:41 +0800 Subject: [PATCH] More certs test MutualTLS --- .../CertificateLoaderMutualTlsTest.cs | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/test/NetLah.Extensions.Configuration.Test/CertificateLoaderMutualTlsTest.cs b/test/NetLah.Extensions.Configuration.Test/CertificateLoaderMutualTlsTest.cs index b2805ef..acdd31d 100644 --- a/test/NetLah.Extensions.Configuration.Test/CertificateLoaderMutualTlsTest.cs +++ b/test/NetLah.Extensions.Configuration.Test/CertificateLoaderMutualTlsTest.cs @@ -11,16 +11,49 @@ namespace NetLah.Extensions.Configuration.Test; public class CertificateLoaderMutualTlsTest { [Theory] - [InlineData("development.dummy_ecdh_p384-2021June.pfx")] - // [InlineData("development.dummy_ecdh_p521-2021June.pfx")] - [InlineData("development.dummy-rsa-2071June.pfx")] - [InlineData("development.dummy-rsa4096-2071June.pfx")] - public void Pkcs12AuthenticationTest(string filename) + [InlineData("development.dummy_ecdh_p384-2021June.pfx", false, true)] + [InlineData("development.dummy_ecdh_p384-2021June_nopass.pfx", false, false)] +#if NET5_0_OR_GREATER + [InlineData("development.dummy_ecdh_p521-2021June.pfx", false, true)] + [InlineData("development.dummy_ecdh_p521-2021June_nopass.pfx", false, false)] +#endif + [InlineData("development.dummy_ecdsa_p384-2024Nov_3ds-sha1.pfx", false, true)] + [InlineData("development.dummy_ecdsa_p384-2024Nov.pfx", false, true)] + [InlineData("development.dummy_ecdsa_p384-2024Nov_nopass.pfx", false, false)] +#if NET5_0_OR_GREATER + [InlineData("development.dummy_ecdsa_p521-2024Nov.pfx", false, true)] + [InlineData("development.dummy_ecdsa_p521-2024Nov_nopass.pfx", false, false)] +#endif + [InlineData("development.dummy-rsa-2071June.pfx", false, true)] + [InlineData("development.dummy-rsa-2071June_nopass.pfx", false, false)] + [InlineData("development.dummy-rsa4096-2071June.pfx", false, true)] + [InlineData("development.dummy-rsa4096-2071June_nopass.pfx", false, false)] +#if NET6_0_OR_GREATER + [InlineData("development.dummy_ecdh_p384-2021June.pem", true, true)] + [InlineData("development.dummy_ecdh_p384-2021June_noenc.pem", true, false)] + [InlineData("development.dummy_ecdh_p521-2021June.pem", true, true)] + [InlineData("development.dummy_ecdh_p521-2021June_noenc.pem", true, false)] + [InlineData("development.dummy_ecdsa_p384-2024Nov.pem", true, true)] + [InlineData("development.dummy_ecdsa_p384-2024Nov_noenc.pem", true, false)] + [InlineData("development.dummy_ecdsa_p521-2024Nov.pem", true, true)] + [InlineData("development.dummy_ecdsa_p521-2024Nov_noenc.pem", true, false)] + [InlineData("development.dummy-rsa-2071June.pem", true, true)] + [InlineData("development.dummy-rsa-2071June_noenc.pem", true, false)] + [InlineData("development.dummy-rsa4096-2071June.pem", true, true)] + [InlineData("development.dummy-rsa4096-2071June_noenc.pem", true, false)] +#endif + public void Pkcs12AuthenticationTest(string filename, bool isPem, bool requirePass) { // Cannot use empty password on MacOS with netcoreapp3.1 and before, only supported custom loader since net5.0 // https://github.com/dotnet/runtime/issues/23635#issuecomment-334028941 var filePath = Path.GetFullPath(Path.Combine("Properties", filename)); - var certificateConfig = new CertificateConfig { Path = filePath, Password = filename }; + var certificateConfig = new CertificateConfig + { + Path = filePath, + KeyPath = isPem ? filePath : null, + IsPem = isPem, + Password = requirePass ? filename : null, + }; var result = CertificateLoader.LoadCertificate(certificateConfig, "Test", requiredPrivateKey: true); Assert.NotNull(result);