Authentication/Handler/TrustedIP.pm

filter: Statementstmt 97.9% 47 / 48 Branchbran 87.5% 7 / 8 Conditioncond 81.8% 9 / 11 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 12 / 12 Podpod 33.3% 2 / 6 totaltotal 88.8% 80 / 90 CC 10 SCAR 15.3
CC
10
Cov
94%
is_trusted_ip_address
9.2
connect_callback
2.0
BEGIN
1.0
CRAP 4.6
« Authentication/Handler/SenderID.pm ↑ Summary Authentication/Handler/Blocker.pm »
1 package Mail::Milter::Authentication::Handler::TrustedIP;
2 31 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 31 ▶use Mail::Milter::Authentication::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: Handler class for Trusted IP addresses
7 31 our $VERSION = '4.20261116'; # VERSION
8 31 ▶use base 'Mail::Milter::Authentication::Handler';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 31 ▶use Net::IP;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶sub default_config {
Subroutine default_config: called CC=1 SCAR=0.0
Pod undocumented
12 return {
13 1 'trusted_ip_list' => [],
14 };
15 }
16  
17 1 ▶sub grafana_rows {
Subroutine grafana_rows: called CC=1 SCAR=0.0
Pod undocumented
18 1 my ( $self ) = @_;
19 1 my @rows;
20 1 push @rows, $self->get_json( 'TrustedIP_metrics' );
21 1 return \@rows;
22 }
23  
24 95 ▶sub is_trusted_ip_address {
Subroutine is_trusted_ip_address: called CC=9 SCAR=22.2
Pod documented
25 95 my ( $self, $ip_obj ) = @_;
26 95 my $config = $self->handler_config();
27 95 ▶ return 0 if not exists( $config->{'trusted_ip_list'} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $config->{"trusted_ip_list"} 24 71 95
28 71 my $trusted = 0;
29 71 foreach my $trusted_ip ( @{ $config->{'trusted_ip_list'} } ) {
30 84 my $trusted_obj = Net::IP->new($trusted_ip);
31 84 ▶ if ( !$trusted_obj ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $trusted_obj) { } 0 84 84
32 0 $self->log_error( 'TrustedIP: Could not parse Trusted IP '.$trusted_ip );
33 }
34 else {
35 84 ▶ my $is_overlap = $ip_obj->overlaps($trusted_obj) || 0;
Condition100%2/2
$ip_obj->overlaps($trusted_obj) || 0
l!l
678
MC/DC100%1/1
$ip_obj->overlaps($trusted_obj) || 0
$ip_obj->overlaps($trusted_obj)
Truth table100%2/2
A
A= $ip_obj->overlaps($trusted_obj)
Aresult
11
00
36 84 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_A_IN_B_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_B_IN_A_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_PARTIAL_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_IDENTICAL) 6 78 84
Condition77%7/9
$is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_A_IN_B_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_B_IN_A_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_PARTIAL_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_IDENTICAL
l!l&&r!l&&!r
2478
$is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_A_IN_B_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_B_IN_A_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_PARTIAL_OVERLAP
l!l&&r!l&&!r
2082
$is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_A_IN_B_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_B_IN_A_OVERLAP
l!l&&r!l&&!r
2082
MC/DC50%2/4
$is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_A_IN_B_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_B_IN_A_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_PARTIAL_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_IDENTICAL
$is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_A_IN_B_OVERLAP $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_B_IN_A_OVERLAP $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_PARTIAL_OVERLAP $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_IDENTICAL
Truth table60%3/5
A or B or C or D
A= $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_A_IN_B_OVERLAPB= $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_B_IN_A_OVERLAPC= $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_PARTIAL_OVERLAPD= $is_overlap == $Mail::Milter::Authentication::Handler::TrustedIP::IP_IDENTICAL
ABCDresult
1XXX1
01XX1
001X1
00011
00000
37 $is_overlap == $IP_A_IN_B_OVERLAP
38 || $is_overlap == $IP_B_IN_A_OVERLAP # Should never happen
39 || $is_overlap == $IP_PARTIAL_OVERLAP # Should never happen
40 || $is_overlap == $IP_IDENTICAL
41 )
42 {
43 6 $trusted = 1;
44 }
45 }
46 }
47 71 return $trusted;
48 }
49  
50 48 ▶sub register_metrics {
Subroutine register_metrics: called CC=1 SCAR=0.0
Pod documented
51 return {
52 48 'trustedip_connect_total' => 'The number of connections from a trusted IP',
53 };
54 }
55  
56 95 ▶sub connect_callback {
Subroutine connect_callback: called CC=2 SCAR=6.9
Pod undocumented
57 95 my ( $self, $hostname, $ip ) = @_;
58 95 $self->{'is_trusted_ip_address'} = 0;
59 95 ▶ if ( $self->is_trusted_ip_address($ip) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_trusted_ip_address($ip)) 6 89 95
60 6 $self->dbgout( 'TrustedIP', 'pass', LOG_DEBUG );
61 6 my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'x-trusted-ip' )->safe_set_value( 'pass' );
62 6 $self->add_c_auth_header( $header );
63 6 $self->{'is_trusted_ip_address'} = 1;
64 6 $self->metric_count( 'trustedip_connect_total' );
65 }
66 }
67  
68 126 ▶sub close_callback {
Subroutine close_callback: called CC=1 SCAR=0.0
Pod undocumented
69 126 my ( $self ) = @_;
70 126 delete $self->{'is_trusted_ip_address'};
71 }
72  
73 31 1;
74  
75 __END__
« Authentication/Handler/SenderID.pm ↑ Summary Authentication/Handler/Blocker.pm »