-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Convert JWT project to netstandard * Migrate and split up test projects * Target .NETFramework 3.5 * Only depend on Csp package in netstandard * Remove extraneous attributes
- Loading branch information
1 parent
872cbf4
commit a2f104d
Showing
27 changed files
with
469 additions
and
529 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,40 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{A80B51B8-DDF6-4026-98A4-B59653E50B38}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>JWT</RootNamespace> | ||
<AssemblyName>JWT</AssemblyName> | ||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<TargetFrameworkProfile> | ||
</TargetFrameworkProfile> | ||
<TargetFrameworks>net35;netstandard1.3</TargetFrameworks> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
<PropertyGroup Condition="'$(TargetFramework)' == 'net35'"> | ||
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier> | ||
<DefineConstants>NET35</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard1.3'"> | ||
<TargetFrameworkIdentifier>.NETStandard</TargetFrameworkIdentifier> | ||
<DefineConstants>NETSTANDARD1_3</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<Company>Public Domain</Company> | ||
<Copyright>Public Domain</Copyright> | ||
<Description>JWT.NET, a JWT (JSON Web Token) implementation for .NET</Description> | ||
<RepositoryUrl>https://github.com/jwt-dotnet/jwt</RepositoryUrl> | ||
<PackageProjectUrl>https://github.com/jwt-dotnet/jwt</PackageProjectUrl> | ||
<Authors>John Sheehan, Michael Lehenbauer, Alexander Batishchev</Authors> | ||
<PackageLicenseUrl>https://creativecommons.org/publicdomain/zero/1.0/</PackageLicenseUrl> | ||
<Version>3.0.0-beta1</Version> | ||
<PackageTags>jwt json</PackageTags> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<DefineConstants>TRACE;DEBUG</DefineConstants> | ||
<DocumentationFile>bin\Debug\netstandard1.3\JWT.xml</DocumentationFile> | ||
<OutputPath>bin\Debug\netstandard1.3\</OutputPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Newtonsoft.Json.10.0.2\lib\net35\Newtonsoft.Json.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="AlgorithmFactory.cs" /> | ||
<Compile Include="Algorithms\HMACSHA256Algorithm.cs" /> | ||
<Compile Include="Algorithms\HMACSHA384Algorithm.cs" /> | ||
<Compile Include="Algorithms\HMACSHA512Algorithm.cs" /> | ||
<Compile Include="Algorithms\RS256Algorithm.cs" /> | ||
<Compile Include="IBase64UrlEncoder.cs" /> | ||
<Compile Include="IDateTimeProvider.cs" /> | ||
<Compile Include="IJsonSerializer.cs" /> | ||
<Compile Include="IJwtAlgorithm.cs" /> | ||
<Compile Include="IJwtDecoder.cs" /> | ||
<Compile Include="IJwtEncoder.cs" /> | ||
<Compile Include="IJwtValidator.cs" /> | ||
<Compile Include="JsonWebToken.cs" /> | ||
<Compile Include="JwtBase64UrlEncoder.cs" /> | ||
<Compile Include="JwtDecoder.cs" /> | ||
<Compile Include="JwtEncoder.cs" /> | ||
<Compile Include="JwtHashAlgorithm.cs" /> | ||
<Compile Include="JwtValidator.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Serializers\JsonNetSerializer.cs" /> | ||
<Compile Include="SignatureVerificationException.cs" /> | ||
<Compile Include="TokenExpiredException.cs" /> | ||
<Compile Include="UtcDateTimeProvider.cs" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'"> | ||
<PackageReference Include="System.Security.Cryptography.Csp" Version="4.3.0" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
16 changes: 8 additions & 8 deletions
16
tests/JWT.Tests/Internal/Customer.cs → tests/JWT.Tests.Common/Customer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
namespace JWT.Tests | ||
{ | ||
internal class Customer | ||
{ | ||
public string FirstName { get; set; } | ||
|
||
public int Age { get; set; } | ||
} | ||
namespace JWT.Tests.Common | ||
{ | ||
public class Customer | ||
{ | ||
public string FirstName { get; set; } | ||
|
||
public int Age { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard1.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace JWT.Tests.Common | ||
{ | ||
public static class TestData | ||
{ | ||
public static readonly Customer Customer = new Customer { FirstName = "Bob", Age = 37 }; | ||
|
||
public const string Token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJGaXJzdE5hbWUiOiJCb2IiLCJBZ2UiOjM3fQ.cr0xw8c_HKzhFBMQrseSPGoJ0NPlRp_3BKzP96jwBdY"; | ||
public const string MalformedToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9eyJGaXJzdE5hbWUiOiJCb2IiLCJBZ2UiOjM3fQ.cr0xw8c_HKzhFBMQrseSPGoJ0NPlRp_3BKzP96jwBdY"; | ||
public const string ExtraHeadersToken = "eyJmb28iOiJiYXIiLCJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJGaXJzdE5hbWUiOiJCb2IiLCJBZ2UiOjM3fQ.slrbXF9VSrlX7LKsV-Umb_zEzWLxQjCfUOjNTbvyr1g"; | ||
|
||
public static readonly IDictionary<string, object> DictionaryPayload = new Dictionary<string, object> | ||
{ | ||
{ "FirstName", "Bob" }, | ||
{ "Age", 37 } | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System; | ||
using FluentAssertions; | ||
using JWT.Serializers; | ||
using Xunit; | ||
using JWT.Tests.Common; | ||
|
||
namespace JWT.Tests | ||
{ | ||
public class DecodeTests | ||
{ | ||
[Fact] | ||
public void Decode_Should_DecodeToken_To_Json_Encoded_String_With_JsonNet_Serializer() | ||
{ | ||
var serializer = new JsonNetSerializer(); | ||
JsonWebToken.JsonSerializer = serializer; | ||
|
||
var expectedPayload = serializer.Serialize(TestData.Customer); | ||
var actualPayload = JsonWebToken.Decode(TestData.Token, "ABC", verify: false); | ||
|
||
actualPayload.Should().Be(expectedPayload); | ||
} | ||
|
||
[Fact] | ||
public void DecodeToObject_Should_DecodeToken_To_Dictionary_With_JsonNet_Serializer() | ||
{ | ||
JsonWebToken.JsonSerializer = new JsonNetSerializer(); | ||
|
||
var actualPayload = JsonWebToken.DecodeToObject(TestData.Token, "ABC", verify: false); | ||
|
||
actualPayload.ShouldBeEquivalentTo(TestData.DictionaryPayload, options => options.IncludingAllRuntimeProperties()); | ||
} | ||
|
||
[Fact] | ||
public void DecodeToObject_Should_DecodeToken_To_Generic_Type_With_JsonNet_Serializer() | ||
{ | ||
JsonWebToken.JsonSerializer = new JsonNetSerializer(); | ||
|
||
var actualPayload = JsonWebToken.DecodeToObject<Customer>(TestData.Token, "ABC", verify: false); | ||
|
||
actualPayload.ShouldBeEquivalentTo(TestData.Customer); | ||
} | ||
|
||
[Fact] | ||
public void DecodeToObject_Should_Throw_Exception_On_MalformedToken() | ||
{ | ||
Action action = () => JsonWebToken.DecodeToObject<Customer>(TestData.MalformedToken, "ABC", verify: false); | ||
|
||
action.ShouldThrow<ArgumentException>(); | ||
} | ||
|
||
[Fact] | ||
public void DecodeToObject_Should_Throw_Exception_On_Invalid_Key() | ||
{ | ||
Action action = () => JsonWebToken.DecodeToObject<Customer>(TestData.Token, "XYZ", verify: true); | ||
|
||
action.ShouldThrow<SignatureVerificationException>(); | ||
} | ||
|
||
[Fact] | ||
public void DecodeToObject_Should_Throw_Exception_On_Invalid_Expiration_Claim() | ||
{ | ||
var invalidexptoken = JsonWebToken.Encode(new { exp = "asdsad" }, "ABC", JwtHashAlgorithm.HS256); | ||
|
||
Action action = () => JsonWebToken.DecodeToObject<Customer>(invalidexptoken, "ABC", verify: true); | ||
|
||
action.ShouldThrow<SignatureVerificationException>(); | ||
} | ||
|
||
[Fact] | ||
public void DecodeToObject_Should_Throw_Exception_On_Expired_Claim() | ||
{ | ||
var hourAgo = DateTime.UtcNow.Subtract(new TimeSpan(1, 0, 0)); | ||
var unixTimestamp = (int)(hourAgo - new DateTime(1970, 1, 1)).TotalSeconds; | ||
var expiredtoken = JsonWebToken.Encode(new { exp = unixTimestamp }, "ABC", JwtHashAlgorithm.HS256); | ||
|
||
Action action = () => JsonWebToken.DecodeToObject<Customer>(expiredtoken, "ABC", verify: true); | ||
|
||
action.ShouldThrow<TokenExpiredException>(); | ||
} | ||
|
||
[Fact] | ||
public void DecodeToObject_Should_Throw_Exception_Before_NotBefore_Becomes_Valid() | ||
{ | ||
var nbf = (int)(DateTime.UtcNow.AddHours(1) - JwtValidator.UnixEpoch).TotalSeconds; | ||
var invalidnbftoken = JsonWebToken.Encode(new { nbf = nbf }, "ABC", JwtHashAlgorithm.HS256); | ||
|
||
Action action = () => JsonWebToken.DecodeToObject<Customer>(invalidnbftoken, "ABC", verify: true); | ||
|
||
action.ShouldThrow<SignatureVerificationException>(); | ||
} | ||
|
||
[Fact] | ||
public void DecodeToObject_Should_Decode_Token_After_NotBefore_Becomes_Valid() | ||
{ | ||
var nbf = (int)(DateTime.UtcNow - JwtValidator.UnixEpoch).TotalSeconds; | ||
var validnbftoken = JsonWebToken.Encode(new { nbf = nbf }, "ABC", JwtHashAlgorithm.HS256); | ||
|
||
JsonWebToken.DecodeToObject<Customer>(validnbftoken, "ABC", verify: true); | ||
} | ||
} | ||
} |
Oops, something went wrong.