line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mojo::Session; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
421590
|
use Mojo::Base 'Test::Mojo'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
4
|
1
|
|
|
1
|
|
4721
|
use Mojo::Util qw(b64_decode hmac_sha1_sum); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
5
|
1
|
|
|
1
|
|
4
|
use Mojo::JSON qw(decode_json); |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
476
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.02'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
1
|
|
|
1
|
1
|
617
|
my $self = shift->SUPER::new(@_); |
11
|
1
|
|
|
|
|
15
|
return $self; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub session_has { |
15
|
1
|
|
|
1
|
1
|
237
|
my ($self, $p, $desc) = @_; |
16
|
1
|
|
33
|
|
|
9
|
$desc //= qq{session has value for JSON Pointer "$p"}; |
17
|
1
|
|
|
|
|
2
|
my $session = $self->_extract_session; |
18
|
1
|
|
|
|
|
10
|
return $self->_test('ok', !!Mojo::JSON::Pointer->new($session)->contains($p), $desc); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub session_hasnt { |
22
|
1
|
|
|
1
|
1
|
441
|
my ($self, $p, $desc) = @_; |
23
|
1
|
|
33
|
|
|
7
|
$desc //= qq{session has no value for JSON Pointer "$p"}; |
24
|
1
|
|
|
|
|
3
|
my $session = $self->_extract_session; |
25
|
1
|
|
|
|
|
7
|
return $self->_test('ok', !Mojo::JSON::Pointer->new($session)->contains($p), $desc); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub session_is { |
29
|
2
|
|
|
2
|
1
|
559
|
my ($self, $p, $data, $desc) = @_; |
30
|
2
|
|
66
|
|
|
9
|
$desc //= qq{session exact match for JSON Pointer "$p"}; |
31
|
2
|
|
|
|
|
4
|
my $session = $self->_extract_session; |
32
|
2
|
|
|
|
|
7
|
return $self->_test('is_deeply', Mojo::JSON::Pointer->new($session)->get($p), $data, $desc); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub session_ok { |
36
|
1
|
|
|
1
|
1
|
42274
|
my $self = shift; |
37
|
1
|
|
|
|
|
6
|
my $session = $self->_extract_session; |
38
|
1
|
|
|
|
|
5
|
return $self->_test('ok', !!$session, 'session ok'); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _extract_session { |
42
|
5
|
|
|
5
|
|
7
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
5
|
|
|
|
|
81
|
my $jar = $self->ua->cookie_jar; |
45
|
5
|
|
|
|
|
113
|
my $app = $self->app; |
46
|
5
|
|
|
|
|
274
|
my $session_name = $app->sessions->cookie_name; |
47
|
|
|
|
|
|
|
|
48
|
5
|
|
|
|
|
118
|
my ($session_cookie) = grep { $_->name eq $session_name } $jar->all; |
|
5
|
|
|
|
|
118
|
|
49
|
5
|
50
|
|
|
|
37
|
return unless $session_cookie; |
50
|
|
|
|
|
|
|
|
51
|
5
|
|
|
|
|
106
|
(my $value = $session_cookie->value) =~ s/--([^\-]+)$//; |
52
|
5
|
|
|
|
|
42
|
my $sign = $1; |
53
|
|
|
|
|
|
|
|
54
|
5
|
|
|
|
|
4
|
my $ok; |
55
|
5
|
|
50
|
|
|
5
|
$sign eq hmac_sha1_sum($value, $_) and $ok = 1 for @{$app->secrets}; |
|
5
|
|
|
|
|
73
|
|
56
|
5
|
50
|
|
|
|
89
|
return unless $ok; |
57
|
|
|
|
|
|
|
|
58
|
5
|
|
|
|
|
11
|
my $session = decode_json(b64_decode $value); |
59
|
5
|
|
|
|
|
1216
|
return $session; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |