diff --git a/tests/LitJWT.Tests/DecodeTest.cs b/tests/LitJWT.Tests/DecodeTest.cs index 07ac869..5ac50e5 100644 --- a/tests/LitJWT.Tests/DecodeTest.cs +++ b/tests/LitJWT.Tests/DecodeTest.cs @@ -115,6 +115,24 @@ public void VerifyExp() var decodeResult = decoder.TryDecode(result, x => JsonConvert.DeserializeObject(Encoding.UTF8.GetString(x)), out var decodedPayload); decodeResult.Should().Be(DecodeResult.Success); } + + { + var nested = new Payload { Bar = 2, Foo = "foo2" }; + var payload = new PayloadExp { Bar = 1, Foo = "foo", Nested = nested, exp = (DateTimeOffset.UtcNow - TimeSpan.FromSeconds(10)).ToUnixTimeSeconds() }; + var jwt = encoder.Encode(payload, null); + + var decodeResult = decoder.TryDecode(jwt, out PayloadExp decodedPayload); + decodeResult.Should().Be(DecodeResult.FailedVerifyExpire); + } + + { + var nested = new Payload { Bar = 2, Foo = "foo2" }; + var payload = new PayloadExp { Bar = 1, Foo = "foo", Nested = nested, exp = (DateTimeOffset.UtcNow + TimeSpan.FromSeconds(10)).ToUnixTimeSeconds() }; + var jwt = encoder.Encode(payload, null); + + var decodeResult = decoder.TryDecode(jwt, out PayloadExp decodedPayload); + decodeResult.Should().Be(DecodeResult.Success); + } } [Fact] @@ -144,6 +162,24 @@ public void VerifyNbf() decodeResult.Should().Be(DecodeResult.Success); } + + { + var nested = new Payload { Bar = 2, Foo = "foo2" }; + var payload = new PayloadNbf { Bar = 1, Foo = "foo", Nested = nested, nbf = (DateTimeOffset.UtcNow + TimeSpan.FromSeconds(10)).ToUnixTimeSeconds() }; + var jwt = encoder.Encode(payload, null); + + var decodeResult = decoder.TryDecode(jwt, out PayloadNbf decodedPayload); + decodeResult.Should().Be(DecodeResult.FailedVerifyNotBefore); + } + + { + var nested = new Payload { Bar = 2, Foo = "foo2" }; + var payload = new PayloadNbf { Bar = 1, Foo = "foo", Nested = nested, nbf = (DateTimeOffset.UtcNow - TimeSpan.FromSeconds(10)).ToUnixTimeSeconds() }; + var jwt = encoder.Encode(payload, null); + + var decodeResult = decoder.TryDecode(jwt, out PayloadNbf decodedPayload); + decodeResult.Should().Be(DecodeResult.Success); + } } @@ -232,6 +268,24 @@ public void VerifyExpUtf8() var decodeResult = decoder.TryDecode(result, x => JsonConvert.DeserializeObject(Encoding.UTF8.GetString(x)), out var decodedPayload); decodeResult.Should().Be(DecodeResult.Success); } + + { + var nested = new Payload { Bar = 2, Foo = "foo2" }; + var payload = new PayloadExp { Bar = 1, Foo = "foo", Nested = nested, exp = (DateTimeOffset.UtcNow - TimeSpan.FromSeconds(10)).ToUnixTimeSeconds() }; + var jwt = encoder.EncodeAsUtf8Bytes(payload, null); + + var decodeResult = decoder.TryDecode(jwt, out PayloadExp decodedPayload); + decodeResult.Should().Be(DecodeResult.FailedVerifyExpire); + } + + { + var nested = new Payload { Bar = 2, Foo = "foo2" }; + var payload = new PayloadExp { Bar = 1, Foo = "foo", Nested = nested, exp = (DateTimeOffset.UtcNow + TimeSpan.FromSeconds(10)).ToUnixTimeSeconds() }; + var jwt = encoder.EncodeAsUtf8Bytes(payload, null); + + var decodeResult = decoder.TryDecode(jwt, out PayloadExp decodedPayload); + decodeResult.Should().Be(DecodeResult.Success); + } } [Fact] @@ -259,6 +313,26 @@ public void VerifyNbfUtf8() var decodeResult = decoder.TryDecode(result, x => JsonConvert.DeserializeObject(Encoding.UTF8.GetString(x)), out var decodedPayload); + decodeResult.Should().Be(DecodeResult.Success); + } + { + var nested = new Payload { Bar = 2, Foo = "foo2" }; + var payload = new PayloadNbf { Bar = 1, Foo = "foo", Nested = nested, nbf = (DateTimeOffset.UtcNow + TimeSpan.FromSeconds(10)).ToUnixTimeSeconds() }; + var jwt = encoder.EncodeAsUtf8Bytes(payload, null); + + + var decodeResult = decoder.TryDecode(jwt, out PayloadNbf decodedPayload); + + decodeResult.Should().Be(DecodeResult.FailedVerifyNotBefore); + } + { + var nested = new Payload { Bar = 2, Foo = "foo2" }; + var payload = new PayloadNbf { Bar = 1, Foo = "foo", Nested = nested, nbf = (DateTimeOffset.UtcNow - TimeSpan.FromSeconds(10)).ToUnixTimeSeconds() }; + var jwt = encoder.EncodeAsUtf8Bytes(payload, null); + + + var decodeResult = decoder.TryDecode(jwt, out PayloadNbf decodedPayload); + decodeResult.Should().Be(DecodeResult.Success); } }