platform/packages/auth/test/auth_token_test.dart
Tobe O e887b1d21f Add 'packages/auth/' from commit '1274ad6b0d9c288ab5366e8f3f977e50418166af'
git-subtree-dir: packages/auth
git-subtree-mainline: 6890bbf53f
git-subtree-split: 1274ad6b0d
2020-02-15 18:28:27 -05:00

34 lines
963 B
Dart

import "package:angel_auth/src/auth_token.dart";
import "package:crypto/crypto.dart";
import "package:test/test.dart";
main() async {
final Hmac hmac = Hmac(sha256, "angel_auth".codeUnits);
test("sample serialization", () {
var token = AuthToken(ipAddress: "localhost", userId: "thosakwe");
var jwt = token.serialize(hmac);
print(jwt);
var parsed = AuthToken.validate(jwt, hmac);
print(parsed.toJson());
expect(parsed.toJson()['aud'], equals(token.ipAddress));
expect(parsed.toJson()['sub'], equals(token.userId));
});
test('custom payload', () {
var token = AuthToken(ipAddress: "localhost", userId: "thosakwe", payload: {
"foo": "bar",
"baz": {
"one": 1,
"franken": ["stein"]
}
});
var jwt = token.serialize(hmac);
print(jwt);
var parsed = AuthToken.validate(jwt, hmac);
print(parsed.toJson());
expect(parsed.toJson()['pld'], equals(token.payload));
});
}