blib/lib/Plack/Middleware/SignedCookies.pm

filter: Statementstmt 100% 47 / 47 Branchbran 85.0% 17 / 20 Conditioncond 75.0% 9 / 12 MC/DCmcdc 62.5% 5 / 8 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 91.0% 91 / 100 CC 17 SCAR 16.3
CC
17
Cov
92%
__ANON__
9.0
call
6.0
prepare_app
3.1
CRAP 5.1
↑ Summary
1 1 ▶use 5.006; use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Plack::Middleware::SignedCookies;
4  
5 1 our $VERSION = '1.204';
6  
7 1 ▶BEGIN { require Plack::Middleware; our @ISA = 'Plack::Middleware' }
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Plack::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Plack::Util::Accessor qw( secret secure httponly );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Digest::SHA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 65 ▶sub _hmac { y{+/}{-~}, return $_ for &Digest::SHA::hmac_sha256_base64 }
Subroutine _hmac: called CC=2 SCAR=6.9
14  
15 1 my $length = length _hmac 'something', 'something';
16  
17 9 ▶sub call {
Subroutine call: called CC=6 SCAR=18.0
Pod documented
18 9 my ( $self, $env ) = ( shift, @_ );
19  
20 9 my $secret = $self->secret;
21  
22 9 my $orig = delete $env->{'HTTP_COOKIE'};
23 9 ▶ $env->{'signedcookies.orig'} = $orig if defined $orig;
Branch: 1 branch
BranchTrueFalseTotal
if defined $orig 9 0 9
24  
25 my $cookie =
26 join '; ',
27 21 ▶ grep { s/[ \t]*=[ \t]*/=/; s/[ \t]*([-~A-Za-z0-9]{$length})\z//o and $1 eq _hmac $_, $secret }
Condition66%2/3
s/[ \t]*([-~A-Za-z0-9]{$length})\z//o && $1 eq _hmac($_, $secret)
!ll&&!rl&&r
2019
MC/DC50%1/2
s/[ \t]*([-~A-Za-z0-9]{$length})\z//o && $1 eq _hmac($_, $secret)
s/[ \t]*([-~A-Za-z0-9]{$length})\z//o $1 eq _hmac($_, $secret)
Truth table66%2/3
A && B
A= s/[ \t]*([-~A-Za-z0-9]{$length})\z//oB= $1 eq _hmac($_, $secret)
ABresult
0X0
100
111
28 9 ▶ map { defined && /\A[ \t]*(.*[^ \t])/s ? split /[ \t]*;[ \t]*/, "$1" : () }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && /\A[ \t]*(.*[^ \t])/s ? : 5 4 9
Condition66%2/3
defined $_ and /\A[ \t]*(.*[^ \t])/s
!ll&&!rl&&r
045
MC/DC50%1/2
defined $_ and /\A[ \t]*(.*[^ \t])/s
defined $_ /\A[ \t]*(.*[^ \t])/s
Truth table66%2/3
A and B
A= defined $_B= /\A[ \t]*(.*[^ \t])/s
ABresult
0X0
100
111
29 $orig;
30  
31 9 ▶ $env->{'HTTP_COOKIE'} = $cookie if '' ne $cookie;
Branch: 1 branch
BranchTrueFalseTotal
if "" ne $cookie 4 5 9
32  
33 9 ▶ return Plack::Util::response_cb( $self->app->( $env ), sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
34 9 my $do_sign;
35 9 for ( @{ $_[0][1] } ) {
36 90 ▶ if ( $do_sign ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do_sign) 45 45 90
37 45 ▶ my $flags = s/(;.*)//s ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
s/(;.*)//s ? : 7 38 45
38 45 s/\A[ \t]+//, s/[ \t]+\z//, s/[ \t]*=[ \t]*|\z/=/; # normalise
39 45 $_ .= ' ' . _hmac( $_, $secret ) . $flags;
40 45 ▶ $_ .= '; secure' if $self->secure and $flags !~ /;[ \t]* secure [ \t]* (?![^;])/ix;
Branch: 1 branch
BranchTrueFalseTotal
if $self->secure and not $flags =~ /;[ \t]* secure [ \t]* (?![^;])/xi 18 27 45
Condition100%3/3
$self->secure and not $flags =~ /;[ \t]* secure [ \t]* (?![^;])/xi
!ll&&!rl&&r
25218
MC/DC100%2/2
$self->secure and not $flags =~ /;[ \t]* secure [ \t]* (?![^;])/xi
$self->secure not $flags =~ /;[ \t]* secure [ \t]* (?![^;])/xi
Truth table100%3/3
A and not(B)
A= $self->secureB= not $flags =~ /;[ \t]* secure [ \t]* (?![^;])/xi
ABresult
0X0
100
111
41 45 ▶ $_ .= '; HTTPonly' if $self->httponly and $flags !~ /;[ \t]* httponly [ \t]* (?![^;])/ix;
Branch: 1 branch
BranchTrueFalseTotal
if $self->httponly and not $flags =~ /;[ \t]* httponly [ \t]* (?![^;])/xi 25 20 45
Condition66%2/3
$self->httponly and not $flags =~ /;[ \t]* httponly [ \t]* (?![^;])/xi
!ll&&!rl&&r
20025
MC/DC50%1/2
$self->httponly and not $flags =~ /;[ \t]* httponly [ \t]* (?![^;])/xi
$self->httponly not $flags =~ /;[ \t]* httponly [ \t]* (?![^;])/xi
Truth table66%2/3
A and not(B)
A= $self->httponlyB= not $flags =~ /;[ \t]* httponly [ \t]* (?![^;])/xi
ABresult
0X0
100
111
42 }
43 90 ▶ $do_sign = defined $do_sign ? undef : 'set-cookie' eq lc;
Branch: 1 branch
BranchTrueFalseTotal
defined $do_sign ? : 45 45 90
44 }
45 9 } );
46 }
47  
48 1 ▶sub prepare_app {
Subroutine prepare_app: called CC=3 SCAR=11.4
Pod documented
49 1 my $self = shift;
50 1 ▶ defined $self->httponly or $self->httponly( 1 );
Branch: 1 branch
BranchTrueFalseTotal
defined $self->httponly or $self->httponly(1) 0 1 1
51 1 ▶ defined $self->secret or $self->secret ( join '', map { chr int rand 256 } 1..17 );
Branch: 1 branch
BranchTrueFalseTotal
defined $self->secret or $self->secret(join("", map({chr int rand 256;} 1..17))) 0 1 1
52 }
53  
54 1 1;
55  
56 __END__
↑ Summary