From 79ac65b0b3e100374c78de95a0e8d8fe215cb399 Mon Sep 17 00:00:00 2001 From: Markus Hartung Date: Wed, 25 Jan 2023 19:20:00 +0100 Subject: [PATCH] Added unit tests for .NET 7 (#463) * Added tests for .NET 7 * Added .NET 7 to build pipeline Co-authored-by: Markus Hartung Co-authored-by: Alexander Batishchev --- .pipelines/build.yml | 11 +++++++++-- JWT.sln | 6 ++++++ src/JWT/Algorithms/ECDSAAlgorithm.cs | 2 +- src/JWT/Algorithms/ECDSAAlgorithmFactory.cs | 6 +++--- src/JWT/Algorithms/ES256Algorithm.cs | 2 +- src/JWT/Algorithms/ES384Algorithm.cs | 2 +- src/JWT/Algorithms/ES512Algorithm.cs | 2 +- src/JWT/Properties/AssemblyInfo.cs | 1 + .../Algorithms/ECDSAAlgorithmFactoryTests.cs | 2 +- .../Algorithms/ECDSAAlgorithmTests.cs | 2 +- .../Builder/JwtBuilderEncodeTests.cs | 4 ++-- tests/JWT.Tests.Common/JwtBuilderEndToEndTests.cs | 2 +- tests/JWT.Tests.Net60/TargetFrameworkTests.cs | 4 ++-- tests/JWT.Tests.Net70/JWT.Tests.Net70.csproj | 15 +++++++++++++++ 14 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 tests/JWT.Tests.Net70/JWT.Tests.Net70.csproj diff --git a/.pipelines/build.yml b/.pipelines/build.yml index e403f77b8..2a4c1a7e8 100644 --- a/.pipelines/build.yml +++ b/.pipelines/build.yml @@ -23,10 +23,17 @@ steps: installationPath: '$(Agent.ToolsDirectory)/dotnet' - task: UseDotNet@2 - displayName: 'Install .NET 6.0.x' + displayName: 'Install .NET 6.x' inputs: packageType: sdk - version: '6.0.x' + version: '6.x' + installationPath: '$(Agent.ToolsDirectory)/dotnet' + +- task: UseDotNet@2 + displayName: 'Install .NET 7.x' + inputs: + packageType: sdk + version: '7.x' installationPath: '$(Agent.ToolsDirectory)/dotnet' - task: NuGetToolInstaller@1 diff --git a/JWT.sln b/JWT.sln index cdf76a388..a694636cd 100644 --- a/JWT.sln +++ b/JWT.sln @@ -55,6 +55,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C86A941F-F65 src\Directory.Build.targets = src\Directory.Build.targets EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JWT.Tests.Net70", "tests\JWT.Tests.Net70\JWT.Tests.Net70.csproj", "{D7F24AC9-D178-4BAB-BF93-4BAD8028416D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -105,6 +107,10 @@ Global {73167BAB-1F21-4DE9-83E0-5E0686AB7245}.Debug|Any CPU.Build.0 = Debug|Any CPU {73167BAB-1F21-4DE9-83E0-5E0686AB7245}.Release|Any CPU.ActiveCfg = Release|Any CPU {73167BAB-1F21-4DE9-83E0-5E0686AB7245}.Release|Any CPU.Build.0 = Release|Any CPU + {D7F24AC9-D178-4BAB-BF93-4BAD8028416D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D7F24AC9-D178-4BAB-BF93-4BAD8028416D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D7F24AC9-D178-4BAB-BF93-4BAD8028416D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D7F24AC9-D178-4BAB-BF93-4BAD8028416D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/JWT/Algorithms/ECDSAAlgorithm.cs b/src/JWT/Algorithms/ECDSAAlgorithm.cs index 558cf380e..81e51a6a5 100644 --- a/src/JWT/Algorithms/ECDSAAlgorithm.cs +++ b/src/JWT/Algorithms/ECDSAAlgorithm.cs @@ -1,4 +1,4 @@ -#if NETSTANDARD2_0 || NET6_0 +#if NETSTANDARD2_0 || NET6_0_OR_GREATER using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; diff --git a/src/JWT/Algorithms/ECDSAAlgorithmFactory.cs b/src/JWT/Algorithms/ECDSAAlgorithmFactory.cs index 4b732dcf7..9928fbb17 100644 --- a/src/JWT/Algorithms/ECDSAAlgorithmFactory.cs +++ b/src/JWT/Algorithms/ECDSAAlgorithmFactory.cs @@ -7,7 +7,7 @@ namespace JWT.Algorithms /// public sealed class ECDSAAlgorithmFactory : HMACSHAAlgorithmFactory { -#if NETSTANDARD2_0 || NET6_0 +#if NETSTANDARD2_0 || NET6_0_OR_GREATER private readonly Func _certFactory; private readonly ECDsa _publicKey; @@ -45,7 +45,7 @@ public ECDSAAlgorithmFactory(ECDsa publicKey, ECDsa privateKey) protected override IJwtAlgorithm Create(JwtAlgorithmName algorithm) { -#if NETSTANDARD2_0 || NET6_0 +#if NETSTANDARD2_0 || NET6_0_OR_GREATER switch (algorithm) { case JwtAlgorithmName.ES256: @@ -70,7 +70,7 @@ protected override IJwtAlgorithm Create(JwtAlgorithmName algorithm) #endif } -#if NETSTANDARD2_0 || NET6_0 +#if NETSTANDARD2_0 || NET6_0_OR_GREATER private IJwtAlgorithm CreateES256Algorithm() { if (_certFactory is object) diff --git a/src/JWT/Algorithms/ES256Algorithm.cs b/src/JWT/Algorithms/ES256Algorithm.cs index a172601f9..ac3aa6a5f 100644 --- a/src/JWT/Algorithms/ES256Algorithm.cs +++ b/src/JWT/Algorithms/ES256Algorithm.cs @@ -1,4 +1,4 @@ -#if NETSTANDARD2_0 || NET6_0 +#if NETSTANDARD2_0 || NET6_0_OR_GREATER using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; diff --git a/src/JWT/Algorithms/ES384Algorithm.cs b/src/JWT/Algorithms/ES384Algorithm.cs index 66498a6d9..169ffe438 100644 --- a/src/JWT/Algorithms/ES384Algorithm.cs +++ b/src/JWT/Algorithms/ES384Algorithm.cs @@ -1,4 +1,4 @@ -#if NETSTANDARD2_0 || NET6_0 +#if NETSTANDARD2_0 || NET6_0_OR_GREATER using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; diff --git a/src/JWT/Algorithms/ES512Algorithm.cs b/src/JWT/Algorithms/ES512Algorithm.cs index 26067450b..1b86c03c2 100644 --- a/src/JWT/Algorithms/ES512Algorithm.cs +++ b/src/JWT/Algorithms/ES512Algorithm.cs @@ -1,4 +1,4 @@ -#if NETSTANDARD2_0 || NET6_0 +#if NETSTANDARD2_0 || NET6_0_OR_GREATER using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; diff --git a/src/JWT/Properties/AssemblyInfo.cs b/src/JWT/Properties/AssemblyInfo.cs index b7eb7edc8..5f0a639ae 100644 --- a/src/JWT/Properties/AssemblyInfo.cs +++ b/src/JWT/Properties/AssemblyInfo.cs @@ -7,6 +7,7 @@ [assembly: InternalsVisibleTo("JWT.Tests.Net40, PublicKey=" + AssemblyInfo.PublicKey)] [assembly: InternalsVisibleTo("JWT.Tests.Net46, PublicKey=" + AssemblyInfo.PublicKey)] [assembly: InternalsVisibleTo("JWT.Tests.Net60, PublicKey=" + AssemblyInfo.PublicKey)] +[assembly: InternalsVisibleTo("JWT.Tests.Net70, PublicKey=" + AssemblyInfo.PublicKey)] [assembly: InternalsVisibleTo("JWT.Extensions.AspNetCore.Tests, PublicKey=" + AssemblyInfo.PublicKey)] namespace JWT diff --git a/tests/JWT.Tests.Common/Algorithms/ECDSAAlgorithmFactoryTests.cs b/tests/JWT.Tests.Common/Algorithms/ECDSAAlgorithmFactoryTests.cs index dac0d0f21..9b11c2220 100644 --- a/tests/JWT.Tests.Common/Algorithms/ECDSAAlgorithmFactoryTests.cs +++ b/tests/JWT.Tests.Common/Algorithms/ECDSAAlgorithmFactoryTests.cs @@ -11,7 +11,7 @@ namespace JWT.Tests.Algorithms [TestClass] public class ECDSAAlgorithmFactoryTests { -#if NETSTANDARD2_0 || NET6_0 +#if NETSTANDARD2_0 || NET6_0_OR_GREATER [TestMethod] public void Create_Should_Return_Instance_Of_ES256Algorithm_When_Algorithm_Specified_In_Jwt_Header_Is_ES256_And_Targeting_NetStandard20() { diff --git a/tests/JWT.Tests.Common/Algorithms/ECDSAAlgorithmTests.cs b/tests/JWT.Tests.Common/Algorithms/ECDSAAlgorithmTests.cs index 9b8aa87b9..aa2aeebc8 100644 --- a/tests/JWT.Tests.Common/Algorithms/ECDSAAlgorithmTests.cs +++ b/tests/JWT.Tests.Common/Algorithms/ECDSAAlgorithmTests.cs @@ -1,4 +1,4 @@ -#if NETSTANDARD2_0 || NET6_0 +#if NETSTANDARD2_0 || NET6_0_OR_GREATER using System; using System.Collections.Generic; using System.Security.Cryptography; diff --git a/tests/JWT.Tests.Common/Builder/JwtBuilderEncodeTests.cs b/tests/JWT.Tests.Common/Builder/JwtBuilderEncodeTests.cs index 79cc821c9..2dd229f23 100644 --- a/tests/JWT.Tests.Common/Builder/JwtBuilderEncodeTests.cs +++ b/tests/JWT.Tests.Common/Builder/JwtBuilderEncodeTests.cs @@ -381,12 +381,12 @@ public void Encode_With_Secret_Should_Return_Valid_Token_Using_Json_Net() .HaveCount(3, "because the token should consist of three parts"); } -#if NETSTANDARD2_0 || NET6_0 +#if NETSTANDARD2_0 || NET6_0_OR_GREATER [TestMethod] public void Encode_Test_Bug438() { var privateKey = ECDsa.Create(); - var publicKey = ECDsa.Create();; + var publicKey = ECDsa.Create(); var algo = new ES256Algorithm(publicKey, privateKey); diff --git a/tests/JWT.Tests.Common/JwtBuilderEndToEndTests.cs b/tests/JWT.Tests.Common/JwtBuilderEndToEndTests.cs index fda5d4c48..493603b70 100644 --- a/tests/JWT.Tests.Common/JwtBuilderEndToEndTests.cs +++ b/tests/JWT.Tests.Common/JwtBuilderEndToEndTests.cs @@ -1,4 +1,4 @@ -#if NETSTANDARD2_1 || NET6_0 +#if NETSTANDARD2_1 || NET6_0_OR_GREATER using System; using System.Collections.Generic; using System.Security.Cryptography.X509Certificates; diff --git a/tests/JWT.Tests.Net60/TargetFrameworkTests.cs b/tests/JWT.Tests.Net60/TargetFrameworkTests.cs index d3a0a8228..2b5deb348 100644 --- a/tests/JWT.Tests.Net60/TargetFrameworkTests.cs +++ b/tests/JWT.Tests.Net60/TargetFrameworkTests.cs @@ -6,12 +6,12 @@ namespace JWT.Tests public class TargetFrameworkTests { [TestMethod] -#if NET6_0 +#if NET6_0_OR_GREATER [ExpectedException(typeof(System.InvalidOperationException))] #endif public void Build_Must_Fail_When_TargetFramework_Is_Incorrect() { -#if NET6_0 +#if NET6_0_OR_GREATER throw new System.InvalidOperationException(); #endif } diff --git a/tests/JWT.Tests.Net70/JWT.Tests.Net70.csproj b/tests/JWT.Tests.Net70/JWT.Tests.Net70.csproj new file mode 100644 index 000000000..9056054f7 --- /dev/null +++ b/tests/JWT.Tests.Net70/JWT.Tests.Net70.csproj @@ -0,0 +1,15 @@ + + + + net7.0 + + + + + + + + + + + \ No newline at end of file