SDK/Core/Credential/Sas.pm

filter: Statementstmt 100% 82 / 82 Branchbran 83.3% 35 / 42 Conditioncond 58.3% 42 / 72 MC/DCmcdc 40.5% 15 / 37 Subroutinesub 100% 14 / 14 Podpod 100% 3 / 3 totaltotal 76.4% 191 / 250 CC 49 SCAR 32.9
CC
49
Cov
81%
__ANON__
34.8
apply
31.1
BEGIN
1.0
CRAP 26.8
« SDK/AppConfiguration/ConnectionString.pm ↑ Summary SDK/AppConfiguration/Uri.pm »
1 10 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 10 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 10 ▶use Azure::SDK::Core::Credential;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 class Azure::SDK::Core::Credential::Sas
8 10 :isa(Azure::SDK::Core::Credential) {
9 10 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶ use bytes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 ▶ use URI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶ use URI::Escape qw(uri_unescape);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶ use Azure::SDK::Core::SecretString;
Subroutine BEGIN: called CC=1 SCAR=0.0
14
15 10 ▶ use constant MAX_TOKEN_BYTES => 8 * 1024;
Subroutine BEGIN: called CC=1 SCAR=0.0
16
17 10 field $token :param = undef;
18 10 field $endpoint :param = undef;
19 10 field %sas_keys;
20
21 88 ▶ ADJUST {
Subroutine __ANON__: called CC=25 SCAR=35.5
22 88 ▶ croak 'Azure::SDK::Core::Credential::Sas requires a token'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token and length $token 0 88 88
Condition33%1/3
defined $token and length $token
!ll&&!rl&&r
0088
MC/DC0%0/2
defined $token and length $token
defined $token length $token
Truth table33%1/3
A and B
A= defined $tokenB= length $token
ABresult
0X0
100
111
23 unless defined $token && length $token;
24
25 88 $token =~ s/\A\?//;
26 88 ▶ croak 'SAS token exceeds the maximum size'
Branch: 1 branch
BranchTrueFalseTotal
if &bytes::length($token) > 8192 1 87 88
27 if bytes::length($token) > MAX_TOKEN_BYTES;
28 87 ▶ croak 'SAS token contains invalid characters or percent-escapes'
Branch: 1 branch
BranchTrueFalseTotal
if $token =~ /[\x00-\x20\x7f#?]/u or $token =~ /%(?![0-9A-Fa-f]{2})/u 5 82 87
Condition100%3/3
$token =~ /[\x00-\x20\x7f#?]/u or $token =~ /%(?![0-9A-Fa-f]{2})/u
l!l&&r!l&&!r
1482
MC/DC100%2/2
$token =~ /[\x00-\x20\x7f#?]/u or $token =~ /%(?![0-9A-Fa-f]{2})/u
$token =~ /[\x00-\x20\x7f#?]/u $token =~ /%(?![0-9A-Fa-f]{2})/u
Truth table100%3/3
A or B
A= $token =~ /[\x00-\x20\x7f#?]/uB= $token =~ /%(?![0-9A-Fa-f]{2})/u
ABresult
1X1
011
000
29 if $token =~ /[\x00-\x20\x7f#?]/ || $token =~ /%(?![0-9A-Fa-f]{2})/;
30
31 82 for my $pair (split /&/, $token, -1) {
32 162 ▶ croak 'SAS token contains an invalid query parameter'
Branch: 1 branch
BranchTrueFalseTotal
unless length $pair and $pair =~ /=/u 2 160 162
Condition100%3/3
length $pair and $pair =~ /=/u
!ll&&!rl&&r
11160
MC/DC100%2/2
length $pair and $pair =~ /=/u
length $pair $pair =~ /=/u
Truth table100%3/3
A and B
A= length $pairB= $pair =~ /=/u
ABresult
0X0
100
111
33 unless length $pair && $pair =~ /=/;
34 160 my ($name, $value) = split /=/, $pair, 2;
35 160 my $key = lc uri_unescape($name);
36 160 ▶ croak 'SAS token contains an invalid query parameter'
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ /\A[a-z][a-z0-9]*\z/u and defined $value 0 160 160
Condition33%1/3
$key =~ /\A[a-z][a-z0-9]*\z/u and defined $value
!ll&&!rl&&r
00160
MC/DC0%0/2
$key =~ /\A[a-z][a-z0-9]*\z/u and defined $value
$key =~ /\A[a-z][a-z0-9]*\z/u defined $value
Truth table33%1/3
A and B
A= $key =~ /\A[a-z][a-z0-9]*\z/uB= defined $value
ABresult
0X0
100
111
37 unless $key =~ /\A[a-z][a-z0-9]*\z/ && defined $value;
38 croak 'SAS token contains a repeated query parameter'
39 160 ▶ if $sas_keys{$key}++;
Branch: 1 branch
BranchTrueFalseTotal
if $sas_keys{$key}++ 9 151 160
40 151 ▶ croak 'SAS token requires a signature'
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "sig" and not length $value 4 147 151
Condition100%3/3
$key eq "sig" and not length $value
!ll&&!rl&&r
70774
MC/DC100%2/2
$key eq "sig" and not length $value
$key eq "sig" not length $value
Truth table100%3/3
A and not(B)
A= $key eq "sig"B= not length $value
ABresult
0X0
100
111
41 if $key eq 'sig' && !length $value;
42 }
43 67 ▶ croak 'SAS token requires a signature' unless $sas_keys{sig};
Branch: 1 branch
BranchTrueFalseTotal
unless $sas_keys{"sig"} 1 66 67
44 66 $token = Azure::SDK::Core::SecretString->new(value => $token);
45
46 66 ▶ if (defined $endpoint) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $endpoint) 23 43 66
47 23 my $uri = URI->new($endpoint);
48 23 ▶ croak 'SAS endpoint must be an absolute URL without credentials, query, or fragment'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->host and length $uri->host and not defined $uri->userinfo and not defined $uri->query and not defined $uri->fragment 0 23 23
Condition33%6/18
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->host and length $uri->host and not defined $uri->userinfo and not defined $uri->query and not defined $uri->fragment
!ll&&!rl&&r
0023
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->host and length $uri->host and not defined $uri->userinfo and not defined $uri->query
!ll&&!rl&&r
0023
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->host and length $uri->host and not defined $uri->userinfo
!ll&&!rl&&r
0023
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->host and length $uri->host
!ll&&!rl&&r
0023
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->host
!ll&&!rl&&r
0023
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u
!ll&&!rl&&r
0023
MC/DC0%0/7
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->host and length $uri->host and not defined $uri->userinfo and not defined $uri->query and not defined $uri->fragment
defined $uri->scheme $uri->scheme =~ /\Ahttps?\z/u defined $uri->host length $uri->host not defined $uri->userinfo not defined $uri->query not defined $uri->fragment
Truth table12%1/8
A and B and C and D and not(E) and not(F) and not(G)
A= defined $uri->schemeB= $uri->scheme =~ /\Ahttps?\z/uC= defined $uri->hostD= length $uri->hostE= not defined $uri->userinfoF= not defined $uri->queryG= not defined $uri->fragment
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
49 unless defined $uri->scheme && $uri->scheme =~ /\Ahttps?\z/
50 && defined $uri->host && length $uri->host
51 && !defined $uri->userinfo && !defined $uri->query
52 && !defined $uri->fragment;
53 23 ▶ croak 'SAS endpoint must use HTTPS outside loopback'
Branch: 1 branch
BranchTrueFalseTotal
if $uri->scheme eq "http" and not $uri->host =~ /\A(?:localhost|127\.0\.0\.1|\[?::1\]?)\z/iu 3 20 23
Condition100%3/3
$uri->scheme eq "http" and not $uri->host =~ /\A(?:localhost|127\.0\.0\.1|\[?::1\]?)\z/iu
!ll&&!rl&&r
10103
MC/DC100%2/2
$uri->scheme eq "http" and not $uri->host =~ /\A(?:localhost|127\.0\.0\.1|\[?::1\]?)\z/iu
$uri->scheme eq "http" not $uri->host =~ /\A(?:localhost|127\.0\.0\.1|\[?::1\]?)\z/iu
Truth table100%3/3
A and not(B)
A= $uri->scheme eq "http"B= not $uri->host =~ /\A(?:localhost|127\.0\.0\.1|\[?::1\]?)\z/iu
ABresult
0X0
100
111
54 if $uri->scheme eq 'http'
55 && $uri->host !~ /\A(?:localhost|127\.0\.0\.1|\[?::1\]?)\z/i;
56 20 $endpoint = $uri;
57 }
58 }
59
60 20 ▶ method applies_to_request () {
Subroutine applies_to_request: called CC=1 SCAR=0.0
Pod documented
61 20 return 1;
62 }
63
64 23 ▶ method bound_to ($service_endpoint) {
Subroutine bound_to: called CC=1 SCAR=0.0
Pod documented
65 23 return $self->new(token => $token->reveal, endpoint => $service_endpoint);
66 }
67
68 43 ▶ method apply ($request) {
Subroutine apply: called CC=25 SCAR=34.4
Pod documented
69 43 my $uri = URI->new($request->url);
70 43 my $sas = $token->reveal;
71
72 43 ▶ croak 'SAS target must be an absolute http or https URL with a host'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->host and length $uri->host 0 43 43
Condition33%3/9
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->host and length $uri->host
!ll&&!rl&&r
0043
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->host
!ll&&!rl&&r
0043
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u
!ll&&!rl&&r
0043
MC/DC0%0/4
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->host and length $uri->host
defined $uri->scheme $uri->scheme =~ /\Ahttps?\z/u defined $uri->host length $uri->host
Truth table20%1/5
A and B and C and D
A= defined $uri->schemeB= $uri->scheme =~ /\Ahttps?\z/uC= defined $uri->hostD= length $uri->host
ABCDresult
0XXX0
10XX0
110X0
11100
11111
73 unless defined $uri->scheme && $uri->scheme =~ /\Ahttps?\z/
74 && defined $uri->host && length $uri->host;
75 43 ▶ croak 'SAS target must not include userinfo or a fragment'
Branch: 1 branch
BranchTrueFalseTotal
if defined $uri->userinfo or defined $uri->fragment 2 41 43
Condition100%3/3
defined $uri->userinfo or defined $uri->fragment
l!l&&r!l&&!r
1141
MC/DC100%2/2
defined $uri->userinfo or defined $uri->fragment
defined $uri->userinfo defined $uri->fragment
Truth table100%3/3
A or B
A= defined $uri->userinfoB= defined $uri->fragment
ABresult
1X1
011
000
76 if defined $uri->userinfo || defined $uri->fragment;
77 41 ▶ croak 'SAS target must use HTTPS outside loopback'
Branch: 1 branch
BranchTrueFalseTotal
if $uri->scheme eq "http" and not $uri->host =~ /\A(?:localhost|127\.0\.0\.1|\[?::1\]?)\z/iu 3 38 41
Condition100%3/3
$uri->scheme eq "http" and not $uri->host =~ /\A(?:localhost|127\.0\.0\.1|\[?::1\]?)\z/iu
!ll&&!rl&&r
27113
MC/DC100%2/2
$uri->scheme eq "http" and not $uri->host =~ /\A(?:localhost|127\.0\.0\.1|\[?::1\]?)\z/iu
$uri->scheme eq "http" not $uri->host =~ /\A(?:localhost|127\.0\.0\.1|\[?::1\]?)\z/iu
Truth table100%3/3
A and not(B)
A= $uri->scheme eq "http"B= not $uri->host =~ /\A(?:localhost|127\.0\.0\.1|\[?::1\]?)\z/iu
ABresult
0X0
100
111
78 if $uri->scheme eq 'http'
79 && $uri->host !~ /\A(?:localhost|127\.0\.0\.1|\[?::1\]?)\z/i;
80 38 ▶ if (defined $endpoint) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $endpoint) 31 7 38
81 31 ▶ my $prefix = $endpoint->path // '';
Condition50%1/2
$endpoint->path // ""
l!l
310
MC/DC0%0/1
$endpoint->path // ""
$endpoint->path
Truth table50%1/2
A
A= $endpoint->path
Aresult
11
00
82 31 $prefix =~ s{/+\z}{};
83 31 ▶ my $path = $uri->path // '';
Condition50%1/2
$uri->path // ""
l!l
310
MC/DC0%0/1
$uri->path // ""
$uri->path
Truth table50%1/2
A
A= $uri->path
Aresult
11
00
84 31 ▶ croak 'SAS target does not belong to the credential endpoint'
Branch: 1 branch
BranchTrueFalseTotal
unless lc $uri->scheme eq lc $endpoint->scheme and lc $uri->host eq lc $endpoint->host and $uri->port == $endpoint->port and $path eq $prefix || index($path, "$prefix/") == 0 2 29 31
Condition66%8/12
lc $uri->scheme eq lc $endpoint->scheme and lc $uri->host eq lc $endpoint->host and $uri->port == $endpoint->port and $path eq $prefix || index($path, "$prefix/") == 0
!ll&&!rl&&r
1129
lc $uri->scheme eq lc $endpoint->scheme and lc $uri->host eq lc $endpoint->host and $uri->port == $endpoint->port
!ll&&!rl&&r
0130
lc $uri->scheme eq lc $endpoint->scheme and lc $uri->host eq lc $endpoint->host
!ll&&!rl&&r
0031
$path eq $prefix or index($path, "$prefix/") == 0
l!l&&r!l&&!r
0291
MC/DC40%2/5
lc $uri->scheme eq lc $endpoint->scheme and lc $uri->host eq lc $endpoint->host and $uri->port == $endpoint->port and $path eq $prefix || index($path, "$prefix/") == 0
lc $uri->scheme eq lc $endpoint->scheme lc $uri->host eq lc $endpoint->host $uri->port == $endpoint->port $path eq $prefix index($path, "$prefix/") == 0
Truth table50%3/6
A and B and C and D or E
A= lc $uri->scheme eq lc $endpoint->schemeB= lc $uri->host eq lc $endpoint->hostC= $uri->port == $endpoint->portD= $path eq $prefixE= index($path, "$prefix/") == 0
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
85 unless lc($uri->scheme) eq lc($endpoint->scheme)
86 && lc($uri->host) eq lc($endpoint->host)
87 && $uri->port == $endpoint->port
88 && ($path eq $prefix || index($path, "$prefix/") == 0);
89 }
90
91 36 ▶ my $query = $uri->query // '';
Condition100%2/2
$uri->query // ""
l!l
2313
MC/DC100%1/1
$uri->query // ""
$uri->query
Truth table100%2/2
A
A= $uri->query
Aresult
11
00
92 36 ▶ croak 'SAS target contains an invalid query'
Branch: 1 branch
BranchTrueFalseTotal
if $query =~ /%(?![0-9A-Fa-f]{2})/u 0 36 36
93 if $query =~ /%(?![0-9A-Fa-f]{2})/;
94
95 my %token_pairs = map {
96 36 my ($name) = split /=/, $_, 2;
97 88 lc(uri_unescape($name)) => $_
98 } split /&/, $sas;
99 36 my %seen;
100 my @kept;
101 36 for my $pair (split /&/, $query, -1) {
102 49 ▶ croak 'SAS target contains an invalid query parameter'
Branch: 1 branch
BranchTrueFalseTotal
unless length $pair and $pair =~ /=/u 0 49 49
Condition33%1/3
length $pair and $pair =~ /=/u
!ll&&!rl&&r
0049
MC/DC0%0/2
length $pair and $pair =~ /=/u
length $pair $pair =~ /=/u
Truth table33%1/3
A and B
A= length $pairB= $pair =~ /=/u
ABresult
0X0
100
111
103 unless length $pair && $pair =~ /=/;
104 49 my ($name) = split /=/, $pair, 2;
105 49 my $key = lc uri_unescape($name);
106 croak 'SAS target contains a repeated query parameter'
107 49 ▶ if $seen{$key}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$key}++ 0 49 49
108 49 ▶ if (exists $token_pairs{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $token_pairs{$key}) 33 16 49
109 croak 'SAS target conflicts with the credential'
110 33 ▶ unless $pair eq $token_pairs{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $pair eq $token_pairs{$key} 1 32 33
111 32 next;
112 }
113 16 push @kept, $pair;
114 }
115
116 35 $uri->query(join '&', @kept, $sas);
117 35 $request->set_url($uri->as_string);
118 35 return $request;
119 }
120 }
121
122 10 1;
123
124 __END__
« SDK/AppConfiguration/ConnectionString.pm ↑ Summary SDK/AppConfiguration/Uri.pm »