SDK/AppConfiguration/ConnectionString.pm

filter: Statementstmt 100% 76 / 76 Branchbran 75.0% 36 / 48 Conditioncond 47.4% 28 / 59 MC/DCmcdc 18.7% 6 / 32 Subroutinesub 100% 15 / 15 Podpod 100% 3 / 3 totaltotal 70.3% 164 / 233 CC 47 SCAR 34.8
CC
47
Cov
77%
__ANON__
58.1
parse
18.1
_looks_like_base64
4.2
CRAP 32.4
« SDK/Storage/Tables/EntityProperty.pm ↑ Summary SDK/Core/Credential/Sas.pm »
1 3 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 3 ▶use Azure::SDK::AppConfiguration::Hmac;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Azure::SDK::Core::SecretString;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 3 class Azure::SDK::AppConfiguration::ConnectionString {
9 3 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶ use bytes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶ use MIME::Base64 qw(decode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶ use URI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13
14 3 ▶ use constant MAX_LENGTH => 8 * 1024;
Subroutine BEGIN: called CC=1 SCAR=0.0
15
16 3 field $endpoint :param :reader = undef;
17 3 field $credential_id :param = undef;
18 3 field $credential_secret :param = undef;
19
20 3 field $is_emulator :reader = 0;
21 3 field $signer = undef;
22
23 20 ▶ ADJUST {
Subroutine __ANON__: called CC=29 SCAR=40.6
24 20 ▶ croak 'Azure::SDK::AppConfiguration::ConnectionString requires an endpoint'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $endpoint and not ref $endpoint and length $endpoint 0 20 20
Condition33%2/6
defined $endpoint and not ref $endpoint and length $endpoint
!ll&&!rl&&r
0020
defined $endpoint and not ref $endpoint
!ll&&!rl&&r
0020
MC/DC0%0/3
defined $endpoint and not ref $endpoint and length $endpoint
defined $endpoint not ref $endpoint length $endpoint
Truth table25%1/4
A and not(B) and C
A= defined $endpointB= not ref $endpointC= length $endpoint
ABCresult
0XX0
10X0
1100
1111
25 unless defined $endpoint && !ref $endpoint && length $endpoint;
26 20 ▶ croak 'Azure::SDK::AppConfiguration::ConnectionString requires a credential_id'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $credential_id and not ref $credential_id and length $credential_id 0 20 20
Condition33%2/6
defined $credential_id and not ref $credential_id and length $credential_id
!ll&&!rl&&r
0020
defined $credential_id and not ref $credential_id
!ll&&!rl&&r
0020
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
27 unless defined $credential_id && !ref $credential_id && length $credential_id;
28 20 ▶ croak 'Azure::SDK::AppConfiguration::ConnectionString requires a credential_secret'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $credential_secret and not ref $credential_secret and length $credential_secret 0 20 20
Condition33%2/6
defined $credential_secret and not ref $credential_secret and length $credential_secret
!ll&&!rl&&r
0020
defined $credential_secret and not ref $credential_secret
!ll&&!rl&&r
0020
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
29 unless defined $credential_secret && !ref $credential_secret
30 && length $credential_secret;
31 20 ▶ croak 'App Configuration credential id contains control characters'
Branch: 1 branch
BranchTrueFalseTotal
if $credential_id =~ /[\x00-\x1f\x7f]/u 0 20 20
32 if $credential_id =~ /[\x00-\x1f\x7f]/;
33 20 ▶ croak 'App Configuration credential id exceeds 1024 bytes'
Branch: 1 branch
BranchTrueFalseTotal
if &bytes::length($credential_id) > 1024 0 20 20
34 if bytes::length($credential_id) > 1024;
35 20 ▶ croak 'App Configuration credential secret is not valid base64'
Branch: 1 branch
BranchTrueFalseTotal
unless _looks_like_base64($credential_secret) 1 19 20
36 unless _looks_like_base64($credential_secret);
37
38 19 my $uri = URI->new($endpoint);
39 19 ▶ croak 'App Configuration endpoint must be an absolute http or https URI'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->host and length $uri->host 0 19 19
Condition33%3/9
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->host and length $uri->host
!ll&&!rl&&r
0019
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u and defined $uri->host
!ll&&!rl&&r
0019
defined $uri->scheme and $uri->scheme =~ /\Ahttps?\z/u
!ll&&!rl&&r
0019
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
40 unless defined $uri->scheme && $uri->scheme =~ /\Ahttps?\z/
41 && defined $uri->host && length $uri->host;
42 19 ▶ croak 'App Configuration endpoint must not include userinfo'
Branch: 1 branch
BranchTrueFalseTotal
if defined $uri->userinfo 1 18 19
43 if defined $uri->userinfo;
44 18 ▶ croak 'App Configuration endpoint must not include a query string'
Branch: 1 branch
BranchTrueFalseTotal
if defined $uri->query 1 17 18
45 if defined $uri->query;
46 17 ▶ croak 'App Configuration endpoint must not include a fragment'
Branch: 1 branch
BranchTrueFalseTotal
if defined $uri->fragment 1 16 17
47 if defined $uri->fragment;
48
49 16 ▶ my $path = $uri->path // '';
Condition50%1/2
$uri->path // ""
l!l
160
MC/DC0%0/1
$uri->path // ""
$uri->path
Truth table50%1/2
A
A= $uri->path
Aresult
11
00
50 16 ▶ croak 'App Configuration endpoint must not include a path'
Branch: 1 branch
BranchTrueFalseTotal
unless $path eq "" or $path eq "/" 1 15 16
Condition66%2/3
$path eq "" or $path eq "/"
l!l&&r!l&&!r
1501
MC/DC50%1/2
$path eq "" or $path eq "/"
$path eq "" $path eq "/"
Truth table66%2/3
A or B
A= $path eq ""B= $path eq "/"
ABresult
1X1
011
000
51 unless $path eq '' || $path eq '/';
52
53 15 my $host = lc $uri->host;
54 15 ▶ my $loopback = $host eq 'localhost' || $host eq '127.0.0.1' || $host eq '::1';
Condition66%4/6
$host eq 'localhost' || $host eq '127.0.0.1' || $host eq '::1'
l!l&&r!l&&!r
1302
$host eq "localhost" or $host eq "127.0.0.1"
l!l&&r!l&&!r
0132
MC/DC33%1/3
$host eq 'localhost' || $host eq '127.0.0.1' || $host eq '::1'
$host eq "localhost" $host eq "127.0.0.1" $host eq '::1'
Truth table50%2/4
A or B || C
A= $host eq "localhost"B= $host eq "127.0.0.1"C= $host eq '::1'
ABCresult
1XX1
01X1
0011
0000
55 15 ▶ croak 'Plain HTTP App Configuration endpoints must be loopback'
Branch: 1 branch
BranchTrueFalseTotal
if $uri->scheme eq "http" and not $loopback 1 14 15
Condition100%3/3
$uri->scheme eq "http" and not $loopback
!ll&&!rl&&r
1131
MC/DC100%2/2
$uri->scheme eq "http" and not $loopback
$uri->scheme eq "http" not $loopback
Truth table100%3/3
A and not(B)
A= $uri->scheme eq "http"B= not $loopback
ABresult
0X0
100
111
56 if $uri->scheme eq 'http' && !$loopback;
57
58 14 ▶ $is_emulator = $uri->scheme eq 'http' && $loopback ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$uri->scheme eq 'http' && $loopback ? : 13 1 14
Condition66%2/3
$uri->scheme eq "http" and $loopback
!ll&&!rl&&r
1013
MC/DC50%1/2
$uri->scheme eq "http" and $loopback
$uri->scheme eq "http" $loopback
Truth table66%2/3
A and B
A= $uri->scheme eq "http"B= $loopback
ABresult
0X0
100
111
59 14 $endpoint = $uri->scheme . '://' . $uri->authority;
60 14 $credential_secret = Azure::SDK::Core::SecretString->new(
61 value => $credential_secret,
62 );
63 }
64
65 25 ▶ sub parse ($class, $text) {
Subroutine parse: called CC=14 SCAR=28.9
Pod documented
66 25 ▶ croak 'Azure::SDK::AppConfiguration::ConnectionString->parse requires a connection string'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and not ref $text and length $text 0 25 25
Condition33%2/6
defined $text and not ref $text and length $text
!ll&&!rl&&r
0025
defined $text and not ref $text
!ll&&!rl&&r
0025
MC/DC0%0/3
defined $text and not ref $text and length $text
defined $text not ref $text length $text
Truth table25%1/4
A and not(B) and C
A= defined $textB= not ref $textC= length $text
ABCresult
0XX0
10X0
1100
1111
67 unless defined $text && !ref $text && length $text;
68 25 ▶ croak 'Connection string exceeds ' . MAX_LENGTH . ' bytes'
Branch: 1 branch
BranchTrueFalseTotal
if &bytes::length($text) > 8192 0 25 25
69 if bytes::length($text) > MAX_LENGTH;
70 25 ▶ croak 'Connection string contains control characters'
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /[\x00-\x1f\x7f]/u 1 24 25
71 if $text =~ /[\x00-\x1f\x7f]/;
72
73 24 my %fields;
74 24 for my $segment (split /;/, $text, -1) {
75 68 ▶ next unless $segment =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $segment =~ /\S/u 0 68 68
76 68 my ($name, $value) = $segment =~ /\A\s*([^=]+?)\s*=(.*)\z/s;
77 68 ▶ croak 'Connection string segment is not a name=value pair'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 0 68 68
Condition33%1/3
defined $name and length $name
!ll&&!rl&&r
0068
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table33%1/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
78 unless defined $name && length $name;
79
80 68 my $key = lc $name;
81 croak "Connection string repeats the '$name' field"
82 68 ▶ if exists $fields{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $fields{$key} 1 67 68
83 67 $fields{$key} = $value;
84 }
85
86 23 for my $required (qw(endpoint id secret)) {
87 croak "Connection string is missing the required '$required' field"
88 66 ▶ unless defined $fields{$required} && length $fields{$required};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fields{$required} and length $fields{$required} 3 63 66
Condition66%2/3
defined $fields{$required} and length $fields{$required}
!ll&&!rl&&r
3063
MC/DC50%1/2
defined $fields{$required} and length $fields{$required}
defined $fields{$required} length $fields{$required}
Truth table66%2/3
A and B
A= defined $fields{$required}B= length $fields{$required}
ABresult
0X0
100
111
89 }
90
91 return $class->new(
92 endpoint => $fields{endpoint},
93 credential_id => $fields{id},
94 credential_secret => $fields{secret},
95 20 );
96 }
97
98 16 ▶ method signer () {
Subroutine signer: called CC=3 SCAR=11.0
Pod documented
99 16 ▶ return undef if $is_emulator;
Branch: 1 branch
BranchTrueFalseTotal
if $is_emulator 13 3 16
100 3 ▶ $signer //= Azure::SDK::AppConfiguration::Hmac->new(
Condition66%2/3
$signer //= "Azure::SDK::AppConfiguration::Hmac"->new("credential_id", $credential_id, "credential_secret", $credential_secret->reveal)
l!l&&r!l&&!r
210
MC/DC0%0/2
$signer //= "Azure::SDK::AppConfiguration::Hmac"->new("credential_id", $credential_id, "credential_secret", $credential_secret->reveal)
$signer "Azure::SDK::AppConfiguration::Hmac"->new("credential_id", $credential_id, "credential_secret", $credential_secret->reveal)
Truth table66%2/3
A //= B
A= $signerB= "Azure::SDK::AppConfiguration::Hmac"->new("credential_id", $credential_id, "credential_secret", $credential_secret->reveal)
ABresult
1X1
011
000
101 credential_id => $credential_id,
102 credential_secret => $credential_secret->reveal,
103 );
104 3 return $signer;
105 }
106
107 2 ▶ method to_string () {
Subroutine to_string: called CC=1 SCAR=0.0
Pod documented
108 2 return "Endpoint=$endpoint;Id=[REDACTED];Secret=[REDACTED]";
109 }
110
111 20 ▶ sub _looks_like_base64 ($value) {
Subroutine _looks_like_base64: called CC=4 SCAR=14.3
112 20 ▶ return 0 unless $value =~ m{\A[A-Za-z0-9+/]+={0,2}\z};
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ m[\A[A-Za-z0-9+/]+={0,2}\z]u 1 19 20
113 19 ▶ return 0 if length($value) % 4;
Branch: 1 branch
BranchTrueFalseTotal
if length($value) % 4 0 19 19
114 19 ▶ return length decode_base64($value) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
length &decode_base64($value) ? : 19 0 19
115 }
116 }
117
118 3 1;
119
120 __END__
« SDK/Storage/Tables/EntityProperty.pm ↑ Summary SDK/Core/Credential/Sas.pm »