line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mojo::Session; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
594037
|
use Mojo::Base 'Test::Mojo'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
4
|
1
|
|
|
1
|
|
6049
|
use Mojo::Util qw(b64_decode hmac_sha1_sum); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
5
|
1
|
|
|
1
|
|
6
|
use Mojo::JSON 'decode_json'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
660
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.05'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
1
|
|
|
1
|
1
|
616
|
my $self = shift->SUPER::new(@_); |
11
|
1
|
|
|
|
|
15
|
return $self; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub session_has { |
15
|
1
|
|
|
1
|
1
|
316
|
my ($self, $p, $desc) = @_; |
16
|
1
|
|
33
|
|
|
10
|
$desc //= qq{session has value for JSON Pointer "$p"}; |
17
|
1
|
|
|
|
|
3
|
my $session = $self->_extract_session; |
18
|
1
|
|
|
|
|
14
|
return $self->_test('ok', !!Mojo::JSON::Pointer->new($session)->contains($p), $desc); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub session_hasnt { |
22
|
1
|
|
|
1
|
1
|
747
|
my ($self, $p, $desc) = @_; |
23
|
1
|
|
33
|
|
|
10
|
$desc //= qq{session has no value for JSON Pointer "$p"}; |
24
|
1
|
|
|
|
|
12
|
my $session = $self->_extract_session; |
25
|
1
|
|
|
|
|
9
|
return $self->_test('ok', !Mojo::JSON::Pointer->new($session)->contains($p), $desc); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub session_is { |
29
|
2
|
|
|
2
|
1
|
737
|
my ($self, $p, $data, $desc) = @_; |
30
|
2
|
|
66
|
|
|
13
|
$desc //= qq{session exact match for JSON Pointer "$p"}; |
31
|
2
|
|
|
|
|
6
|
my $session = $self->_extract_session; |
32
|
2
|
|
|
|
|
10
|
return $self->_test('is_deeply', Mojo::JSON::Pointer->new($session)->get($p), $data, $desc); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub session_ok { |
36
|
1
|
|
|
1
|
1
|
19302
|
my $self = shift; |
37
|
1
|
|
|
|
|
5
|
my $session = $self->_extract_session; |
38
|
1
|
|
|
|
|
6
|
return $self->_test('ok', !!$session, 'session ok'); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _extract_session { |
42
|
5
|
|
|
5
|
|
11
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
5
|
|
|
|
|
19
|
my $app = $self->app; |
45
|
5
|
|
|
|
|
106
|
my $session_name = $app->sessions->cookie_name; |
46
|
|
|
|
|
|
|
|
47
|
5
|
|
|
|
|
42
|
my @cookies = $self->ua->cookie_jar->all; |
48
|
5
|
50
|
|
|
|
99
|
@cookies = @{$cookies[0]} if ref $cookies[0] eq 'ARRAY'; |
|
5
|
|
|
|
|
12
|
|
49
|
5
|
|
|
|
|
11
|
my ($session_cookie) = grep { $_->name eq $session_name } @cookies; |
|
5
|
|
|
|
|
15
|
|
50
|
5
|
50
|
|
|
|
58
|
return unless $session_cookie; |
51
|
|
|
|
|
|
|
|
52
|
5
|
|
|
|
|
32
|
(my $value = $session_cookie->value) =~ s/--([^\-]+)$//; |
53
|
5
|
|
|
|
|
60
|
my $sign = $1; |
54
|
|
|
|
|
|
|
|
55
|
5
|
|
|
|
|
8
|
my $ok; |
56
|
5
|
|
|
|
|
9
|
for (@{$app->secrets}) { |
|
5
|
|
|
|
|
15
|
|
57
|
|
|
|
|
|
|
|
58
|
5
|
50
|
33
|
|
|
109
|
if ( |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Mojolicious < 8.13 |
61
|
|
|
|
|
|
|
$sign eq hmac_sha1_sum($value, $_) || |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Mojolicious >= 8.13 |
64
|
|
|
|
|
|
|
$sign eq hmac_sha1_sum("$session_name=$value", $_) |
65
|
|
|
|
|
|
|
) { |
66
|
5
|
|
|
|
|
10
|
$ok = 1; |
67
|
5
|
|
|
|
|
10
|
last; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
5
|
50
|
|
|
|
17
|
return unless $ok; |
71
|
|
|
|
|
|
|
|
72
|
5
|
|
|
|
|
29
|
my $session = decode_json(b64_decode $value); |
73
|
5
|
|
|
|
|
1033
|
return $session; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__END__ |