TLSRPT/Failure.pm

filter: Statementstmt 100% 36 / 36 Branchbran 94.1% 32 / 34 Conditioncond 70.0% 7 / 10 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 14 / 14 Podpod 100% 4 / 4 totaltotal 92.2% 95 / 103 CC 23 SCAR 14.6
CC
23
Cov
94%
as_struct
6.0
new_from_data
6.0
as_string
6.0
CRAP 4.3
« TLSRPT/App/Command/csv.pm ↑ Summary TLSRPT/Policy.pm »
1 package Mail::TLSRPT::Failure;
2 # ABSTRACT: TLSRPT failure object
3 9 our $VERSION = '2.20210112'; # VERSION
4 9 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use Mail::TLSRPT::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Net::IP;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 has result_type => (is => 'rw', isa => Enum[ qw( starttls-not-supported certificate-host-mismatch certificate-expired certificate-not-trusted validation-failure tlsa-invalid dnssec-invalid dane-required sts-policy-fetch-error sts-policy-invalid sts-webpki-invalid ) ], required => 1);
9 27 ▶ has sending_mta_ip => (is => 'rw', isa => class_type('Net::IP'), required => 1,coerce => sub{&_coerce_ip});
Subroutine __ANON__: called CC=1 SCAR=0.0
10 9 has receiving_mx_hostname => (is => 'rw', isa => Str, required => 1);
11 9 has receiving_mx_helo => (is => 'rw', isa => Str, required => 0);
12 27 ▶ has receiving_ip => (is => 'rw', isa => class_type('Net::IP'), required => 0, coerce => sub{&_coerce_ip});
Subroutine __ANON__: called CC=1 SCAR=0.0
13 9 has failed_session_count => (is => 'rw', isa => Int, required => 1);
14 9 has additional_information => (is => 'rw', isa => Str, required => 0);
15 9 has failure_reason_code => (is => 'rw', isa => Str, required => 0);
16  
17 54 ▶sub _coerce_ip {
Subroutine _coerce_ip: called CC=2 SCAR=6.9
18 54 my $ip = shift;
19 54 ▶ $ip = Net::IP->new($ip) unless ref $ip eq 'Net::IP';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ip eq "Net::IP" 53 1 54
20 54 return $ip;
21 }
22  
23  
24 13 ▶sub new_from_data($class,$data) {
Subroutine new_from_data: called CC=6 SCAR=18.0
Pod documented
25 my $self = $class->new(
26 result_type => $data->{'result-type'},
27 sending_mta_ip => $data->{'sending-mta-ip'},
28 receiving_mx_hostname => $data->{'receiving-mx-hostname'},
29 $data->{'receiving-mx-helo'} ? ( receiving_mx_helo => $data->{'receiving-mx-helo'} ) : (),
30 $data->{'receiving-ip'} ? ( receiving_ip => $data->{'receiving-ip'} ) : (),
31 failed_session_count => $data->{'failed-session-count'} // 0,
32 $data->{'additional-information'} ? ( additional_information => $data->{'additional-information'} ) : (),
33 13 ▶ $data->{'failure-reason-code'} ? ( failure_reason_code => $data->{'failure-reason-code'} ) : (),
Branch: 4 branches
BranchTrueFalseTotal
$data->{'receiving-mx-helo'} ? : 1 12 13
$data->{'receiving-ip'} ? : 9 4 13
$data->{'additional-information'} ? : 5 8 13
$data->{'failure-reason-code'} ? : 5 8 13
Condition50%1/2
$data->{"failed-session-count"} // 0
l!l
130
MC/DC0%0/1
$data->{"failed-session-count"} // 0
$data->{"failed-session-count"}
Truth table50%1/2
A
A= $data->{"failed-session-count"}
Aresult
11
00
34 );
35 13 return $self;
36 }
37  
38  
39 4 ▶sub as_struct($self) {
Subroutine as_struct: called CC=6 SCAR=18.0
Pod documented
40 return {
41 4 ▶ 'result-type' => $self->result_type,
Branch: 5 branches
BranchTrueFalseTotal
$self->sending_mta_ip ? : 4 0 4
$self->receiving_mx_helo ? : 1 3 4
$self->receiving_ip ? : 3 1 4
$self->additional_information ? : 2 2 4
$self->failure_reason_code ? : 2 2 4
42 $self->sending_mta_ip ? ( 'sending-mta-ip' => $self->sending_mta_ip->ip ) : (),
43 'receiving-mx-hostname' => $self->receiving_mx_hostname,
44 $self->receiving_mx_helo ? ( 'receiving-mx-helo' => $self->receiving_mx_helo ) : (),
45 $self->receiving_ip ? ( 'receiving-ip' => $self->receiving_ip->ip ) : (),
46 'failed-session-count' => $self->failed_session_count,
47 $self->additional_information ? ( 'additional-information' => $self->additional_information ) : (),
48 $self->failure_reason_code ? ( 'failure-reason-code' => $self->failure_reason_code ) : (),
49 };
50 }
51  
52  
53 5 ▶sub as_string($self) {
Subroutine as_string: called CC=6 SCAR=18.0
Pod documented
54 5 ▶ my $receiving_ip = $self->receiving_ip ? ' ('.$self->receiving_ip->ip.')' : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->receiving_ip ? : 4 1 5
55 5 ▶ return join( "\n",
Branch: 4 branches
BranchTrueFalseTotal
$self->sending_mta_ip ? : 5 0 5
$self->receiving_mx_helo ? : 2 3 5
$self->additional_information ? : 3 2 5
$self->failure_reason_code ? : 3 2 5
56 ' Failure:',
57 ' Result-Type: '.$self->result_type,
58 $self->sending_mta_ip ? (' Sending-MTA-IP: '.$self->sending_mta_ip->ip) : (),
59 ' Receiving-MX-Hostname: '.$self->receiving_mx_hostname . $receiving_ip,
60 $self->receiving_mx_helo ? (' Receiving-MX-HELO: '.$self->receiving_mx_helo) : (),
61 ' Failed-Session-Count: '.$self->failed_session_count,
62 $self->additional_information ? (' Additional-Information: '.$self->additional_information ) : (),
63 $self->failure_reason_code ? (' Failure-Reason-Code: '.$self->failure_reason_code ) : (),
64 );
65 }
66  
67 3 ▶sub _register_prometheus($self,$prometheus) {
Subroutine _register_prometheus: called CC=1 SCAR=0.0
68 3 $prometheus->declare('tlsrpt_failures_total', help=>'TLSRPT failures', type=>'counter' );
69 }
70  
71  
72 3 ▶sub process_prometheus($self,$policy,$report,$prometheus) {
Subroutine process_prometheus: called CC=3 SCAR=11.1
Pod documented
73 3 $self->_register_prometheus($prometheus);
74 3 ▶ $prometheus->add('tlsrpt_failures_total',$self->failed_session_count,{
Branch: 1 branch
BranchTrueFalseTotal
$self->receiving_ip ? : 2 1 3
Condition50%1/2
$self->receiving_mx_helo // ""
l!l
03
MC/DC0%0/1
$self->receiving_mx_helo // ""
$self->receiving_mx_helo
Truth table50%1/2
A
A= $self->receiving_mx_helo
Aresult
11
00
75 organization_name=>$report->organization_name,
76 policy_type=>$policy->policy_type,
77 policy_domain=>$policy->policy_domain,
78 policy_mx_host=>$policy->policy_mx_host,
79 result_type=>$self->result_type,
80 sending_mta_ip=>$self->sending_mta_ip,
81 receiving_mx_hostname=>$self->receiving_mx_hostname,
82 receiving_mx_helo=>$self->receiving_mx_helo // '',
83 receiving_ip=>($self->receiving_ip?$self->receiving_ip->ip:''),
84 });
85 }
86  
87 1 ▶sub _csv_headers($self) {
Subroutine _csv_headers: called CC=1 SCAR=0.0
88 return (
89 1 'result type',
90 'sending mta ip',
91 'receiving mx hostname',
92 'receiving mx helo',
93 'receiving ip',
94 'failed session count',
95 'additional information',
96 'failure reason code',
97 );
98 }
99  
100 3 ▶sub _csv_fragment($self) {
Subroutine _csv_fragment: called CC=5 SCAR=16.2
101 return (
102 3 ▶ $self->result_type,
Branch: 1 branch
BranchTrueFalseTotal
$self->receiving_ip ? : 2 1 3
Condition83%5/6
$self->receiving_mx_helo // ""
l!l
03
$self->additional_information // ""
l!l
12
$self->failure_reason_code // ""
l!l
12
MC/DC0%0/1
$self->receiving_mx_helo // ""
$self->receiving_mx_helo
MC/DC100%1/1
$self->additional_information // ""
$self->additional_information
MC/DC100%1/1
$self->failure_reason_code // ""
$self->failure_reason_code
Truth table50%1/2
A
A= $self->receiving_mx_helo
Aresult
11
00
Truth table100%2/2
A
A= $self->additional_information
Aresult
11
00
Truth table100%2/2
A
A= $self->failure_reason_code
Aresult
11
00
103 $self->sending_mta_ip->ip,
104 $self->receiving_mx_hostname,
105 $self->receiving_mx_helo // '',
106 $self->receiving_ip ? $self->receiving_ip->ip : '',
107 $self->failed_session_count,
108 $self->additional_information // '',
109 $self->failure_reason_code // '',
110 );
111 }
112  
113 9 1;
114  
115 __END__
« TLSRPT/App/Command/csv.pm ↑ Summary TLSRPT/Policy.pm »