mirror of
https://github.com/jonasroussel/dart_jsonwebtoken.git
synced 2025-05-17 16:15:52 +08:00
test: Add tests for iat claim
This commit is contained in:
@ -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);
|
||||
@ -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'),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user