Update some CertificateRequest tests to behave correctly on systems lacking SHA-1
authorTom Deseyn <tom.deseyn@gmail.com>
Thu, 2 Feb 2023 18:10:56 +0000 (19:10 +0100)
committerGitHub <noreply@github.com>
Thu, 2 Feb 2023 18:10:56 +0000 (10:10 -0800)
src/libraries/System.Security.Cryptography/tests/X509Certificates/CertificateCreation/CertificateRequestLoadTests.cs

index 70738ac..b29429f 100644 (file)
@@ -341,7 +341,15 @@ Y2FsaG9zdDANBgkqhkiG9w0BAQsFAAMCB4A=
 
                 if (hashAlgorithm == "SHA1")
                 {
-                    pkcs10 = first.CreateSigningRequest(new RSASha1Pkcs1SignatureGenerator(key));
+                    if (SignatureSupport.SupportsX509Sha1Signatures)
+                    {
+                        pkcs10 = first.CreateSigningRequest(new RSASha1Pkcs1SignatureGenerator(key));
+                    }
+                    else
+                    {
+                        Assert.ThrowsAny<CryptographicException>(() => first.CreateSigningRequest(new RSASha1Pkcs1SignatureGenerator(key)));
+                        return;
+                    }
                 }
                 else
                 {
@@ -386,7 +394,15 @@ Y2FsaG9zdDANBgkqhkiG9w0BAQsFAAMCB4A=
 
                 if (hashAlgorithm == "SHA1")
                 {
-                    pkcs10 = first.CreateSigningRequest(new RSASha1PssSignatureGenerator(key));
+                    if (SignatureSupport.SupportsX509Sha1Signatures)
+                    {
+                        pkcs10 = first.CreateSigningRequest(new RSASha1PssSignatureGenerator(key));
+                    }
+                    else
+                    {
+                        Assert.ThrowsAny<CryptographicException>(() => first.CreateSigningRequest(new RSASha1PssSignatureGenerator(key)));
+                        return;
+                    }
                 }
                 else
                 {