SDK/Storage/Tables/ConnectionString.pm

filter: Statementstmt 98.9% 90 / 91 Branchbran 73.2% 41 / 56 Conditioncond 54.1% 26 / 48 MC/DCmcdc 16.1% 5 / 31 Subroutinesub 100% 19 / 19 Podpod 0.0% 0 / 3 totaltotal 72.9% 181 / 248 CC 47 SCAR 26.4
CC
47
Cov
81%
parse
23.5
__ANON__
21.1
_derive_endpoint
9.8
CRAP 14.0
« SDK/Storage/Queues/ConnectionString.pm ↑ Summary SDK/AppConfiguration/SnapshotFilter.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 class Azure::SDK::Storage::Tables::ConnectionString {
6 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶ use bytes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶ use MIME::Base64 qw(decode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶ use Azure::SDK::Core::Credential::Sas;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶ use Azure::SDK::Core::Credential::SharedKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶ use Azure::SDK::Core::SecretString;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶ use Azure::SDK::Storage::Tables::Uri;
Subroutine BEGIN: called CC=1 SCAR=0.0
13
14 5 ▶ use constant MAX_LENGTH => 8 * 1024;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶ use constant DEFAULT_ENDPOINT_SUFFIX => 'core.windows.net';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶ use constant MAX_ENDPOINT_SUFFIX_LENGTH => 253;
Subroutine BEGIN: called CC=1 SCAR=0.0
17
18 5 my $DNS_LABEL = qr/[A-Za-z0-9](?:[A-Za-z0-9\-]*[A-Za-z0-9])?/;
19
20 5 field $table_endpoint :param :reader = undef;
21 5 field $account_name :param :reader = undef;
22 5 field $account_key :param = undef;
23 5 field $shared_access_signature :param = undef;
24
25 5 field $endpoint_path :reader = undef;
26 5 field $credential = undef;
27
28 29 ▶ ADJUST {
Subroutine __ANON__: called CC=16 SCAR=30.5
29 29 ▶ croak 'AccountKey cannot be combined with SharedAccessSignature'
Branch: 1 branch
BranchTrueFalseTotal
if defined $account_key and defined $shared_access_signature 2 27 29
Condition100%3/3
defined $account_key and defined $shared_access_signature
!ll&&!rl&&r
6212
MC/DC100%2/2
defined $account_key and defined $shared_access_signature
defined $account_key defined $shared_access_signature
Truth table100%3/3
A and B
A= defined $account_keyB= defined $shared_access_signature
ABresult
0X0
100
111
30 if defined $account_key && defined $shared_access_signature;
31 27 ▶ croak 'Azure::SDK::Storage::Tables::ConnectionString requires an account_key or SharedAccessSignature'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $account_key or defined $shared_access_signature 0 27 27
Condition66%2/3
defined $account_key or defined $shared_access_signature
l!l&&r!l&&!r
2160
MC/DC0%0/2
defined $account_key or defined $shared_access_signature
defined $account_key defined $shared_access_signature
Truth table66%2/3
A or B
A= defined $account_keyB= defined $shared_access_signature
ABresult
1X1
011
000
32 unless defined $account_key || defined $shared_access_signature;
33 27 ▶ croak 'Azure::SDK::Storage::Tables::ConnectionString requires an account_name for Shared Key'
Branch: 1 branch
BranchTrueFalseTotal
if defined $account_key and not defined $account_name && length $account_name 0 27 27
Condition50%3/6
defined $account_key and not defined $account_name && length $account_name
!ll&&!rl&&r
6210
defined $account_name && length $account_name
!ll&&!rl&&r
0021
MC/DC0%0/3
defined $account_key and not defined $account_name && length $account_name
defined $account_key defined $account_name length $account_name
Truth table50%2/4
A and not(B && C)
A= defined $account_keyB= defined $account_nameC= length $account_name
ABCresult
0XX0
1110
10X1
1101
34 if defined $account_key && !(defined $account_name && length $account_name);
35 27 ▶ croak 'Azure::SDK::Storage::Tables::ConnectionString requires a table_endpoint'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table_endpoint and length $table_endpoint 0 27 27
Condition33%1/3
defined $table_endpoint and length $table_endpoint
!ll&&!rl&&r
0027
MC/DC0%0/2
defined $table_endpoint and length $table_endpoint
defined $table_endpoint length $table_endpoint
Truth table33%1/3
A and B
A= defined $table_endpointB= length $table_endpoint
ABresult
0X0
100
111
36 unless defined $table_endpoint && length $table_endpoint;
37 27 ▶ croak 'AccountName must be 3-24 alphanumeric characters'
Branch: 1 branch
BranchTrueFalseTotal
if defined $account_name and not $account_name =~ /\A[A-Za-z0-9]{3,24}\z/u 0 27 27
Condition66%2/3
defined $account_name and not $account_name =~ /\A[A-Za-z0-9]{3,24}\z/u
!ll&&!rl&&r
5220
MC/DC0%0/2
defined $account_name and not $account_name =~ /\A[A-Za-z0-9]{3,24}\z/u
defined $account_name not $account_name =~ /\A[A-Za-z0-9]{3,24}\z/u
Truth table66%2/3
A and not(B)
A= defined $account_nameB= not $account_name =~ /\A[A-Za-z0-9]{3,24}\z/u
ABresult
0X0
100
111
38 if defined $account_name && $account_name !~ /\A[A-Za-z0-9]{3,24}\z/;
39 27 ▶ croak 'AccountKey is not valid base64'
Branch: 1 branch
BranchTrueFalseTotal
if defined $account_key and not _looks_like_base64($account_key) 0 27 27
Condition66%2/3
defined $account_key and not _looks_like_base64($account_key)
!ll&&!rl&&r
6210
MC/DC0%0/2
defined $account_key and not _looks_like_base64($account_key)
defined $account_key not _looks_like_base64($account_key)
Truth table66%2/3
A and not(B)
A= defined $account_keyB= not _looks_like_base64($account_key)
ABresult
0X0
100
111
40 if defined $account_key && !_looks_like_base64($account_key);
41
42 27 ( $table_endpoint, $endpoint_path )
43 = Azure::SDK::Storage::Tables::Uri->normalize_endpoint($table_endpoint);
44 24 ▶ $account_key = Azure::SDK::Core::SecretString->new(value => $account_key)
Branch: 1 branch
BranchTrueFalseTotal
if defined $account_key 19 5 24
45 if defined $account_key;
46 24 ▶ if (defined $shared_access_signature) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $shared_access_signature) 5 19 24
47 5 $credential = Azure::SDK::Core::Credential::Sas->new(
48 token => $shared_access_signature,
49 );
50 4 $shared_access_signature = Azure::SDK::Core::SecretString->new(
51 value => $shared_access_signature,
52 );
53 }
54 }
55
56 34 ▶ sub parse ( $class, $text ) {
Subroutine parse: called CC=19 SCAR=31.6
Pod undocumented
57 34 ▶ croak 'Azure::SDK::Storage::Tables::ConnectionString->parse requires a connection string'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and length $text 0 34 34
Condition33%1/3
defined $text and length $text
!ll&&!rl&&r
0034
MC/DC0%0/2
defined $text and length $text
defined $text length $text
Truth table33%1/3
A and B
A= defined $textB= length $text
ABresult
0X0
100
111
58 unless defined $text && length $text;
59 34 ▶ croak 'Connection string exceeds ' . MAX_LENGTH . ' bytes'
Branch: 1 branch
BranchTrueFalseTotal
if &bytes::length($text) > 8192 0 34 34
60 if bytes::length($text) > MAX_LENGTH;
61 34 ▶ croak 'Connection string contains control characters'
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /[\x00-\x08\x0a-\x1f\x7f]/u 1 33 34
62 if $text =~ /[\x00-\x08\x0a-\x1f\x7f]/;
63
64 33 my %fields;
65 33 for my $segment (split /;/, $text, -1) {
66 96 ▶ next unless $segment =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $segment =~ /\S/u 0 96 96
67 96 my ($name, $value) = $segment =~ /\A\s*([^=]+?)\s*=(.*)\z/s;
68 96 ▶ croak 'Connection string segment is not a name=value pair'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 0 96 96
Condition33%1/3
defined $name and length $name
!ll&&!rl&&r
0096
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
69 unless defined $name && length $name;
70
71 96 my $key = lc $name;
72 croak "Connection string repeats the '$name' field"
73 96 ▶ if exists $fields{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $fields{$key} 1 95 96
74 95 $fields{$key} = $value;
75 }
76
77 croak 'UseDevelopmentStorage is not supported; supply AccountName and '
78 . 'AccountKey explicitly, plus TableEndpoint when targeting an emulator'
79 32 ▶ if exists $fields{usedevelopmentstorage};
Branch: 1 branch
BranchTrueFalseTotal
if exists $fields{"usedevelopmentstorage"} 1 31 32
80
81 31 ▶ if (!defined $fields{sharedaccesssignature}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $fields{'sharedaccesssignature'}) { } 23 8 31
elsif (not defined $fields{'tableendpoint'} || defined $fields{'accountname'}) { } 0 8 8
82 23 for my $required (qw(accountname accountkey)) {
83 croak "Connection string is missing the required '$required' field"
84 46 ▶ unless defined $fields{$required} && length $fields{$required};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fields{$required} and length $fields{$required} 1 45 46
Condition66%2/3
defined $fields{$required} and length $fields{$required}
!ll&&!rl&&r
1045
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
85 }
86 }
87 ▶ elsif (!defined $fields{tableendpoint} && !defined $fields{accountname}) {
Condition66%2/3
defined $fields{'tableendpoint'} || defined $fields{'accountname'}
l!l&&r!l&&!r
710
MC/DC0%0/2
defined $fields{'tableendpoint'} || defined $fields{'accountname'}
defined $fields{'tableendpoint'} defined $fields{'accountname'}
Truth table66%2/3
A || B
A= defined $fields{'tableendpoint'}B= defined $fields{'accountname'}
ABresult
1X1
011
000
88 0 croak 'SAS connection string requires TableEndpoint or AccountName';
89 }
90
91 30 my $endpoint = $fields{tableendpoint};
92 $endpoint = _derive_endpoint(
93 $fields{defaultendpointsprotocol},
94 $fields{accountname},
95 $fields{endpointsuffix},
96 30 ▶ ) unless defined $endpoint && length $endpoint;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $endpoint and length $endpoint 3 27 30
Condition66%2/3
defined $endpoint and length $endpoint
!ll&&!rl&&r
3027
MC/DC50%1/2
defined $endpoint and length $endpoint
defined $endpoint length $endpoint
Truth table66%2/3
A and B
A= defined $endpointB= length $endpoint
ABresult
0X0
100
111
97
98 return $class->new(
99 account_name => $fields{accountname},
100 account_key => $fields{accountkey},
101 table_endpoint => $endpoint,
102 shared_access_signature => $fields{sharedaccesssignature},
103 29 );
104 }
105
106 21 ▶ method credential () {
Subroutine credential: called CC=3 SCAR=11.4
Pod undocumented
107 21 ▶ return $credential if defined $credential;
Branch: 1 branch
BranchTrueFalseTotal
if defined $credential 5 16 21
108 16 ▶ $credential //= Azure::SDK::Core::Credential::SharedKey->new(
Condition33%1/3
$credential //= "Azure::SDK::Core::Credential::SharedKey"->new("account_name", $account_name, "account_key", $account_key->reveal)
l!l&&r!l&&!r
0160
MC/DC0%0/2
$credential //= "Azure::SDK::Core::Credential::SharedKey"->new("account_name", $account_name, "account_key", $account_key->reveal)
$credential "Azure::SDK::Core::Credential::SharedKey"->new("account_name", $account_name, "account_key", $account_key->reveal)
Truth table33%1/3
A //= B
A= $credentialB= "Azure::SDK::Core::Credential::SharedKey"->new("account_name", $account_name, "account_key", $account_key->reveal)
ABresult
1X1
011
000
109 account_name => $account_name,
110 account_key => $account_key->reveal,
111 );
112 16 return $credential;
113 }
114
115 3 ▶ method to_string () {
Subroutine to_string: called CC=2 SCAR=6.9
Pod undocumented
116 3 ▶ return "TableEndpoint=$table_endpoint;SharedAccessSignature=[REDACTED]"
Branch: 1 branch
BranchTrueFalseTotal
if defined $shared_access_signature 1 2 3
117 if defined $shared_access_signature;
118 2 return "AccountName=$account_name;TableEndpoint=$table_endpoint;AccountKey=[REDACTED]";
119 }
120
121 21 ▶ sub _looks_like_base64 ($value) {
Subroutine _looks_like_base64: called CC=4 SCAR=15.2
122 21 ▶ 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 0 21 21
123 21 ▶ return 0 if length($value) % 4;
Branch: 1 branch
BranchTrueFalseTotal
if length($value) % 4 0 21 21
124 21 ▶ return length decode_base64($value) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
length &decode_base64($value) ? : 21 0 21
125 }
126
127 3 ▶ sub _derive_endpoint ( $protocol, $account, $suffix ) {
Subroutine _derive_endpoint: called CC=8 SCAR=22.8
128 3 ▶ $protocol = defined $protocol && length $protocol ? lc $protocol : 'https';
Branch: 1 branch
BranchTrueFalseTotal
defined $protocol && length $protocol ? : 1 2 3
Condition66%2/3
defined $protocol and length $protocol
!ll&&!rl&&r
201
MC/DC50%1/2
defined $protocol and length $protocol
defined $protocol length $protocol
Truth table66%2/3
A and B
A= defined $protocolB= length $protocol
ABresult
0X0
100
111
129 3 ▶ croak 'DefaultEndpointsProtocol must be http or https'
Branch: 1 branch
BranchTrueFalseTotal
unless $protocol eq "http" or $protocol eq "https" 0 3 3
Condition33%1/3
$protocol eq "http" or $protocol eq "https"
l!l&&r!l&&!r
030
MC/DC0%0/2
$protocol eq "http" or $protocol eq "https"
$protocol eq "http" $protocol eq "https"
Truth table33%1/3
A or B
A= $protocol eq "http"B= $protocol eq "https"
ABresult
1X1
011
000
130 unless $protocol eq 'http' || $protocol eq 'https';
131
132 3 ▶ if (defined $suffix) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $suffix) { } 1 2 3
133 1 ▶ croak 'EndpointSuffix must be a bare DNS suffix'
Branch: 1 branch
BranchTrueFalseTotal
unless length $suffix <= 253 and $suffix =~ /\A$DNS_LABEL(?:\.$DNS_LABEL)*\z/u 1 0 1
Condition33%1/3
length $suffix <= 253 and $suffix =~ /\A$DNS_LABEL(?:\.$DNS_LABEL)*\z/u
!ll&&!rl&&r
010
MC/DC0%0/2
length $suffix <= 253 and $suffix =~ /\A$DNS_LABEL(?:\.$DNS_LABEL)*\z/u
length $suffix <= 253 $suffix =~ /\A$DNS_LABEL(?:\.$DNS_LABEL)*\z/u
Truth table33%1/3
A and B
A= length $suffix <= 253B= $suffix =~ /\A$DNS_LABEL(?:\.$DNS_LABEL)*\z/u
ABresult
0X0
100
111
134 unless length($suffix) <= MAX_ENDPOINT_SUFFIX_LENGTH
135 && $suffix =~ /\A$DNS_LABEL(?:\.$DNS_LABEL)*\z/;
136 }
137 else {
138 2 $suffix = DEFAULT_ENDPOINT_SUFFIX;
139 }
140
141 2 return "$protocol://$account.table.$suffix";
142 }
143 }
144
145 5 1;
146
147 __END__
« SDK/Storage/Queues/ConnectionString.pm ↑ Summary SDK/AppConfiguration/SnapshotFilter.pm »