SDK/Storage/Blobs/ConnectionString.pm

filter: Statementstmt 98.9% 90 / 91 Branchbran 83.9% 47 / 56 Conditioncond 62.5% 30 / 48 MC/DCmcdc 32.2% 10 / 31 Subroutinesub 100% 19 / 19 Podpod 100% 3 / 3 totaltotal 80.2% 199 / 248 CC 47 SCAR 25.2
CC
47
Cov
86%
parse
21.7
__ANON__
17.7
_derive_endpoint
8.3
CRAP 12.4
« SDK/AppConfiguration/Hmac.pm ↑ Summary SDK/Storage/Tables/EntityContinuation.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 class Azure::SDK::Storage::Blobs::ConnectionString {
6 3 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶ use bytes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶ use MIME::Base64 qw(decode_base64 encode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶ use Azure::SDK::Core::Credential::Sas;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶ use Azure::SDK::Core::SecretString;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶ use Azure::SDK::Core::Credential::SharedKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶ use Azure::SDK::Storage::Blobs::Uri;
Subroutine BEGIN: called CC=1 SCAR=0.0
13
14 # Defence-in-depth cap on parsing work (CWE-770).
15 3 ▶ use constant MAX_LENGTH => 8 * 1024;
Subroutine BEGIN: called CC=1 SCAR=0.0
16
17 3 ▶ use constant DEFAULT_ENDPOINT_SUFFIX => 'core.windows.net';
Subroutine BEGIN: called CC=1 SCAR=0.0
18
19 # RFC 1035 limit on a fully qualified domain name.
20 3 ▶ use constant MAX_ENDPOINT_SUFFIX_LENGTH => 253;
Subroutine BEGIN: called CC=1 SCAR=0.0
21
22 # One DNS label: alphanumeric ends, optional interior hyphens.
23 3 my $DNS_LABEL = qr/[A-Za-z0-9](?:[A-Za-z0-9\-]*[A-Za-z0-9])?/;
24
25 3 field $blob_endpoint :param :reader = undef;
26 3 field $account_name :param :reader = undef;
27 3 field $account_key :param = undef;
28 3 field $shared_access_signature :param = undef;
29
30 3 field $endpoint_path :reader = undef;
31 3 field $credential = undef;
32
33 37 ▶ ADJUST {
Subroutine __ANON__: called CC=16 SCAR=28.7
34 37 ▶ croak 'AccountKey cannot be combined with SharedAccessSignature'
Branch: 1 branch
BranchTrueFalseTotal
if defined $account_key and defined $shared_access_signature 2 35 37
Condition100%3/3
defined $account_key and defined $shared_access_signature
!ll&&!rl&&r
6292
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
35 if defined $account_key && defined $shared_access_signature;
36 35 ▶ croak 'Azure::SDK::Storage::Blobs::ConnectionString requires an account_key or SharedAccessSignature'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $account_key or defined $shared_access_signature 0 35 35
Condition66%2/3
defined $account_key or defined $shared_access_signature
l!l&&r!l&&!r
2960
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
37 unless defined $account_key || defined $shared_access_signature;
38 35 ▶ croak 'Azure::SDK::Storage::Blobs::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 35 35
Condition50%3/6
defined $account_key and not defined $account_name && length $account_name
!ll&&!rl&&r
6290
defined $account_name && length $account_name
!ll&&!rl&&r
0029
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
39 if defined $account_key && !(defined $account_name && length $account_name);
40 35 ▶ croak 'Azure::SDK::Storage::Blobs::ConnectionString requires a blob_endpoint'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $blob_endpoint and length $blob_endpoint 0 35 35
Condition33%1/3
defined $blob_endpoint and length $blob_endpoint
!ll&&!rl&&r
0035
MC/DC0%0/2
defined $blob_endpoint and length $blob_endpoint
defined $blob_endpoint length $blob_endpoint
Truth table33%1/3
A and B
A= defined $blob_endpointB= length $blob_endpoint
ABresult
0X0
100
111
41 unless defined $blob_endpoint && length $blob_endpoint;
42
43 35 ▶ 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 1 34 35
Condition100%3/3
defined $account_name and not $account_name =~ /\A[A-Za-z0-9]{3,24}\z/u
!ll&&!rl&&r
5291
MC/DC100%2/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 table100%3/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
44 if defined $account_name && $account_name !~ /\A[A-Za-z0-9]{3,24}\z/;
45
46 # Validate the shape without ever putting the key in an error message.
47 34 ▶ croak 'AccountKey is not valid base64'
Branch: 1 branch
BranchTrueFalseTotal
if defined $account_key and not _looks_like_base64($account_key) 1 33 34
Condition100%3/3
defined $account_key and not _looks_like_base64($account_key)
!ll&&!rl&&r
6271
MC/DC100%2/2
defined $account_key and not _looks_like_base64($account_key)
defined $account_key not _looks_like_base64($account_key)
Truth table100%3/3
A and not(B)
A= defined $account_keyB= not _looks_like_base64($account_key)
ABresult
0X0
100
111
48 if defined $account_key && !_looks_like_base64($account_key);
49
50 33 ( $blob_endpoint, $endpoint_path )
51 = Azure::SDK::Storage::Blobs::Uri->normalize_endpoint($blob_endpoint);
52
53 28 ▶ $account_key = Azure::SDK::Core::SecretString->new(value => $account_key)
Branch: 1 branch
BranchTrueFalseTotal
if defined $account_key 23 5 28
54 if defined $account_key;
55 28 ▶ if (defined $shared_access_signature) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $shared_access_signature) 5 23 28
56 5 $credential = Azure::SDK::Core::Credential::Sas->new(
57 token => $shared_access_signature,
58 );
59 4 $shared_access_signature = Azure::SDK::Core::SecretString->new(
60 value => $shared_access_signature,
61 );
62 }
63 }
64
65 # Class method: parse a Storage connection string. Both the account form the
66 # Azure portal emits and the explicit-endpoint form emulators emit are
67 # accepted.
68 50 ▶ sub parse ( $class, $text ) {
Subroutine parse: called CC=19 SCAR=30.8
Pod documented
69 50 ▶ croak 'Azure::SDK::Storage::Blobs::ConnectionString->parse requires a connection string'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and length $text 0 50 50
Condition33%1/3
defined $text and length $text
!ll&&!rl&&r
0050
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
70 unless defined $text && length $text;
71
72 # bytes::length, not length: the cap is documented in bytes, and Perl's
73 # length counts characters, so a decoded value could carry twice this
74 # many octets while appearing to fit.
75 50 ▶ croak 'Connection string exceeds ' . MAX_LENGTH . ' bytes'
Branch: 1 branch
BranchTrueFalseTotal
if &bytes::length($text) > 8192 1 49 50
76 if bytes::length($text) > MAX_LENGTH;
77 49 ▶ croak 'Connection string contains control characters'
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /[\x00-\x08\x0a-\x1f\x7f]/u 1 48 49
78 if $text =~ /[\x00-\x08\x0a-\x1f\x7f]/;
79
80 48 my %fields;
81 48 for my $segment ( split /;/, $text, -1 ) {
82 155 ▶ next unless $segment =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $segment =~ /\S/u 7 148 155
83
84 148 my ( $name, $value ) = $segment =~ /\A\s*([^=]+?)\s*=(.*)\z/s;
85 148 ▶ croak 'Connection string segment is not a name=value pair'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 0 148 148
Condition33%1/3
defined $name and length $name
!ll&&!rl&&r
00148
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
86 unless defined $name && length $name;
87
88 148 my $key = lc $name;
89 croak "Connection string repeats the '$name' field"
90 148 ▶ if exists $fields{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $fields{$key} 1 147 148
91
92 147 $fields{$key} = $value;
93 }
94
95 croak 'UseDevelopmentStorage is not supported; supply AccountName and '
96 . 'AccountKey explicitly, plus BlobEndpoint when targeting an emulator'
97 47 ▶ if exists $fields{usedevelopmentstorage};
Branch: 1 branch
BranchTrueFalseTotal
if exists $fields{"usedevelopmentstorage"} 1 46 47
98
99 46 ▶ if (!defined $fields{sharedaccesssignature}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $fields{'sharedaccesssignature'}) { } 38 8 46
elsif (not defined $fields{'blobendpoint'} || defined $fields{'accountname'}) { } 0 8 8
100 38 for my $required (qw(accountname accountkey)) {
101 croak "Connection string is missing the required '$required' field"
102 75 ▶ unless defined $fields{$required} && length $fields{$required};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fields{$required} and length $fields{$required} 2 73 75
Condition66%2/3
defined $fields{$required} and length $fields{$required}
!ll&&!rl&&r
2073
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
103 }
104 }
105 ▶ elsif (!defined $fields{blobendpoint} && !defined $fields{accountname}) {
Condition66%2/3
defined $fields{'blobendpoint'} || defined $fields{'accountname'}
l!l&&r!l&&!r
710
MC/DC0%0/2
defined $fields{'blobendpoint'} || defined $fields{'accountname'}
defined $fields{'blobendpoint'} defined $fields{'accountname'}
Truth table66%2/3
A || B
A= defined $fields{'blobendpoint'}B= defined $fields{'accountname'}
ABresult
1X1
011
000
106 0 croak 'SAS connection string requires BlobEndpoint or AccountName';
107 }
108
109 # Only required when the endpoint cannot be derived: an emulator, a
110 # custom domain, or any non-standard host.
111 44 my $endpoint = $fields{blobendpoint};
112 $endpoint = _derive_endpoint(
113 $fields{defaultendpointsprotocol},
114 $fields{accountname},
115 $fields{endpointsuffix},
116 44 ▶ ) unless defined $endpoint && length $endpoint;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $endpoint and length $endpoint 13 31 44
Condition66%2/3
defined $endpoint and length $endpoint
!ll&&!rl&&r
13031
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
117
118 return $class->new(
119 account_name => $fields{accountname},
120 account_key => $fields{accountkey},
121 blob_endpoint => $endpoint,
122 shared_access_signature => $fields{sharedaccesssignature},
123 37 );
124 }
125
126 17 ▶ method credential () {
Subroutine credential: called CC=3 SCAR=11.4
Pod documented
127 17 ▶ return $credential if defined $credential;
Branch: 1 branch
BranchTrueFalseTotal
if defined $credential 4 13 17
128 13 ▶ $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
0130
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
129 account_name => $account_name,
130 account_key => $account_key->reveal,
131 );
132 13 return $credential;
133 }
134
135 4 ▶ method to_string () {
Subroutine to_string: called CC=2 SCAR=6.9
Pod documented
136 4 ▶ return "BlobEndpoint=$blob_endpoint;SharedAccessSignature=[REDACTED]"
Branch: 1 branch
BranchTrueFalseTotal
if defined $shared_access_signature 2 2 4
137 if defined $shared_access_signature;
138 2 return "AccountName=$account_name;BlobEndpoint=$blob_endpoint;AccountKey=[REDACTED]";
139 }
140
141 28 ▶ sub _looks_like_base64 ($value) {
Subroutine _looks_like_base64: called CC=4 SCAR=14.3
142 28 ▶ 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 27 28
143 27 ▶ return 0 if length($value) % 4;
Branch: 1 branch
BranchTrueFalseTotal
if length($value) % 4 0 27 27
144 27 ▶ return length decode_base64($value) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
length &decode_base64($value) ? : 27 0 27
145 }
146
147 # The suffix becomes part of a signed hostname, so it is held to a bare DNS
148 # name: a scheme, userinfo, port, path, or query could otherwise redirect a
149 # signed request to a host the caller never named (CWE-918).
150 13 ▶ sub _derive_endpoint ( $protocol, $account, $suffix ) {
Subroutine _derive_endpoint: called CC=8 SCAR=21.2
151 13 ▶ $protocol = defined $protocol && length $protocol ? lc $protocol : 'https';
Branch: 1 branch
BranchTrueFalseTotal
defined $protocol && length $protocol ? : 11 2 13
Condition66%2/3
defined $protocol and length $protocol
!ll&&!rl&&r
2011
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
152 13 ▶ croak 'DefaultEndpointsProtocol must be http or https'
Branch: 1 branch
BranchTrueFalseTotal
unless $protocol eq "http" or $protocol eq "https" 0 13 13
Condition66%2/3
$protocol eq "http" or $protocol eq "https"
l!l&&r!l&&!r
1120
MC/DC0%0/2
$protocol eq "http" or $protocol eq "https"
$protocol eq "http" $protocol eq "https"
Truth table66%2/3
A or B
A= $protocol eq "http"B= $protocol eq "https"
ABresult
1X1
011
000
153 unless $protocol eq 'http' || $protocol eq 'https';
154
155 13 ▶ if ( defined $suffix ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $suffix) { } 8 5 13
156 8 ▶ 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 7 1 8
Condition66%2/3
length $suffix <= 253 and $suffix =~ /\A$DNS_LABEL(?:\.$DNS_LABEL)*\z/u
!ll&&!rl&&r
071
MC/DC50%1/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 table66%2/3
A and B
A= length $suffix <= 253B= $suffix =~ /\A$DNS_LABEL(?:\.$DNS_LABEL)*\z/u
ABresult
0X0
100
111
157 unless length($suffix) <= MAX_ENDPOINT_SUFFIX_LENGTH
158 && $suffix =~ /\A$DNS_LABEL(?:\.$DNS_LABEL)*\z/;
159 }
160 else {
161 5 $suffix = DEFAULT_ENDPOINT_SUFFIX;
162 }
163
164 6 return "$protocol://$account.blob.$suffix";
165 }
166 }
167
168 3 1;
169
170 __END__
« SDK/AppConfiguration/Hmac.pm ↑ Summary SDK/Storage/Tables/EntityContinuation.pm »