/
Util.pm6
41 lines (34 loc) · 830 Bytes
/
Util.pm6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use v6;
unit package t::Util;
use Test;
use JSON::WebToken;
sub test_encode_decode is export {
my %specs = @_;
my ($desc, $input, $expects_exception) =
%specs{qw/desc input expects_exception/};
my ($claims, $secret, $public_key, $algorithm, $header_fields) =
$input{qw/claims secret public_key algorithm header_fields/};
$public_key ||= $secret;
my $test = sub {
my $jwt = encode_jwt $claims, $secret, $algorithm, $header_fields;
return decode_jwt $jwt, $public_key, $algorithm;
};
# subtest $desc => sub {
subtest {
if (!$expects_exception) {
my $got = $test();
is-deeply $got, $claims;
}
else {
{
$test();
CATCH {
default {
like $_.message, rx/$expects_exception/;
}
}
};
}
};
}
=finish