2018-06-27 16:36:31 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2021-05-14 11:09:48 +00:00
|
|
|
import 'package:angel3_auth/angel3_auth.dart';
|
2018-06-27 16:36:31 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
2021-05-09 11:16:15 +00:00
|
|
|
const Duration threeDays = Duration(days: 3);
|
2018-06-27 16:36:31 +00:00
|
|
|
|
|
|
|
void main() {
|
2021-03-20 23:51:20 +00:00
|
|
|
late Cookie defaultCookie;
|
2019-04-19 07:50:04 +00:00
|
|
|
var auth = AngelAuth(
|
2021-06-07 00:50:39 +00:00
|
|
|
secureCookies: true,
|
|
|
|
cookieDomain: 'SECURE',
|
|
|
|
jwtLifeSpan: threeDays.inMilliseconds,
|
2023-05-21 11:02:54 +00:00
|
|
|
serializer: (u) => u,
|
2021-06-07 00:50:39 +00:00
|
|
|
deserializer: (u) => u);
|
2018-06-27 16:36:31 +00:00
|
|
|
|
2019-04-19 07:50:04 +00:00
|
|
|
setUp(() => defaultCookie = Cookie('a', 'b'));
|
2018-06-27 16:36:31 +00:00
|
|
|
|
|
|
|
test('sets maxAge', () {
|
|
|
|
expect(auth.protectCookie(defaultCookie).maxAge, threeDays.inSeconds);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('sets expires', () {
|
2019-04-19 07:50:04 +00:00
|
|
|
var now = DateTime.now();
|
2021-03-20 23:51:20 +00:00
|
|
|
var expiry = auth.protectCookie(defaultCookie).expires!;
|
2018-06-27 16:36:31 +00:00
|
|
|
var diff = expiry.difference(now);
|
|
|
|
expect(diff.inSeconds, threeDays.inSeconds);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('sets httpOnly', () {
|
|
|
|
expect(auth.protectCookie(defaultCookie).httpOnly, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('sets secure', () {
|
|
|
|
expect(auth.protectCookie(defaultCookie).secure, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('sets domain', () {
|
|
|
|
expect(auth.protectCookie(defaultCookie).domain, 'SECURE');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('preserves domain if present', () {
|
|
|
|
expect(auth.protectCookie(defaultCookie..domain = 'foo').domain, 'foo');
|
|
|
|
});
|
|
|
|
}
|