DKIM/Policy.pm

filter: Statementstmt 71.2% 52 / 73 Branchbran 30.0% 6 / 20 Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 75.0% 9 / 12 Podpod 57.1% 4 / 7 totaltotal 58.4% 73 / 125 CC 17 SCAR 28.3
CC
17
Cov
59%
apply
56.0
__ANON__
7.3
fetch_async
4.4
CRAP 16.9
« DKIM/ARC/Verifier.pm ↑ Summary DKIM/DNS.pm »
1 package Mail::DKIM::Policy;
2 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 our $VERSION = '1.20240923'; # VERSION
5 # ABSTRACT: abstract base class for originator "signing" policies
6  
7 # Copyright 2005-2007 Messiah College.
8 # Jason Long <jlong@messiah.edu>
9  
10 # Copyright (c) 2004 Anthony D. Urso. All rights reserved.
11 # This program is free software; you can redistribute it and/or
12 # modify it under the same terms as Perl itself.
13  
14 7 ▶use Mail::DKIM::DNS;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 1 ▶sub fetch {
Subroutine fetch: called CC=1 SCAR=0.0
Pod undocumented
18 1 my $class = shift;
19 1 my $waiter = $class->fetch_async(@_);
20 1 return $waiter->();
21 }
22  
23 1 ▶sub fetch_async {
Subroutine fetch_async: called CC=4 SCAR=14.7
Pod undocumented
24 1 my $class = shift;
25 1 my %prms = @_;
26  
27 1 ▶ ( $prms{'Protocol'} eq 'dns' )
Branch: 1 branch
BranchTrueFalseTotal
$prms{"Protocol"} eq "dns" or die qq[invalid protocol '$prms{"Protocol"}'\n] 1 0 1
28 or die "invalid protocol '$prms{Protocol}'\n";
29  
30 1 my $host = $class->get_lookup_name( \%prms );
31 1 ▶ my %callbacks = %{ $prms{Callbacks} || {} };
Condition50%1/2
$prms{'Callbacks'} || {}
l!l
01
MC/DC0%0/1
$prms{'Callbacks'} || {}
$prms{'Callbacks'}
Truth table50%1/2
A
A= $prms{'Callbacks'}
Aresult
11
00
32 1 ▶ my $on_success = $callbacks{Success} || sub { $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$callbacks{'Success'} || sub { $_[0]; }
l!l&&r!l&&!r
010
MC/DC0%0/2
$callbacks{'Success'} || sub { $_[0]; }
$callbacks{'Success'} sub { $_[0]; }
Truth table33%1/3
A || B
A= $callbacks{'Success'}B= sub { $_[0]; }
ABresult
1X1
011
000
33 1 ▶ $callbacks{Success} = sub {
Subroutine __ANON__: called CC=6 SCAR=19.9
34 1 my @resp = @_;
35 1 ▶ unless (@resp) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@resp) 0 1 1
36  
37 # no requested resource records or NXDOMAIN,
38 # use default policy
39 0 return $on_success->( $class->default );
40 }
41  
42 1 my $strn;
43 1 foreach my $rr (@resp) {
44 1 ▶ next unless $rr->type eq 'TXT';
Branch: 1 branch
BranchTrueFalseTotal
unless $rr->type eq "TXT" 0 1 1
45  
46 # join with no intervening spaces, RFC 5617
47 1 ▶ if ( $rr->can('txtdata') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rr->can('txtdata')) { } 1 0 1
48  
49 # must call txtdata() in a list context
50 1 $strn = join '', $rr->txtdata;
51 }
52 else {
53 # char_str_list method is 'historical'
54 0 $strn = join '', $rr->char_str_list;
55 }
56 }
57  
58 1 ▶ unless ($strn) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($strn) 0 1 1
59  
60 # empty record found in DNS, use default policy
61 0 return $on_success->( $class->default );
62 }
63  
64 my $self = $class->parse(
65 String => $strn,
66 Domain => $prms{Domain},
67 1 );
68 1 return $on_success->($self);
69 1 };
70  
71 #
72 # perform DNS query for domain policy...
73 #
74 1 my $waiter =
75 Mail::DKIM::DNS::query_async( $host, 'TXT', Callbacks => \%callbacks, );
76 1 return $waiter;
77 }
78  
79 8 ▶sub parse {
Subroutine parse: called CC=3 SCAR=11.0
Pod undocumented
80 8 my $class = shift;
81 8 my %prms = @_;
82  
83 8 my $text = $prms{'String'};
84 8 my %tags;
85 8 foreach my $tag ( split /;/, $text ) {
86  
87 # strip whitespace
88 9 $tag =~ s/^\s+|\s+$//g;
89  
90 9 my ( $tagname, $value ) = split /=/, $tag, 2;
91 9 ▶ unless ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 9 9
92 0 die "policy syntax error\n";
93 }
94  
95 9 $tagname =~ s/\s+$//;
96 9 $value =~ s/^\s+//;
97 9 $tags{$tagname} = $value;
98 }
99  
100 8 $prms{tags} = \%tags;
101 8 return bless \%prms, $class;
102 }
103  
104  
105 0 ▶sub apply {
Subroutine apply: not called CC=7 SCAR=40.3
Pod documented
106 0 my $self = shift;
107 0 my ($dkim) = @_;
108  
109 0 my $first_party;
110 0 foreach my $signature ( $dkim->signatures ) {
111 0 ▶ next if $signature->result ne 'pass';
Branch: 1 branch
BranchTrueFalseTotal
if $signature->result ne "pass" 0 0 0
112  
113 0 my $oa = $dkim->message_sender->address;
114 0 ▶ if ( $signature->identity_matches($oa) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature->identity_matches($oa)) 0 0 0
115  
116 # found a first party signature
117 0 $first_party = 1;
118 0 last;
119 }
120 }
121  
122 0 ▶ return 'accept' if $first_party;
Branch: 1 branch
BranchTrueFalseTotal
if $first_party 0 0 0
123 0 ▶ return 'reject' if ( $self->signall && !$self->testing );
Branch: 1 branch
BranchTrueFalseTotal
if $self->signall and not $self->testing 0 0 0
Condition0%0/3
$self->signall and not $self->testing
!ll&&!rl&&r
000
MC/DC0%0/2
$self->signall and not $self->testing
$self->signall not $self->testing
Truth table0%0/3
A and not(B)
A= $self->signallB= not $self->testing
ABresult
0X0
100
111
124 0 return 'neutral';
125 }
126  
127  
128 1 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
129 1 my $self = shift;
130  
131 return join(
132 2 '; ', map { "$_=" . $self->{tags}->{$_} }
133 1 keys %{ $self->{tags} }
134 );
135 }
136  
137  
138 0 ▶sub is_implied_default_policy {
Subroutine is_implied_default_policy: not called CC=1 SCAR=6.9
Pod documented
139 0 my $self = shift;
140 0 my $default_policy = ref($self)->default;
141 0 return ( $self == $default_policy );
142 }
143  
144  
145 0 ▶sub location {
Subroutine location: not called CC=1 SCAR=6.9
Pod documented
146 0 my $self = shift;
147 0 return $self->{Domain};
148 }
149  
150  
151 7 1;
152  
153 __END__
« DKIM/ARC/Verifier.pm ↑ Summary DKIM/DNS.pm »