line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mojo::Session; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
610185
|
use Mojo::Base 'Test::Mojo'; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
9
|
|
4
|
1
|
|
|
1
|
|
6815
|
use Mojo::Util qw(b64_decode hmac_sha1_sum); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
71
|
|
5
|
1
|
|
|
1
|
|
11
|
use Mojo::JSON 'decode_json'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
592
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.06'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
1
|
|
|
1
|
1
|
597
|
my $self = shift->SUPER::new(@_); |
11
|
1
|
|
|
|
|
19
|
return $self; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Compatibility hack for Mojolicious < 8.36 |
15
|
|
|
|
|
|
|
sub test { |
16
|
7
|
50
|
|
7
|
1
|
23080
|
if (Test::Mojo->can('test')) { |
17
|
7
|
|
|
|
|
29
|
return shift->SUPER::test(@_); |
18
|
|
|
|
|
|
|
} |
19
|
0
|
|
|
|
|
0
|
return shift->SUPER::_test(@_); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub session_has { |
23
|
1
|
|
|
1
|
1
|
337
|
my ($self, $p, $desc) = @_; |
24
|
1
|
|
33
|
|
|
15
|
$desc //= qq{session has value for JSON Pointer "$p"}; |
25
|
1
|
|
|
|
|
4
|
my $session = $self->_extract_session; |
26
|
1
|
|
|
|
|
38
|
return $self->test('ok', !!Mojo::JSON::Pointer->new($session)->contains($p), $desc); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub session_hasnt { |
30
|
1
|
|
|
1
|
1
|
380
|
my ($self, $p, $desc) = @_; |
31
|
1
|
|
33
|
|
|
10
|
$desc //= qq{session has no value for JSON Pointer "$p"}; |
32
|
1
|
|
|
|
|
5
|
my $session = $self->_extract_session; |
33
|
1
|
|
|
|
|
32
|
return $self->test('ok', !Mojo::JSON::Pointer->new($session)->contains($p), $desc); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub session_is { |
37
|
2
|
|
|
2
|
1
|
676
|
my ($self, $p, $data, $desc) = @_; |
38
|
2
|
|
66
|
|
|
13
|
$desc //= qq{session exact match for JSON Pointer "$p"}; |
39
|
2
|
|
|
|
|
5
|
my $session = $self->_extract_session; |
40
|
2
|
|
|
|
|
60
|
return $self->test('is_deeply', Mojo::JSON::Pointer->new($session)->get($p), $data, $desc); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub session_ok { |
44
|
1
|
|
|
1
|
1
|
700
|
my $self = shift; |
45
|
1
|
|
|
|
|
6
|
my $session = $self->_extract_session; |
46
|
1
|
|
|
|
|
35
|
return $self->test('ok', !!$session, 'session ok'); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _extract_session { |
50
|
5
|
|
|
5
|
|
10
|
my $self = shift; |
51
|
|
|
|
|
|
|
|
52
|
5
|
|
|
|
|
18
|
my $app = $self->app; |
53
|
5
|
|
|
|
|
110
|
my $sessions = $app->sessions; |
54
|
5
|
|
|
|
|
30
|
my $c = $app->build_controller; |
55
|
5
|
|
|
|
|
406
|
my $name = $sessions->cookie_name; |
56
|
5
|
50
|
|
|
|
24
|
return unless my $cookie = (grep { $_->name eq $name } @{$self->ua->cookie_jar->all})[0]; |
|
5
|
|
|
|
|
97
|
|
|
5
|
|
|
|
|
12
|
|
57
|
|
|
|
|
|
|
|
58
|
5
|
|
|
|
|
70
|
$c->req->cookies($cookie); |
59
|
5
|
|
|
|
|
890
|
$sessions->load($c); |
60
|
5
|
|
|
|
|
3398
|
return $c->session; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |