| 1 | package Mail::TLSRPT::Failure; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: TLSRPT failure object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 14 | our $VERSION = '2.20261112'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use 5.20.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 14 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 14 | ▶ | use Mail::TLSRPT::Pragmas; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 14 | ▶ | use Net::IP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 14 | has result_type => (is => 'rw', isa => Str, required => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 68 | ▶ | has sending_mta_ip => (is => 'rw', isa => class_type('Net::IP'), required => 0,coerce => sub{&_coerce_ip}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 14 | has receiving_mx_hostname => (is => 'rw', isa => Str, required => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 14 | has receiving_mx_helo => (is => 'rw', isa => Str, required => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 28 | ▶ | 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 | 14 | has failed_session_count => (is => 'rw', isa => Int, required => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 14 | has additional_information => (is => 'rw', isa => Str, required => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 14 | has failure_reason_code => (is => 'rw', isa => Str, required => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 96 | ▶ | sub _coerce_ip { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_coerce_ip: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 96 | my $ip = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 96 | ▶ | return $ip if ref $ip eq 'Net::IP'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # An address Net::IP can't parse is left as it was, for the type check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # to name in its error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 95 | ▶ | return Net::IP->new($ip) // $ip; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
"Net::IP"->new($ip) // $ip
MC/DC0%0/2
"Net::IP"->new($ip) // $ip
"Net::IP"->new($ip)
$ip
Truth table66%2/3
A // B
A= "Net::IP"->new($ip)B= $ip
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 54 | ▶ | sub new_from_data($class,$data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_data: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 54 | ▶ | croak 'Failure is not an object' unless ref $data eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | my $self = $class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | result_type => $data->{'result-type'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | $data->{'sending-mta-ip'} ? ( sending_mta_ip => $data->{'sending-mta-ip'} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | $data->{'receiving-mx-hostname'} ? ( receiving_mx_hostname => $data->{'receiving-mx-hostname'} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | $data->{'receiving-mx-helo'} ? ( receiving_mx_helo => $data->{'receiving-mx-helo'} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | $data->{'receiving-ip'} ? ( receiving_ip => $data->{'receiving-ip'} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | failed_session_count => $data->{'failed-session-count'} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | $data->{'additional-information'} ? ( additional_information => $data->{'additional-information'} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 53 | ▶ | $data->{'failure-reason-code'} ? ( failure_reason_code => $data->{'failure-reason-code'} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
Condition50%1/2
$data->{"failed-session-count"} // 0
MC/DC0%0/1
$data->{"failed-session-count"} // 0
$data->{"failed-session-count"}
Truth table50%1/2
A
A= $data->{"failed-session-count"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 51 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 16 | ▶ | sub registered_result_types($class) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
registered_result_types: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 16 | return 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 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 15 | ▶ | sub is_registered_result_type($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_registered_result_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 15 | return scalar grep { $_ eq $self->result_type } $self->registered_result_types; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 7 | ▶ | sub as_struct($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_struct: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 7 | ▶ | 'result-type' => $self->result_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | $self->sending_mta_ip ? ( 'sending-mta-ip' => $self->sending_mta_ip->ip ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | $self->receiving_mx_hostname ? ( 'receiving-mx-hostname' => $self->receiving_mx_hostname ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | $self->receiving_mx_helo ? ( 'receiving-mx-helo' => $self->receiving_mx_helo ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | $self->receiving_ip ? ( 'receiving-ip' => $self->receiving_ip->ip ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 'failed-session-count' => $self->failed_session_count, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | $self->additional_information ? ( 'additional-information' => $self->additional_information ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | $self->failure_reason_code ? ( 'failure-reason-code' => $self->failure_reason_code ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 7 | ▶ | sub as_string($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 7 | ▶ | my $receiving_ip = $self->receiving_ip ? ' ('.$self->receiving_ip->ip.')' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 7 | ▶ | return join( "\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ' Failure:', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ' Result-Type: '.$self->result_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | $self->sending_mta_ip ? (' Sending-MTA-IP: '.$self->sending_mta_ip->ip) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | $self->receiving_mx_hostname ? (' Receiving-MX-Hostname: '.$self->receiving_mx_hostname . $receiving_ip) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | : $self->receiving_ip ? (' Receiving-IP: '.$self->receiving_ip->ip) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | $self->receiving_mx_helo ? (' Receiving-MX-HELO: '.$self->receiving_mx_helo) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ' Failed-Session-Count: '.$self->failed_session_count, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | $self->additional_information ? (' Additional-Information: '.$self->additional_information ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | $self->failure_reason_code ? (' Failure-Reason-Code: '.$self->failure_reason_code ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 4 | ▶ | sub _register_prometheus($self,$prometheus) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_register_prometheus: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 4 | $prometheus->declare('tlsrpt_failures_total', help=>'TLSRPT failures', type=>'counter' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | ▶ | sub process_prometheus($self,$policy,$report,$prometheus) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_prometheus: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | $self->_register_prometheus($prometheus); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 4 | ▶ | $prometheus->add('tlsrpt_failures_total',$self->failed_session_count,{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition75%3/4
$self->receiving_mx_hostname // ""
$self->receiving_mx_helo // ""
MC/DC100%1/1
$self->receiving_mx_hostname // ""
$self->receiving_mx_hostname
MC/DC0%0/1
$self->receiving_mx_helo // ""
$self->receiving_mx_helo
Truth table100%2/2
A
A= $self->receiving_mx_hostname
Truth table50%1/2
A
A= $self->receiving_mx_helo
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | organization_name=>$report->organization_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | policy_type=>$policy->policy_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | policy_domain=>$policy->policy_domain, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | policy_mx_host=>$policy->policy_mx_host, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | result_type=>$self->result_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | sending_mta_ip=>($self->sending_mta_ip?$self->sending_mta_ip->ip:''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | receiving_mx_hostname=>$self->receiving_mx_hostname // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | receiving_mx_helo=>$self->receiving_mx_helo // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | receiving_ip=>($self->receiving_ip?$self->receiving_ip->ip:''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | sub _csv_headers($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_csv_headers: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | 'result type', | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 'sending mta ip', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 'receiving mx hostname', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 'receiving mx helo', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 'receiving ip', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 'failed session count', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 'additional information', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 'failure reason code', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 4 | ▶ | sub _csv_fragment($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_csv_fragment: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 4 | ▶ | $self->result_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition87%7/8
$self->receiving_mx_hostname // ""
$self->receiving_mx_helo // ""
$self->additional_information // ""
$self->failure_reason_code // ""
MC/DC100%1/1
$self->receiving_mx_hostname // ""
$self->receiving_mx_hostname
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 table100%2/2
A
A= $self->receiving_mx_hostname
Truth table50%1/2
A
A= $self->receiving_mx_helo
Truth table100%2/2
A
A= $self->additional_information
Truth table100%2/2
A
A= $self->failure_reason_code
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | $self->sending_mta_ip ? $self->sending_mta_ip->ip : '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | $self->receiving_mx_hostname // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | $self->receiving_mx_helo // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | $self->receiving_ip ? $self->receiving_ip->ip : '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | $self->failed_session_count, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | $self->additional_information // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | $self->failure_reason_code // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 14 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||