Skip to content

Commit a56efef

Browse files
authored
Move RSA 16384 tests to outerloop.
These tests take a significant amount of time on Linux due to primality tests of RSA 16384.
1 parent d9ed370 commit a56efef

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/ImportExport.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ namespace System.Security.Cryptography.Rsa.Tests
1010
[SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")]
1111
public partial class ImportExport
1212
{
13-
public static bool Supports16384 { get; } = TestRsa16384();
13+
private static readonly Lazy<bool> s_supports16384 = new Lazy<bool>(TestRsa16384);
14+
public static bool Supports16384 => s_supports16384.Value;
1415

1516
[Fact]
1617
public static void ExportAutoKey()

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/RSAKeyFileTests.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Security.Cryptography.Encryption.RC2.Tests;
55
using System.Text;
6+
using Microsoft.DotNet.XUnitExtensions;
67
using Test.Cryptography;
78
using Xunit;
89

@@ -122,9 +123,17 @@ public static void ReadWriteDiminishedDPPrivatePkcs1()
122123
TestData.DiminishedDPParameters);
123124
}
124125

125-
[ConditionalFact(typeof(ImportExport), nameof(ImportExport.Supports16384))]
126+
[ConditionalFact]
127+
[OuterLoop("RSA 16384 takes considerable time.")]
126128
public static void ReadWritePublicPkcs1()
127129
{
130+
// Do not move this to the [ConditionalFact], otherwise the platform will check if RSA 16384 is supported
131+
// during test discovery for innerloop, and the check itself is expensive.
132+
if (!ImportExport.Supports16384)
133+
{
134+
throw new SkipTestException("Platform does not support RSA 16384.");
135+
}
136+
128137
ReadWriteBase64PublicPkcs1(
129138
@"
130139
MIIICgKCCAEAmyxwX6kQNx+LSMao1StC1p5rKCEwcBjzI136An3B/BjthgezAOuu
@@ -198,9 +207,18 @@ public static void ReadWriteSubjectPublicKeyInfo_DiminishedDPKey()
198207
TestData.DiminishedDPParameters);
199208
}
200209

201-
[ConditionalFact(typeof(ImportExport), nameof(ImportExport.Supports16384))]
210+
211+
[ConditionalFact]
212+
[OuterLoop("RSA 16384 takes considerable time.")]
202213
public static void ReadWriteRsa16384SubjectPublicKeyInfo()
203214
{
215+
// Do not move this to the [ConditionalFact], otherwise the platform will check if RSA 16384 is supported
216+
// during test discovery for innerloop, and the check itself is expensive.
217+
if (!ImportExport.Supports16384)
218+
{
219+
throw new SkipTestException("Platform does not support RSA 16384.");
220+
}
221+
204222
ReadWriteBase64SubjectPublicKeyInfo(
205223
@"
206224
MIIIIjANBgkqhkiG9w0BAQEFAAOCCA8AMIIICgKCCAEAmyxwX6kQNx+LSMao1StC
@@ -250,9 +268,17 @@ public static void ReadWriteRsa16384SubjectPublicKeyInfo()
250268
TestData.RSA16384Params);
251269
}
252270

253-
[ConditionalFact(typeof(ImportExport), nameof(ImportExport.Supports16384))]
271+
[ConditionalFact]
272+
[OuterLoop("RSA 16384 takes considerable time.")]
254273
public static void ReadWrite16384Pkcs8()
255274
{
275+
// Do not move this to the [ConditionalFact], otherwise the platform will check if RSA 16384 is supported
276+
// during test discovery for innerloop, and the check itself is expensive.
277+
if (!ImportExport.Supports16384)
278+
{
279+
throw new SkipTestException("Platform does not support RSA 16384");
280+
}
281+
256282
ReadWriteBase64Pkcs8(
257283
@"
258284
MIIkQgIBADANBgkqhkiG9w0BAQEFAASCJCwwgiQoAgEAAoIIAQCbLHBfqRA3H4tI
@@ -525,9 +551,17 @@ public static void ReadEncryptedRsa1032()
525551
TestData.RSA1032Parameters);
526552
}
527553

528-
[ConditionalFact(typeof(ImportExport), nameof(ImportExport.Supports16384))]
554+
[ConditionalFact]
555+
[OuterLoop("RSA 16384 takes considerable time.")]
529556
public static void ReadEncryptedRsa16384()
530557
{
558+
// Do not move this to the [ConditionalFact], otherwise the platform will check if RSA 16384 is supported
559+
// during test discovery for innerloop, and the check itself is expensive.
560+
if (!ImportExport.Supports16384)
561+
{
562+
throw new SkipTestException("Platform does not support RSA 16384");
563+
}
564+
531565
// PBES2: PBKDF2 + des (single DES, not 3DES).
532566
const string base64 = @"
533567
MIIkizA9BgkqhkiG9w0BBQ0wMDAbBgkqhkiG9w0BBQwwDgQI63upT8JPNNcCAggA

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/RSAXml.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Collections.Generic;
55
using System.Xml.Linq;
6+
using Microsoft.DotNet.XUnitExtensions;
67
using Xunit;
78

89
namespace System.Security.Cryptography.Rsa.Tests
@@ -76,9 +77,17 @@ public static void TestRead1032Parameters_Private()
7677
TestData.RSA1032Parameters);
7778
}
7879

79-
[ConditionalFact(typeof(ImportExport), nameof(ImportExport.Supports16384))]
80+
[ConditionalFact]
81+
[OuterLoop("RSA 16384 takes considerable time.")]
8082
public static void TestRead16384Parameters_Public()
8183
{
84+
// Do not move this to the [ConditionalFact], otherwise the platform will check if RSA 16384 is supported
85+
// during test discovery for innerloop, and the check itself is expensive.
86+
if (!ImportExport.Supports16384)
87+
{
88+
throw new SkipTestException("Platform does not support RSA 16384");
89+
}
90+
8291
RSAParameters expectedParameters = ImportExport.MakePublic(TestData.RSA16384Params);
8392

8493
// Bonus trait of this XML: the Modulus and Exponent parameters
@@ -157,9 +166,16 @@ iC2wXFMDafnWp1lxXiGcVVu9dE2LeglCgnMUps9QlJD0aXaJHYi2VDQ3zFdMvn8A imlqKtZGdGf9
157166
expectedParameters);
158167
}
159168

160-
[ConditionalFact(typeof(ImportExport), nameof(ImportExport.Supports16384))]
169+
[ConditionalFact]
161170
public static void TestRead16384Parameters_Private()
162171
{
172+
// Do not move this to the [ConditionalFact], otherwise the platform will check if RSA 16384 is supported
173+
// during test discovery for innerloop, and the check itself is expensive.
174+
if (!ImportExport.Supports16384)
175+
{
176+
throw new SkipTestException("Platform does not support RSA 16384");
177+
}
178+
163179
// Bonus trait of this XML: the D parameter is not in
164180
// canonical order.
165181
TestReadXml(
@@ -634,11 +650,19 @@ public static void TestWrite2048Parameters(bool includePrivateParameters)
634650
));
635651
}
636652

637-
[ConditionalTheory(typeof(ImportExport), nameof(ImportExport.Supports16384))]
653+
[ConditionalTheory]
638654
[InlineData(true)]
639655
[InlineData(false)]
656+
[OuterLoop("RSA 16384 takes considerable time for primality tests.")]
640657
public static void TestWrite16384Parameters(bool includePrivateParameters)
641658
{
659+
// Do not move this to the [ConditionalFact], otherwise the platform will check if RSA 16384 is supported
660+
// during test discovery for innerloop, and the check itself is expensive.
661+
if (!ImportExport.Supports16384)
662+
{
663+
throw new SkipTestException("Platform does not support RSA 16384");
664+
}
665+
642666
TestWriteXml(
643667
TestData.RSA16384Params,
644668
includePrivateParameters,

0 commit comments

Comments
 (0)