SDK/Core/Error.pm

filter: Statementstmt 100% 34 / 34 Branchbran 70.0% 7 / 10 Conditioncond 88.8% 8 / 9 MC/DCmcdc 80.0% 4 / 5 Subroutinesub 100% 11 / 11 Podpod 100% 4 / 4 totaltotal 93.1% 68 / 73 CC 9 SCAR 11.1
CC
9
Cov
92%
__ANON__
6.0
to_string
3.1
_sanitize_for_log
2.0
CRAP 3.0
« SDK/Core/Policy/Headers.pm ↑ Summary SDK/Core/Credential/SharedKey.pm »
1 19 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 19 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 19 ▶no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 19 class Azure::SDK::Core::Error {
6 19 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 19 field $message :param :reader = undef;
10 19 field $status :param :reader = undef;
11 19 field $code :param :reader = undef;
12 19 field $body :param :reader = undef;
13 19 field $max_body_bytes :param = 16 * 1024;
14
15 47 ▶ ADJUST {
Subroutine __ANON__: called CC=6 SCAR=17.9
16 47 ▶ croak 'Azure::SDK::Core::Error requires a message'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message and length $message 1 46 47
Condition66%2/3
defined $message and length $message
!ll&&!rl&&r
1046
MC/DC50%1/2
defined $message and length $message
defined $message length $message
Truth table66%2/3
A and B
A= defined $messageB= length $message
ABresult
0X0
100
111
17 unless defined $message && length $message;
18
19 # CWE-770 defense-in-depth: cap the stored server body so a hostile or
20 # runaway error response cannot balloon memory or log volume. The raw
21 # bytes up to the cap are preserved (see log_safe for a log-safe view).
22 46 ▶ if (defined $body && $max_body_bytes > 0 && length $body > $max_body_bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $body and $max_body_bytes > 0 and length $body > $max_body_bytes) 1 45 46
Condition100%6/6
defined $body and $max_body_bytes > 0 and length $body > $max_body_bytes
!ll&&!rl&&r
11341
defined $body and $max_body_bytes > 0
!ll&&!rl&&r
10135
MC/DC100%3/3
defined $body and $max_body_bytes > 0 and length $body > $max_body_bytes
defined $body $max_body_bytes > 0 length $body > $max_body_bytes
Truth table100%4/4
A and B and C
A= defined $bodyB= $max_body_bytes > 0C= length $body > $max_body_bytes
ABCresult
0XX0
10X0
1100
1111
23 1 $body = substr($body, 0, $max_body_bytes) . '...[truncated]';
24 }
25 }
26
27 41 ▶ method throw () {
Subroutine throw: called CC=1 SCAR=0.0
Pod documented
28 41 die $self;
29 }
30
31 14 ▶ method to_string () {
Subroutine to_string: called CC=3 SCAR=11.4
Pod documented
32 # to_string is documented as single-line, so the (untrusted) message and
33 # code are sanitized to neutralize embedded CR/LF and control characters.
34 14 my $detail = _sanitize_for_log($message);
35 14 ▶ $detail .= " (status $status)" if defined $status;
Branch: 1 branch
BranchTrueFalseTotal
if defined $status 14 0 14
36 14 ▶ $detail .= ' [' . _sanitize_for_log($code) . ']' if defined $code;
Branch: 1 branch
BranchTrueFalseTotal
if defined $code 14 0 14
37 14 return $detail;
38 }
39
40 2 ▶ method as_hashref () {
Subroutine as_hashref: called CC=1 SCAR=0.0
Pod documented
41 return {
42 2 message => $message,
43 status => $status,
44 code => $code,
45 body => $body,
46 };
47 }
48
49 10 ▶ method log_safe () {
Subroutine log_safe: called CC=1 SCAR=0.0
Pod documented
50 return {
51 10 message => _sanitize_for_log($message),
52 status => $status,
53 code => _sanitize_for_log($code),
54 body => _sanitize_for_log($body),
55 };
56 }
57
58 # Collapse runs of control characters (including CR/LF and tab) to a single
59 # space so untrusted server-supplied text cannot forge or split log lines
60 # (CWE-117) when a caller logs the error.
61 58 ▶ sub _sanitize_for_log ($value) {
Subroutine _sanitize_for_log: called CC=2 SCAR=7.1
62 58 ▶ return undef unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 58 58
63 58 $value =~ s/[\x00-\x1f\x7f]+/ /g;
64 58 return $value;
65 }
66 }
67
68 19 1;
69
70 __END__
« SDK/Core/Policy/Headers.pm ↑ Summary SDK/Core/Credential/SharedKey.pm »