Skip to content

Commit

Permalink
Manually fix some conflits after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
nbarbettini committed Apr 14, 2017
1 parent 96a712c commit c828ffb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
25 changes: 16 additions & 9 deletions tests/JWT.Tests.Core/JwtDecoderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public class JwtDecoderTest
public void Decode_Should_Decode_Token_To_Json_Encoded_String()
{
var serializer = new JsonNetSerializer();
var decoder = new JwtDecoder(serializer, null);
var urlEncoder = new JwtBase64UrlEncoder();
var decoder = new JwtDecoder(serializer, null, urlEncoder);

var expectedPayload = serializer.Serialize(TestData.Customer);

Expand All @@ -26,7 +27,8 @@ public void Decode_Should_Decode_Token_To_Json_Encoded_String()
public void DecodeToObject_Should_Decode_Token_To_Dictionary()
{
var serializer = new JsonNetSerializer();
var decoder = new JwtDecoder(serializer, null);
var urlEncoder = new JwtBase64UrlEncoder();
var decoder = new JwtDecoder(serializer, null, urlEncoder);

var actualPayload = decoder.DecodeToObject(TestData.Token, "ABC", verify: false);

Expand All @@ -37,7 +39,8 @@ public void DecodeToObject_Should_Decode_Token_To_Dictionary()
public void DecodeToObject_Should_Decode_Token_To_Generic_Type()
{
var serializer = new JsonNetSerializer();
var decoder = new JwtDecoder(serializer, null);
var urlEncoder = new JwtBase64UrlEncoder();
var decoder = new JwtDecoder(serializer, null, urlEncoder);

var actualPayload = decoder.DecodeToObject<Customer>(TestData.Token, "ABC", verify: false);

Expand All @@ -48,7 +51,8 @@ public void DecodeToObject_Should_Decode_Token_To_Generic_Type()
public void DecodeToObject_Should_Throw_Exception_On_Malformed_Token()
{
var serializer = new JsonNetSerializer();
var decoder = new JwtDecoder(serializer, null);
var urlEncoder = new JwtBase64UrlEncoder();
var decoder = new JwtDecoder(serializer, null, urlEncoder);

Action action = () => decoder.DecodeToObject<Customer>(TestData.MalformedToken, "ABC", verify: false);

Expand All @@ -60,7 +64,8 @@ public void DecodeToObject_Should_Throw_Exception_On_Invalid_Key()
{
var serializer = new JsonNetSerializer();
var validator = new JwtValidator(serializer, new UtcDateTimeProvider());
var decoder = new JwtDecoder(serializer, validator);
var urlEncoder = new JwtBase64UrlEncoder();
var decoder = new JwtDecoder(serializer, validator, urlEncoder);

Action action = () => decoder.DecodeToObject<Customer>(TestData.Token, "XYZ", verify: true);

Expand All @@ -72,9 +77,10 @@ public void DecodeToObject_Should_Throw_Exception_On_Invalid_Expiration_Claim()
{
var serializer = new JsonNetSerializer();
var validator = new JwtValidator(serializer, new UtcDateTimeProvider());
var decoder = new JwtDecoder(serializer, validator);
var urlEncoder = new JwtBase64UrlEncoder();
var decoder = new JwtDecoder(serializer, validator, urlEncoder);

var encoder = new JwtEncoder(new HMACSHA256Algorithm(), serializer);
var encoder = new JwtEncoder(new HMACSHA256Algorithm(), serializer, urlEncoder);
var invalidtoken = encoder.Encode(new { exp = "asdsad" }, "ABC");

Action action = () => decoder.DecodeToObject<Customer>(invalidtoken, "ABC", verify: true);
Expand All @@ -88,13 +94,14 @@ public void DecodeToObject_Should_Throw_Exception_On_Expired_Claim()
var serializer = new JsonNetSerializer();
var dateTimeProvider = new UtcDateTimeProvider();
var validator = new JwtValidator(serializer, dateTimeProvider);
var decoder = new JwtDecoder(serializer, validator);
var urlEncoder = new JwtBase64UrlEncoder();
var decoder = new JwtDecoder(serializer, validator, urlEncoder);

var now = dateTimeProvider.GetNow();
var hourAgo = now.Subtract(new TimeSpan(1, 0, 0));
var unixTimestamp = (int)(hourAgo - new DateTime(1970, 1, 1)).TotalSeconds;

var encoder = new JwtEncoder(new HMACSHA256Algorithm(), serializer);
var encoder = new JwtEncoder(new HMACSHA256Algorithm(), serializer, urlEncoder);
var expiredtoken = encoder.Encode(new { exp = unixTimestamp }, "ABC");

Action action = () => decoder.DecodeToObject<Customer>(expiredtoken, "ABC", verify: true);
Expand Down
6 changes: 4 additions & 2 deletions tests/JWT.Tests.Core/JwtEncoderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public class JwtEncoderTest
public void Encode_Should_Encode_To_Token()
{
var serializer = new JsonNetSerializer();
var encoder = new JwtEncoder(new HMACSHA256Algorithm(), serializer);
var urlEncoder = new JwtBase64UrlEncoder();
var encoder = new JwtEncoder(new HMACSHA256Algorithm(), serializer, urlEncoder);

var actual = encoder.Encode(TestData.Customer, "ABC");

Expand All @@ -24,7 +25,8 @@ public void Encode_Should_Encode_To_Token()
public void Encode_Should_Encode_To_Token_With_Extra_Headers()
{
var serializer = new JsonNetSerializer();
var encoder = new JwtEncoder(new HMACSHA256Algorithm(), serializer);
var urlEncoder = new JwtBase64UrlEncoder();
var encoder = new JwtEncoder(new HMACSHA256Algorithm(), serializer, urlEncoder);

var extraheaders = new Dictionary<string, object> { { "foo", "bar" } };
var actual = encoder.Encode(extraheaders, TestData.Customer, "ABC");
Expand Down

0 comments on commit c828ffb

Please sign in to comment.