summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander Scheel <alexander.scheel@keyfactor.com>2024-02-12 12:37:42 -0500
committerAlexander Scheel <alexander.scheel@keyfactor.com>2024-02-12 12:38:16 -0500
commit5e0509e00ee714824f0b859a8be2b6da469a3d0a (patch)
tree1b88629b12d5ac8fbeb5e1c44a8d4d9131150b37
parentVerifying read of MS PKCS#7 SignedData (diff)
downloadBouncyCastle.NET-ed25519-5e0509e00ee714824f0b859a8be2b6da469a3d0a.tar.xz
Correctly disable tests on Linux
The SP800-38G tests fail to execute on Linux, due to the inability to
set environment variables documented in a dotnet runtime issue.

This uses RuntimeInformation to conditionally exclude the test from
being run on Linux.

Switch from SupportedOSPlatform to RuntimeInformation.IsOSPlatform for TestRsaInterop

Guard this by a NET 6.0 requirement so that it doesn't affect old
Windows-only .NET framework versions.

Note: this only appears to fail on Linux when building from the CLI:

> dotnet test -v:normal -l \"console;verbosity=detailed\"

Building from an IDE (e.g., Rider) does not seem to be affected.

Signed-off-by: Alexander Scheel <alexander.scheel@keyfactor.com>
-rw-r--r--crypto/test/src/crypto/test/SP80038GTest.cs34
-rw-r--r--crypto/test/src/security/test/TestDotNetUtil.cs17
2 files changed, 37 insertions, 14 deletions
diff --git a/crypto/test/src/crypto/test/SP80038GTest.cs b/crypto/test/src/crypto/test/SP80038GTest.cs
index c1eac2a24..13f67e485 100644
--- a/crypto/test/src/crypto/test/SP80038GTest.cs
+++ b/crypto/test/src/crypto/test/SP80038GTest.cs
@@ -1,5 +1,9 @@
 using System;
 
+#if NET6_0_OR_GREATER
+using System.Runtime.InteropServices;
+#endif
+
 using NUnit.Framework;
 
 using Org.BouncyCastle.Crypto.Utilities;
@@ -146,7 +150,7 @@ namespace Org.BouncyCastle.Crypto.Tests
             try
             {
                 fpeEngine.ProcessBlock(plainText, 0, plainText.Length, plainText, 0);
-                Fail("no exception");
+                Fail("no exception - ImplTestFF1 first");
             }
             catch (ArgumentException e)
             {
@@ -156,7 +160,7 @@ namespace Org.BouncyCastle.Crypto.Tests
             try
             {
                 fpeEngine.ProcessBlock(new byte[] { 1 }, 0, 1, plainText, 0);
-                Fail("no exception");
+                Fail("no exception - ImplTestFF1 second");
             }
             catch (ArgumentException e)
             {
@@ -217,7 +221,7 @@ namespace Org.BouncyCastle.Crypto.Tests
             try
             {
                 fpeEngine.ProcessBlock(plainText, 0, plainText.Length, plainText, 0);
-                Fail("no exception");
+                Fail("no exception - ImplTestFF3_1 first");
             }
             catch (ArgumentException e)
             {
@@ -228,7 +232,7 @@ namespace Org.BouncyCastle.Crypto.Tests
             {
                 fpeEngine.Init(true, new FpeParameters(new KeyParameter(key), 24, Hex.Decode("beef")));
 
-                Fail("no exception");
+                Fail("no exception - ImplTestFF3_1 second");
             }
             catch (ArgumentException e)
             {
@@ -277,7 +281,7 @@ namespace Org.BouncyCastle.Crypto.Tests
             try
             {
                 ImplTestFF1();
-                Fail("no exception");
+                Fail("no exception - ImplTestDisable first");
             }
             catch (InvalidOperationException e)
             {
@@ -287,7 +291,7 @@ namespace Org.BouncyCastle.Crypto.Tests
             try
             {
                 ImplTestFF3_1();
-                Fail("no exception");
+                Fail("no exception - ImplTestDisable second");
             }
             catch (InvalidOperationException e)
             {
@@ -299,7 +303,7 @@ namespace Org.BouncyCastle.Crypto.Tests
             try
             {
                 ImplTestFF1();
-                Fail("no exception");
+                Fail("no exception - ImplTestDisable third");
             }
             catch (InvalidOperationException e)
             {
@@ -390,7 +394,7 @@ namespace Org.BouncyCastle.Crypto.Tests
                 fpeEngine.Init(true, new FpeParameters(new KeyParameter(key), alphabetMapper.Radix, tweak));
 
                 ImplProcess(fpeEngine, new byte[] { 1, 2, 3 });
-                Fail("no exception");
+                Fail("no exception - ImplTestFF1Bounds first");
             }
             catch (ArgumentException e)
             {
@@ -405,7 +409,7 @@ namespace Org.BouncyCastle.Crypto.Tests
                             alphabetMapper.Radix, tweak));
 
                 ImplProcess(fpeEngine, new byte[] { 1, 2, 3 });
-                Fail("no exception");
+                Fail("no exception - ImplTestFF1Bounds second");
             }
             catch (ArgumentException e)
             {
@@ -522,6 +526,11 @@ namespace Org.BouncyCastle.Crypto.Tests
             IsTrue("no match", Arrays.AreEqual(input, decrypted));
         }
 
+        // On Linux platforms, ImplTestDisable requires setting
+        // environment variables, which isn't fully supported by
+        // dotnet due to libc's lack of locking semantics, which
+        // can result in race conditions reading and writing
+        // environment variables.
         public override void PerformTest()
         {
             ImplTestFF1();
@@ -532,7 +541,12 @@ namespace Org.BouncyCastle.Crypto.Tests
             ImplTestFF3_1w();
             ImplTestFF3_1_255();
             ImplTestFF3_1Bounds();
-            ImplTestDisable();
+#if NET6_0_OR_GREATER
+            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+            {
+                ImplTestDisable();
+            }
+#endif
             ImplTestUtility();
         }
 
diff --git a/crypto/test/src/security/test/TestDotNetUtil.cs b/crypto/test/src/security/test/TestDotNetUtil.cs
index 5d0177ead..77a975c19 100644
--- a/crypto/test/src/security/test/TestDotNetUtil.cs
+++ b/crypto/test/src/security/test/TestDotNetUtil.cs
@@ -1,8 +1,14 @@
 using System;
 using System.Collections.Generic;
+
 #if NET5_0_OR_GREATER
 using System.Runtime.Versioning;
 #endif
+
+#if NET6_0_OR_GREATER
+using System.Runtime.InteropServices;
+#endif
+
 using System.Security.Cryptography;
 using SystemX509 = System.Security.Cryptography.X509Certificates;
 
@@ -52,13 +58,16 @@ namespace Org.BouncyCastle.Security.Tests
         }
 #endif
 
-//#if NET5_0_OR_GREATER
-#if NET6_0_OR_GREATER
-        [SupportedOSPlatform("windows")]
-#endif
         [Test]
 		public void TestRsaInterop()
 		{
+#if NET6_0_OR_GREATER
+			if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+			{
+				return;
+			}
+#endif
+
 			for (int i = 0; i < 10; ++i)
 			{
 				RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(512);