SDK/AppConfiguration/Hmac.pm

filter: Statementstmt 100% 63 / 63 Branchbran 50.0% 8 / 16 Conditioncond 41.3% 12 / 29 MC/DCmcdc 6.6% 1 / 15 Subroutinesub 100% 14 / 14 Podpod 100% 2 / 2 totaltotal 71.9% 100 / 139 CC 20 SCAR 25.4
CC
20
Cov
77%
__ANON__
28.5
send
7.8
string_to_sign
3.0
CRAP 12.6
« SDK/Storage/Queues/SharedKey.pm ↑ Summary SDK/Storage/Blobs/ConnectionString.pm »
1 5 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 5 ▶use Azure::SDK::Core::Policy;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 5 class Azure::SDK::AppConfiguration::Hmac :isa(Azure::SDK::Core::Policy) {
8 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶ use Digest::SHA qw(hmac_sha256 sha256);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶ use MIME::Base64 qw(decode_base64 encode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶ use URI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶ use Azure::SDK::Core::SecretString;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶ use Azure::SDK::Core::Transport::Default ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14
15 5 field $credential_id :param = undef;
16 5 field $credential_secret :param = undef;
17 5 field $clock :param = undef;
18
19 9 ▶ ADJUST {
Subroutine __ANON__: called CC=12 SCAR=33.5
20 9 ▶ croak 'Azure::SDK::AppConfiguration::Hmac requires a credential_id'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $credential_id and not ref $credential_id and length $credential_id 0 9 9
Condition33%2/6
defined $credential_id and not ref $credential_id and length $credential_id
!ll&&!rl&&r
009
defined $credential_id and not ref $credential_id
!ll&&!rl&&r
009
MC/DC0%0/3
defined $credential_id and not ref $credential_id and length $credential_id
defined $credential_id not ref $credential_id length $credential_id
Truth table25%1/4
A and not(B) and C
A= defined $credential_idB= not ref $credential_idC= length $credential_id
ABCresult
0XX0
10X0
1100
1111
21 unless defined $credential_id && !ref $credential_id
22 && length $credential_id;
23 9 ▶ croak 'Azure::SDK::AppConfiguration::Hmac requires a credential_secret'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $credential_secret and not ref $credential_secret and length $credential_secret 0 9 9
Condition33%2/6
defined $credential_secret and not ref $credential_secret and length $credential_secret
!ll&&!rl&&r
009
defined $credential_secret and not ref $credential_secret
!ll&&!rl&&r
009
MC/DC0%0/3
defined $credential_secret and not ref $credential_secret and length $credential_secret
defined $credential_secret not ref $credential_secret length $credential_secret
Truth table25%1/4
A and not(B) and C
A= defined $credential_secretB= not ref $credential_secretC= length $credential_secret
ABCresult
0XX0
10X0
1100
1111
24 unless defined $credential_secret && !ref $credential_secret
25 && length $credential_secret;
26 9 ▶ croak 'App Configuration HMAC credential id contains control characters'
Branch: 1 branch
BranchTrueFalseTotal
if $credential_id =~ /[\x00-\x1f\x7f]/u 0 9 9
27 if $credential_id =~ /[\x00-\x1f\x7f]/;
28 9 ▶ croak 'App Configuration HMAC credential secret is not valid base64'
Branch: 1 branch
BranchTrueFalseTotal
unless $credential_secret =~ m[\A[A-Za-z0-9+/]+={0,2}\z]u and length($credential_secret) % 4 == 0 and length &decode_base64($credential_secret) 0 9 9
Condition33%2/6
$credential_secret =~ m[\A[A-Za-z0-9+/]+={0,2}\z]u and length($credential_secret) % 4 == 0 and length &decode_base64($credential_secret)
!ll&&!rl&&r
009
$credential_secret =~ m[\A[A-Za-z0-9+/]+={0,2}\z]u and length($credential_secret) % 4 == 0
!ll&&!rl&&r
009
MC/DC0%0/3
$credential_secret =~ m[\A[A-Za-z0-9+/]+={0,2}\z]u and length($credential_secret) % 4 == 0 and length &decode_base64($credential_secret)
$credential_secret =~ m[\A[A-Za-z0-9+/]+={0,2}\z]u length($credential_secret) % 4 == 0 length &decode_base64($credential_secret)
Truth table25%1/4
A and B and C
A= $credential_secret =~ m[\A[A-Za-z0-9+/]+={0,2}\z]uB= length($credential_secret) % 4 == 0C= length &decode_base64($credential_secret)
ABCresult
0XX0
10X0
1100
1111
29 unless $credential_secret =~ m{\A[A-Za-z0-9+/]+={0,2}\z}
30 && length($credential_secret) % 4 == 0
31 && length(decode_base64($credential_secret));
32
33 9 $credential_secret = Azure::SDK::Core::SecretString->new(
34 value => $credential_secret,
35 );
36 9 ▶ $clock //= sub { time };
Condition66%2/3
$clock //= sub { time; }
l!l&&r!l&&!r
810
MC/DC0%0/2
$clock //= sub { time; }
$clock sub { time; }
Truth table66%2/3
A //= B
A= $clockB= sub { time; }
ABresult
1X1
011
000
37 }
38
39 9 ▶ method send ($context, $request, $next) {
Subroutine send: called CC=7 SCAR=20.5
Pod documented
40 9 my $uri = URI->new($request->url);
41 9 ▶ croak 'App Configuration HMAC request URL must be absolute HTTP(S)'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->authority 0 9 9
Condition33%2/6
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->authority
!ll&&!rl&&r
009
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u
!ll&&!rl&&r
009
MC/DC0%0/3
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->authority
defined $uri->scheme $uri->scheme =~ /\Ahttps?\z/u defined $uri->authority
Truth table25%1/4
A and B and C
A= defined $uri->schemeB= $uri->scheme =~ /\Ahttps?\z/uC= defined $uri->authority
ABCresult
0XX0
10X0
1100
1111
42 unless defined $uri->scheme && $uri->scheme =~ /\Ahttps?\z/
43 && defined $uri->authority;
44
45 9 ▶ my $body = $request->body // '';
Condition100%2/2
$request->body // ""
l!l
72
MC/DC100%1/1
$request->body // ""
$request->body
Truth table100%2/2
A
A= $request->body
Aresult
11
00
46 9 ▶ utf8::encode($body) if utf8::is_utf8($body);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($body) 0 9 9
47 9 my $content_hash = encode_base64(sha256($body), '');
48 9 my $timestamp = _http_date($clock->());
49
50 9 my $host = Azure::SDK::Core::Transport::Default::wire_host($request->url);
51 9 ▶ croak 'App Configuration HMAC request URL must be absolute HTTP(S)'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 0 9 9
52 unless defined $host;
53 9 $request->set_header('Host', $host);
54 9 $request->set_header('x-ms-date', $timestamp);
55 9 $request->set_header('x-ms-content-sha256', $content_hash);
56
57 9 my $signature = encode_base64(
58 hmac_sha256(
59 $self->string_to_sign($request),
60 decode_base64($credential_secret->reveal),
61 ),
62 '',
63 );
64 9 $request->set_header(
65 'Authorization',
66 'HMAC-SHA256 Credential=' . $credential_id
67 . '&SignedHeaders=x-ms-date;host;x-ms-content-sha256'
68 . '&Signature=' . $signature,
69 );
70 9 return $next->($context, $request);
71 }
72
73 10 ▶ method string_to_sign ($request) {
Subroutine string_to_sign: called CC=3 SCAR=11.1
Pod documented
74 10 my $uri = URI->new($request->url);
75 10 for my $header (qw(x-ms-date host x-ms-content-sha256)) {
76 30 ▶ croak "App Configuration HMAC request is missing '$header'"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $request->header($header) 0 30 30
77 unless defined $request->header($header);
78 }
79 return join(
80 "\n",
81 $request->method,
82 $uri->path_query,
83 join(
84 ';',
85 10 map { $request->header($_) }
86 qw(x-ms-date host x-ms-content-sha256),
87 ),
88 );
89 }
90
91 9 ▶ sub _http_date ($epoch) {
Subroutine _http_date: called CC=1 SCAR=0.0
92 9 my @weekdays = qw(Sun Mon Tue Wed Thu Fri Sat);
93 9 my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
94 9 my ($second, $minute, $hour, $day, $month, $year, $weekday) = gmtime($epoch);
95 9 return sprintf(
96 '%s, %02d %s %04d %02d:%02d:%02d GMT',
97 $weekdays[$weekday],
98 $day,
99 $months[$month],
100 $year + 1900,
101 $hour,
102 $minute,
103 $second,
104 );
105 }
106 }
107
108 5 1;
109
110 __END__
« SDK/Storage/Queues/SharedKey.pm ↑ Summary SDK/Storage/Blobs/ConnectionString.pm »