Lite/Provider/AssociationBuilder.pm

filter: Statementstmt 100% 56 / 56 Branchbran 58.3% 14 / 24 Conditioncond 47.0% 16 / 34 MC/DCmcdc 11.1% 2 / 18 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 3 totaltotal 67.3% 97 / 144 CC 25 SCAR 25.2
CC
25
Cov
75%
secret_of_handle
20.8
build_from_handle
12.1
build_association
6.1
CRAP 12.4
« Lite/Provider/Discover.pm ↑ Summary Lite/RelyingParty/Discover/Service.pm »
1 package OpenID::Lite::Provider::AssociationBuilder;
2  
3 2 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Digest::SHA;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use String::Random;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use OpenID::Lite::Association;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use OpenID::Lite::SignatureMethods;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 with 'OpenID::Lite::Role::ErrorHandler';
9  
10 2 has 'server_secret' => (
11 is => 'ro',
12 isa => 'Str',
13 default => q{secret},
14 );
15  
16 2 has 'secret_lifetime' => (
17 is => 'ro',
18 isa => 'Int',
19 default => 86400,
20 );
21  
22 #has 'secret_gen_interval' => (
23 # is => 'ro',
24 # isa => 'Int',
25 # default => 86400,
26 #);
27 #
28 #has 'get_server_secret' => (
29 # is => 'ro',
30 # isa => 'CodeRef',
31 # default => sub {
32 # sub {
33 # my $sec_time = shift;
34 # my $secret = '';
35 # return $secret;
36 # }
37 # },
38 #);
39 #
40  
41 12 ▶sub build_association {
Subroutine build_association: called CC=6 SCAR=18.1
Pod undocumented
42 12 my $self = shift;
43 12 my %opts = @_;
44 12 my $type = $opts{type};
45 12 ▶ my $dumb = $opts{dumb} || 0;
Condition100%2/2
$opts{'dumb'} || 0
l!l
66
MC/DC100%1/1
$opts{'dumb'} || 0
$opts{'dumb'}
Truth table100%2/2
A
A= $opts{'dumb'}
Aresult
11
00
46 12 ▶ my $lifetime = $opts{lifetime} || $self->secret_lifetime;
Condition33%1/3
$opts{'lifetime'} || $self->secret_lifetime
l!l&&r!l&&!r
0120
MC/DC0%0/2
$opts{'lifetime'} || $self->secret_lifetime
$opts{'lifetime'} $self->secret_lifetime
Truth table33%1/3
A || B
A= $opts{'lifetime'}B= $self->secret_lifetime
ABresult
1X1
011
000
47  
48 12 ▶ my $signature_method
Branch: 1 branch
BranchTrueFalseTotal
my $signature_method = "OpenID::Lite::SignatureMethods"->select_method($type) or return $self->ERROR(sprintf('Invalid assoc_type "%s"', $type)) 12 0 12
49 = OpenID::Lite::SignatureMethods->select_method($type)
50 or return $self->ERROR( sprintf q{Invalid assoc_type "%s"}, $type );
51  
52 12 my $now = time();
53 #my $sec_time = $now - ( $now % $self->secret_gen_interval );
54 #my $s_sec = $self->get_server_secret->($sec_time)
55 # || $self->server_secret;
56 12 my $s_sec = $self->server_secret;
57  
58 12 my $random = String::Random->new;
59 12 my $nonce = $random->randregex( sprintf '[a-zA-Z0-9]{%d}', 20 );
60 12 ▶ $nonce = sprintf( q{STLS.%s}, $nonce ) if $dumb;
Branch: 1 branch
BranchTrueFalseTotal
if $dumb 6 6 12
61  
62 12 my $handle = sprintf( q{%d:%s:%s}, $now, $type, $nonce );
63 12 $handle
64 .= ":"
65 . substr( $signature_method->hmac_hash_hex( $handle, $s_sec ), 0,
66 10 );
67 12 ▶ my $c_sec = $self->secret_of_handle( $handle, $dumb, 1 )
Branch: 1 branch
BranchTrueFalseTotal
my $c_sec = $self->secret_of_handle($handle, $dumb, 1) or return 12 0 12
68 or return;
69  
70 12 my $assoc = OpenID::Lite::Association->new(
71 secret => $c_sec,
72 handle => $handle,
73 type => $type,
74 expires_in => $lifetime,
75 issued => $now
76 );
77 12 return $assoc;
78 }
79  
80 4 ▶sub build_from_handle {
Subroutine build_from_handle: called CC=8 SCAR=24.9
Pod undocumented
81 4 my ( $self, $handle, $opts ) = @_;
82  
83 4 ▶ my $dumb = $opts->{dumb} || 0;
Condition100%2/2
$opts->{'dumb'} || 0
l!l
22
MC/DC100%1/1
$opts->{'dumb'} || 0
$opts->{'dumb'}
Truth table100%2/2
A
A= $opts->{'dumb'}
Aresult
11
00
84 4 ▶ my $lifetime = $opts->{lifetime} || $self->secret_lifetime;
Condition33%1/3
$opts->{'lifetime'} || $self->secret_lifetime
l!l&&r!l&&!r
040
MC/DC0%0/2
$opts->{'lifetime'} || $self->secret_lifetime
$opts->{'lifetime'} $self->secret_lifetime
Truth table33%1/3
A || B
A= $opts->{'lifetime'}B= $self->secret_lifetime
ABresult
1X1
011
000
85 4 my ( $time, $type, $nonce, $nonce_sig80 ) = split( /:/, $handle );
86 4 ▶ return $self->ERROR(q{not found proper time,type,nonce and nonce_sig80})
Branch: 1 branch
BranchTrueFalseTotal
unless $time =~ /^\d+$/ and $type and $nonce and $nonce_sig80 0 4 4
Condition33%3/9
$time =~ /^\d+$/ and $type and $nonce and $nonce_sig80
!ll&&!rl&&r
004
$time =~ /^\d+$/ and $type and $nonce
!ll&&!rl&&r
004
$time =~ /^\d+$/ and $type
!ll&&!rl&&r
004
MC/DC0%0/4
$time =~ /^\d+$/ and $type and $nonce and $nonce_sig80
$time =~ /^\d+$/ $type $nonce $nonce_sig80
Truth table20%1/5
A and B and C and D
A= $time =~ /^\d+$/B= $typeC= $nonceD= $nonce_sig80
ABCDresult
0XXX0
10XX0
110X0
11100
11111
87 unless $time =~ /^\d+$/ && $type && $nonce && $nonce_sig80;
88  
89 4 ▶ my $secret = $self->secret_of_handle( $handle, $dumb )
Branch: 1 branch
BranchTrueFalseTotal
my $secret = $self->secret_of_handle($handle, $dumb) or return 4 0 4
90 or return;
91  
92 4 return OpenID::Lite::Association->new(
93 secret => $secret,
94 handle => $handle,
95 type => $type,
96 issued => $time,
97 expires_in => $lifetime,
98 );
99  
100 }
101  
102 20 ▶sub secret_of_handle {
Subroutine secret_of_handle: called CC=13 SCAR=30.4
Pod undocumented
103 20 my ( $self, $handle, $dumb, $no_verify ) = @_;
104 20 my ( $time, $type, $nonce, $nonce_sig80 ) = split( /:/, $handle );
105 20 ▶ return $self->ERROR(q{not found proper time,type,nonce and nonce_sig80})
Branch: 1 branch
BranchTrueFalseTotal
unless $time =~ /^\d+$/ and $type and $nonce and $nonce_sig80 0 20 20
Condition33%3/9
$time =~ /^\d+$/ and $type and $nonce and $nonce_sig80
!ll&&!rl&&r
0020
$time =~ /^\d+$/ and $type and $nonce
!ll&&!rl&&r
0020
$time =~ /^\d+$/ and $type
!ll&&!rl&&r
0020
MC/DC0%0/4
$time =~ /^\d+$/ and $type and $nonce and $nonce_sig80
$time =~ /^\d+$/ $type $nonce $nonce_sig80
Truth table20%1/5
A and B and C and D
A= $time =~ /^\d+$/B= $typeC= $nonceD= $nonce_sig80
ABCDresult
0XXX0
10XX0
110X0
11100
11111
106 unless $time =~ /^\d+$/ && $type && $nonce && $nonce_sig80;
107 20 ▶ return $self->ERROR(q{nonce is invalid for dumb-mode})
Branch: 1 branch
BranchTrueFalseTotal
if $dumb and not $nonce =~ /^STLS\./ 0 20 20
Condition66%2/3
$dumb and not $nonce =~ /^STLS\./
!ll&&!rl&&r
10100
MC/DC0%0/2
$dumb and not $nonce =~ /^STLS\./
$dumb not $nonce =~ /^STLS\./
Truth table66%2/3
A and not(B)
A= $dumbB= not $nonce =~ /^STLS\./
ABresult
0X0
100
111
108 if $dumb && $nonce !~ /^STLS\./;
109 20 ▶ my $signature_method
Branch: 1 branch
BranchTrueFalseTotal
my $signature_method = "OpenID::Lite::SignatureMethods"->select_method($type) or return $self->ERROR(sprintf('Invalid assoc_type, "%s"', $type)) 20 0 20
110 = OpenID::Lite::SignatureMethods->select_method($type)
111 or return $self->ERROR( sprintf q{Invalid assoc_type, "%s"}, $type );
112  
113 #my $sec_time = $time - ( $time % $self->secret_gen_interval );
114 #my $s_sec = $self->get_server_secret->($sec_time)
115 # || $self->server_secret;
116 20 my $s_sec = $self->server_secret;
117  
118 20 ▶ length($nonce) == ( $dumb ? 25 : 20 )
Branch: 2 branches
BranchTrueFalseTotal
length $nonce == ($dumb ? 25 : 20) or return $self->ERROR("Invalid nonce length") 20 0 20
$dumb ? : 10 10 20
119 or return $self->ERROR(q{Invalid nonce length});
120 20 ▶ length($nonce_sig80) == 10
Branch: 1 branch
BranchTrueFalseTotal
length $nonce_sig80 == 10 or return $self->ERROR("Invalid nonce_sig80 length") 20 0 20
121 or return $self->ERROR(q{Invalid nonce_sig80 length});
122  
123 20 ▶ return $self->ERROR(q{Failed to verify nonce_sig80.})
Branch: 1 branch
BranchTrueFalseTotal
unless $no_verify or $nonce_sig80 eq substr($signature_method->hmac_hash_hex(sprintf("%d:%s:%s", $time, $type, $nonce), $s_sec), 0, 10) 0 20 20
Condition66%2/3
$no_verify or $nonce_sig80 eq substr($signature_method->hmac_hash_hex(sprintf("%d:%s:%s", $time, $type, $nonce), $s_sec), 0, 10)
l!l&&r!l&&!r
1280
MC/DC0%0/2
$no_verify or $nonce_sig80 eq substr($signature_method->hmac_hash_hex(sprintf("%d:%s:%s", $time, $type, $nonce), $s_sec), 0, 10)
$no_verify $nonce_sig80 eq substr($signature_method->hmac_hash_hex(sprintf("%d:%s:%s", $time, $type, $nonce), $s_sec), 0, 10)
Truth table66%2/3
A or B
A= $no_verifyB= $nonce_sig80 eq substr($signature_method->hmac_hash_hex(sprintf("%d:%s:%s", $time, $type, $nonce), $s_sec), 0, 10)
ABresult
1X1
011
000
124 unless $no_verify
125 || $nonce_sig80 eq substr(
126 $signature_method->hmac_hash_hex(
127 sprintf( q{%d:%s:%s}, $time, $type, $nonce ), $s_sec
128 ),
129 0, 10
130 );
131 20 return $signature_method->hmac_hash( $handle, $s_sec );
132 }
133  
134 2 ▶no Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
135 2 __PACKAGE__->meta->make_immutable;
136 2 1;
137  
« Lite/Provider/Discover.pm ↑ Summary Lite/RelyingParty/Discover/Service.pm »