mirror of
https://github.com/jonasroussel/dart_jsonwebtoken.git
synced 2025-05-18 00:25: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', () {
|
test('should be still valid', () {
|
||||||
final iat = DateTime(2023);
|
final iat = DateTime(2042);
|
||||||
final exp = DateTime(2023).add(Duration(hours: 1));
|
final exp = DateTime(2042).add(Duration(hours: 1));
|
||||||
|
|
||||||
withClock(
|
withClock(
|
||||||
Clock.fixed(DateTime(2023)),
|
Clock.fixed(DateTime(2042)),
|
||||||
() {
|
() {
|
||||||
final duration = Duration(hours: 1);
|
final duration = Duration(hours: 1);
|
||||||
final token = JWT({'foo': 'bar'}).sign(hsKey, expiresIn: duration);
|
final token = JWT({'foo': 'bar'}).sign(hsKey, expiresIn: duration);
|
||||||
@ -75,11 +75,11 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should be valid after nbf time', () {
|
test('should be valid after nbf time', () {
|
||||||
final iat = DateTime(2023);
|
final iat = DateTime(2042);
|
||||||
final nbf = iat.add(Duration(minutes: 30));
|
final nbf = iat.add(Duration(minutes: 30));
|
||||||
|
|
||||||
withClock(
|
withClock(
|
||||||
Clock.fixed(DateTime(2023)),
|
Clock.fixed(DateTime(2042)),
|
||||||
() {
|
() {
|
||||||
final token = JWT({'foo': 'bar'}).sign(
|
final token = JWT({'foo': 'bar'}).sign(
|
||||||
hsKey,
|
hsKey,
|
||||||
@ -112,6 +112,40 @@ void main() {
|
|||||||
contains('foo'),
|
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