Skip to content

Commit

Permalink
Added unit tests for .NET 7 (jwt-dotnet#463)
Browse files Browse the repository at this point in the history
* Added tests for .NET 7
* Added .NET 7 to build pipeline

Co-authored-by: Markus Hartung <[email protected]>
Co-authored-by: Alexander Batishchev <[email protected]>
  • Loading branch information
3 people authored Jan 25, 2023
1 parent d3b4cea commit 79ac65b
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 16 deletions.
11 changes: 9 additions & 2 deletions .pipelines/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions JWT.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/JWT/Algorithms/ECDSAAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/JWT/Algorithms/ECDSAAlgorithmFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace JWT.Algorithms
/// <inheritdoc />
public sealed class ECDSAAlgorithmFactory : HMACSHAAlgorithmFactory
{
#if NETSTANDARD2_0 || NET6_0
#if NETSTANDARD2_0 || NET6_0_OR_GREATER
private readonly Func<X509Certificate2> _certFactory;

private readonly ECDsa _publicKey;
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/JWT/Algorithms/ES256Algorithm.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/JWT/Algorithms/ES384Algorithm.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/JWT/Algorithms/ES512Algorithm.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/JWT/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/JWT.Tests.Common/Algorithms/ECDSAAlgorithmTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/JWT.Tests.Common/Builder/JwtBuilderEncodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/JWT.Tests.Common/JwtBuilderEndToEndTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/JWT.Tests.Net60/TargetFrameworkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 15 additions & 0 deletions tests/JWT.Tests.Net70/JWT.Tests.Net70.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\JWT\JWT.csproj" />
<ProjectReference Include="..\JWT.Tests.Common\JWT.Tests.Common.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\JWT.Tests.Net60\*Tests.cs" />
</ItemGroup>

</Project>

0 comments on commit 79ac65b

Please sign in to comment.