From 69d721940be72e9410597000fcf24e4c016a5a60 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 12 Jan 2024 14:06:33 -0800 Subject: [PATCH] Move RSA 16384 tests to outerloop. (#95310) These tests take a significant amount of time on Linux due to primality tests of RSA 16384. Co-authored-by: Kevin Jones --- .../RSA/ImportExport.cs | 3 +- .../RSA/RSAKeyFileTests.cs | 42 +++++++++++++++++-- .../AlgorithmImplementations/RSA/RSAXml.cs | 30 +++++++++++-- 3 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/ImportExport.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/ImportExport.cs index 4378f4590f19d..0c196f1c0290a 100644 --- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/ImportExport.cs +++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/ImportExport.cs @@ -10,7 +10,8 @@ namespace System.Security.Cryptography.Rsa.Tests [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] public partial class ImportExport { - public static bool Supports16384 { get; } = TestRsa16384(); + private static readonly Lazy s_supports16384 = new Lazy(TestRsa16384); + public static bool Supports16384 => s_supports16384.Value; [Fact] public static void ExportAutoKey() diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/RSAKeyFileTests.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/RSAKeyFileTests.cs index daa175dda47a9..65f73cdef4351 100644 --- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/RSAKeyFileTests.cs +++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/RSAKeyFileTests.cs @@ -3,6 +3,7 @@ using System.Security.Cryptography.Encryption.RC2.Tests; using System.Text; +using Microsoft.DotNet.XUnitExtensions; using Test.Cryptography; using Xunit; @@ -122,9 +123,17 @@ public static void ReadWriteDiminishedDPPrivatePkcs1() TestData.DiminishedDPParameters); } - [ConditionalFact(typeof(ImportExport), nameof(ImportExport.Supports16384))] + [ConditionalFact] + [OuterLoop("RSA 16384 takes considerable time.")] public static void ReadWritePublicPkcs1() { + // Do not move this to the [ConditionalFact], otherwise the platform will check if RSA 16384 is supported + // during test discovery for innerloop, and the check itself is expensive. + if (!ImportExport.Supports16384) + { + throw new SkipTestException("Platform does not support RSA 16384."); + } + ReadWriteBase64PublicPkcs1( @" MIIICgKCCAEAmyxwX6kQNx+LSMao1StC1p5rKCEwcBjzI136An3B/BjthgezAOuu @@ -198,9 +207,18 @@ public static void ReadWriteSubjectPublicKeyInfo_DiminishedDPKey() TestData.DiminishedDPParameters); } - [ConditionalFact(typeof(ImportExport), nameof(ImportExport.Supports16384))] + + [ConditionalFact] + [OuterLoop("RSA 16384 takes considerable time.")] public static void ReadWriteRsa16384SubjectPublicKeyInfo() { + // Do not move this to the [ConditionalFact], otherwise the platform will check if RSA 16384 is supported + // during test discovery for innerloop, and the check itself is expensive. + if (!ImportExport.Supports16384) + { + throw new SkipTestException("Platform does not support RSA 16384."); + } + ReadWriteBase64SubjectPublicKeyInfo( @" MIIIIjANBgkqhkiG9w0BAQEFAAOCCA8AMIIICgKCCAEAmyxwX6kQNx+LSMao1StC @@ -250,9 +268,17 @@ public static void ReadWriteRsa16384SubjectPublicKeyInfo() TestData.RSA16384Params); } - [ConditionalFact(typeof(ImportExport), nameof(ImportExport.Supports16384))] + [ConditionalFact] + [OuterLoop("RSA 16384 takes considerable time.")] public static void ReadWrite16384Pkcs8() { + // Do not move this to the [ConditionalFact], otherwise the platform will check if RSA 16384 is supported + // during test discovery for innerloop, and the check itself is expensive. + if (!ImportExport.Supports16384) + { + throw new SkipTestException("Platform does not support RSA 16384"); + } + ReadWriteBase64Pkcs8( @" MIIkQgIBADANBgkqhkiG9w0BAQEFAASCJCwwgiQoAgEAAoIIAQCbLHBfqRA3H4tI @@ -525,9 +551,17 @@ public static void ReadEncryptedRsa1032() TestData.RSA1032Parameters); } - [ConditionalFact(typeof(ImportExport), nameof(ImportExport.Supports16384))] + [ConditionalFact] + [OuterLoop("RSA 16384 takes considerable time.")] public static void ReadEncryptedRsa16384() { + // Do not move this to the [ConditionalFact], otherwise the platform will check if RSA 16384 is supported + // during test discovery for innerloop, and the check itself is expensive. + if (!ImportExport.Supports16384) + { + throw new SkipTestException("Platform does not support RSA 16384"); + } + // PBES2: PBKDF2 + des (single DES, not 3DES). const string base64 = @" MIIkizA9BgkqhkiG9w0BBQ0wMDAbBgkqhkiG9w0BBQwwDgQI63upT8JPNNcCAggA diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/RSAXml.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/RSAXml.cs index 666f9bea3c409..eb354216e77fc 100644 --- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/RSAXml.cs +++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/RSAXml.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Xml.Linq; +using Microsoft.DotNet.XUnitExtensions; using Xunit; namespace System.Security.Cryptography.Rsa.Tests @@ -76,9 +77,17 @@ public static void TestRead1032Parameters_Private() TestData.RSA1032Parameters); } - [ConditionalFact(typeof(ImportExport), nameof(ImportExport.Supports16384))] + [ConditionalFact] + [OuterLoop("RSA 16384 takes considerable time.")] public static void TestRead16384Parameters_Public() { + // Do not move this to the [ConditionalFact], otherwise the platform will check if RSA 16384 is supported + // during test discovery for innerloop, and the check itself is expensive. + if (!ImportExport.Supports16384) + { + throw new SkipTestException("Platform does not support RSA 16384"); + } + RSAParameters expectedParameters = ImportExport.MakePublic(TestData.RSA16384Params); // Bonus trait of this XML: the Modulus and Exponent parameters @@ -157,9 +166,16 @@ iC2wXFMDafnWp1lxXiGcVVu9dE2LeglCgnMUps9QlJD0aXaJHYi2VDQ3zFdMvn8A imlqKtZGdGf9 expectedParameters); } - [ConditionalFact(typeof(ImportExport), nameof(ImportExport.Supports16384))] + [ConditionalFact] public static void TestRead16384Parameters_Private() { + // Do not move this to the [ConditionalFact], otherwise the platform will check if RSA 16384 is supported + // during test discovery for innerloop, and the check itself is expensive. + if (!ImportExport.Supports16384) + { + throw new SkipTestException("Platform does not support RSA 16384"); + } + // Bonus trait of this XML: the D parameter is not in // canonical order. TestReadXml( @@ -634,11 +650,19 @@ public static void TestWrite2048Parameters(bool includePrivateParameters) )); } - [ConditionalTheory(typeof(ImportExport), nameof(ImportExport.Supports16384))] + [ConditionalTheory] [InlineData(true)] [InlineData(false)] + [OuterLoop("RSA 16384 takes considerable time for primality tests.")] public static void TestWrite16384Parameters(bool includePrivateParameters) { + // Do not move this to the [ConditionalFact], otherwise the platform will check if RSA 16384 is supported + // during test discovery for innerloop, and the check itself is expensive. + if (!ImportExport.Supports16384) + { + throw new SkipTestException("Platform does not support RSA 16384"); + } + TestWriteXml( TestData.RSA16384Params, includePrivateParameters,