From f379952695f9e9ccdc68afcb987250832a983463 Mon Sep 17 00:00:00 2001 From: Markus Hartung Date: Sat, 18 Jun 2022 02:58:59 +0200 Subject: [PATCH 1/4] Skip AutoFixture for RSACryptoServiceProvider so we have running tests on linux --- .../Algorithms/RSAlgorithmFactoryTests.cs | 16 ++++++++-------- .../Algorithms/RSAlgorithmTests.cs | 9 ++++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs b/tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs index 37b122ca4..db10e5019 100644 --- a/tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs +++ b/tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs @@ -1,5 +1,4 @@ using System.Security.Cryptography; -using AutoFixture; using FluentAssertions; using JWT.Algorithms; using JWT.Builder; @@ -10,12 +9,12 @@ namespace JWT.Tests.Algorithms [TestClass] public class RSAlgorithmFactoryTests { - private static readonly Fixture _fixture = new Fixture(); + private static RSACryptoServiceProvider RSACryptoServiceProvider => new(); [TestMethod] public void Create_Should_Return_Instance_Of_RS256Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS256() { - var publicKey = _fixture.Create(); + var publicKey = RSACryptoServiceProvider; var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { @@ -33,7 +32,7 @@ public void Create_Should_Return_Instance_Of_RS256Algorithm_When_Algorithm_Speci [TestMethod] public void Create_Should_Return_Instance_Of_RS384Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS384() { - var publicKey = _fixture.Create(); + var publicKey = RSACryptoServiceProvider; var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { @@ -51,7 +50,7 @@ public void Create_Should_Return_Instance_Of_RS384Algorithm_When_Algorithm_Speci [TestMethod] public void Create_Should_Return_Instance_Of_RS512Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS512() { - var publicKey = _fixture.Create(); + var publicKey = RSACryptoServiceProvider; var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { @@ -69,7 +68,8 @@ public void Create_Should_Return_Instance_Of_RS512Algorithm_When_Algorithm_Speci [TestMethod] public void Create_Should_Return_Instance_Of_RS1024Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS1024() { - var publicKey = _fixture.Create(); + var publicKey = RSACryptoServiceProvider; + var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { @@ -87,7 +87,7 @@ public void Create_Should_Return_Instance_Of_RS1024Algorithm_When_Algorithm_Spec [TestMethod] public void Create_Should_Return_Instance_Of_RS2048Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS2048() { - var publicKey = _fixture.Create(); + var publicKey = RSACryptoServiceProvider; var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { @@ -105,7 +105,7 @@ public void Create_Should_Return_Instance_Of_RS2048Algorithm_When_Algorithm_Spec [TestMethod] public void Create_Should_Return_Instance_Of_RS4096Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS4096() { - var publicKey = _fixture.Create(); + var publicKey = RSACryptoServiceProvider; var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { diff --git a/tests/JWT.Tests.Common/Algorithms/RSAlgorithmTests.cs b/tests/JWT.Tests.Common/Algorithms/RSAlgorithmTests.cs index 10fce85ec..45c92c2d6 100644 --- a/tests/JWT.Tests.Common/Algorithms/RSAlgorithmTests.cs +++ b/tests/JWT.Tests.Common/Algorithms/RSAlgorithmTests.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; -using AutoFixture; using FluentAssertions; using JWT.Algorithms; using JWT.Tests.Models; @@ -13,13 +12,13 @@ namespace JWT.Tests.Algorithms [TestClass] public class RSAlgorithmTests { - private static readonly Fixture _fixture = new Fixture(); + private static RSACryptoServiceProvider RSACryptoServiceProvider => new(); [DynamicData(nameof(GetFactoryWithPublicPrivateKey), DynamicDataSourceType.Method)] [DataTestMethod] public void Ctor_Should_Throw_Exception_When_PublicKey_Is_Null(Func algFactory) { - var privateKey = _fixture.Create(); + var privateKey = RSACryptoServiceProvider; Action action = () => algFactory(null, privateKey); @@ -31,7 +30,7 @@ public void Ctor_Should_Throw_Exception_When_PublicKey_Is_Null(Func algFactory) { - var publicKey = _fixture.Create(); + var publicKey = RSACryptoServiceProvider; Action action = () => algFactory(publicKey, null); @@ -43,7 +42,7 @@ public void Ctor_Should_Throw_Exception_When_PrivateKey_Is_Null(Func algFactory) { - var publicKey = _fixture.Create(); + var publicKey = RSACryptoServiceProvider; var alg = algFactory(publicKey); var bytesToSign = Array.Empty(); From 26670f6956bf0c9c565dd9e3c0b7c7320057bc11 Mon Sep 17 00:00:00 2001 From: Alexander Batishchev Date: Mon, 20 Jun 2022 15:44:39 -0700 Subject: [PATCH 2/4] Update RSAlgorithmFactoryTests.cs --- .../Algorithms/RSAlgorithmFactoryTests.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs b/tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs index db10e5019..6f00987b9 100644 --- a/tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs +++ b/tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs @@ -9,12 +9,10 @@ namespace JWT.Tests.Algorithms [TestClass] public class RSAlgorithmFactoryTests { - private static RSACryptoServiceProvider RSACryptoServiceProvider => new(); - [TestMethod] public void Create_Should_Return_Instance_Of_RS256Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS256() { - var publicKey = RSACryptoServiceProvider; + var publicKey = new RSACryptoServiceProvider(); var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { @@ -50,7 +48,7 @@ public void Create_Should_Return_Instance_Of_RS384Algorithm_When_Algorithm_Speci [TestMethod] public void Create_Should_Return_Instance_Of_RS512Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS512() { - var publicKey = RSACryptoServiceProvider; + var publicKey = new RSACryptoServiceProvider(); var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { @@ -87,7 +85,7 @@ public void Create_Should_Return_Instance_Of_RS1024Algorithm_When_Algorithm_Spec [TestMethod] public void Create_Should_Return_Instance_Of_RS2048Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS2048() { - var publicKey = RSACryptoServiceProvider; + var publicKey = new RSACryptoServiceProvider(); var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { @@ -105,7 +103,7 @@ public void Create_Should_Return_Instance_Of_RS2048Algorithm_When_Algorithm_Spec [TestMethod] public void Create_Should_Return_Instance_Of_RS4096Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS4096() { - var publicKey = RSACryptoServiceProvider; + var publicKey = new RSACryptoServiceProvider(); var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { From 623a6ad0c21abc7bc9518c20bd480718a898cf8a Mon Sep 17 00:00:00 2001 From: Alexander Batishchev Date: Mon, 20 Jun 2022 15:45:27 -0700 Subject: [PATCH 3/4] Update RSAlgorithmTests.cs --- tests/JWT.Tests.Common/Algorithms/RSAlgorithmTests.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/JWT.Tests.Common/Algorithms/RSAlgorithmTests.cs b/tests/JWT.Tests.Common/Algorithms/RSAlgorithmTests.cs index 45c92c2d6..440794320 100644 --- a/tests/JWT.Tests.Common/Algorithms/RSAlgorithmTests.cs +++ b/tests/JWT.Tests.Common/Algorithms/RSAlgorithmTests.cs @@ -12,13 +12,11 @@ namespace JWT.Tests.Algorithms [TestClass] public class RSAlgorithmTests { - private static RSACryptoServiceProvider RSACryptoServiceProvider => new(); - [DynamicData(nameof(GetFactoryWithPublicPrivateKey), DynamicDataSourceType.Method)] [DataTestMethod] public void Ctor_Should_Throw_Exception_When_PublicKey_Is_Null(Func algFactory) { - var privateKey = RSACryptoServiceProvider; + var privateKey = new RSACryptoServiceProvider(); Action action = () => algFactory(null, privateKey); @@ -30,7 +28,7 @@ public void Ctor_Should_Throw_Exception_When_PublicKey_Is_Null(Func algFactory) { - var publicKey = RSACryptoServiceProvider; + var publicKey = new RSACryptoServiceProvider(); Action action = () => algFactory(publicKey, null); @@ -42,7 +40,7 @@ public void Ctor_Should_Throw_Exception_When_PrivateKey_Is_Null(Func algFactory) { - var publicKey = RSACryptoServiceProvider; + var publicKey = new RSACryptoServiceProvider(); var alg = algFactory(publicKey); var bytesToSign = Array.Empty(); From ce5ef4e1a3e00169230a8c241d0c8bce155b4272 Mon Sep 17 00:00:00 2001 From: Markus Hartung Date: Tue, 21 Jun 2022 01:12:35 +0200 Subject: [PATCH 4/4] Buildfix --- tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs b/tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs index 6f00987b9..9dbdeec7e 100644 --- a/tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs +++ b/tests/JWT.Tests.Common/Algorithms/RSAlgorithmFactoryTests.cs @@ -30,7 +30,7 @@ public void Create_Should_Return_Instance_Of_RS256Algorithm_When_Algorithm_Speci [TestMethod] public void Create_Should_Return_Instance_Of_RS384Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS384() { - var publicKey = RSACryptoServiceProvider; + var publicKey = new RSACryptoServiceProvider(); var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext { @@ -66,7 +66,7 @@ public void Create_Should_Return_Instance_Of_RS512Algorithm_When_Algorithm_Speci [TestMethod] public void Create_Should_Return_Instance_Of_RS1024Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_RS1024() { - var publicKey = RSACryptoServiceProvider; + var publicKey = new RSACryptoServiceProvider(); var factory = new RSAlgorithmFactory(publicKey); var context = new JwtDecoderContext