diff --git a/test/header_test.dart b/test/header_test.dart index 48f9798..f7781fd 100644 --- a/test/header_test.dart +++ b/test/header_test.dart @@ -25,11 +25,11 @@ void main() { }); test('should be still valid', () { - final iat = DateTime(2023); - final exp = DateTime(2023).add(Duration(hours: 1)); + final iat = DateTime(2042); + final exp = DateTime(2042).add(Duration(hours: 1)); withClock( - Clock.fixed(DateTime(2023)), + Clock.fixed(DateTime(2042)), () { final duration = Duration(hours: 1); final token = JWT({'foo': 'bar'}).sign(hsKey, expiresIn: duration); @@ -61,7 +61,7 @@ void main() { }); //----------------------// - // Not Before (nbf) // + // Not Before (nbf) // //----------------------// group('nbf', () { test('should throw when token is not yet valid', () { @@ -75,11 +75,11 @@ void main() { }); test('should be valid after nbf time', () { - final iat = DateTime(2023); + final iat = DateTime(2042); final nbf = iat.add(Duration(minutes: 30)); withClock( - Clock.fixed(DateTime(2023)), + Clock.fixed(DateTime(2042)), () { final token = JWT({'foo': 'bar'}).sign( hsKey, @@ -112,6 +112,40 @@ void main() { contains('foo'), ); }); + + //----------------------// + // Issued At (iat) // + //----------------------// + group('iat', () { + test('should have iat claim by default', () { + final iat = DateTime(2042); + + withClock(Clock.fixed(iat), () { + final token = JWT({'foo': 'bar'}).sign(hsKey); + + expect( + JWT.verify(token, hsKey).payload, + equals({ + 'foo': 'bar', + 'iat': iat.millisecondsSinceEpoch ~/ 1000, + }), + ); + }); + }); + + test('should be valid when iat is in the future', () { + final futureIat = DateTime(2042).add(Duration(hours: 1)); + final token = JWT({ + 'foo': 'bar', + 'iat': futureIat.millisecondsSinceEpoch ~/ 1000 + }).sign(hsKey); + + expect( + JWT.verify(token, hsKey).payload, + contains('foo'), + ); + }); + }); }); }); }