DKIM/Policy.pm

filter: Statementstmt 71.6% 53 / 74 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.7% 74 / 126 CC 17 SCAR 28.3
CC
17
Cov
60%
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 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 our $VERSION = '1.20261116'; # 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 10 ▶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 10 ▶sub parse {
Subroutine parse: called CC=3 SCAR=11.0
Pod undocumented
80 10 my $class = shift;
81 10 my %prms = @_;
82  
83 10 my $text = $prms{'String'};
84 10 my %tags;
85 10 foreach my $tag ( split /;/, $text ) {
86  
87 # strip whitespace (not s/^\s+|\s+$//g, which is quadratic)
88 12 $tag =~ s/^\s+//;
89 12 $tag =~ s/\s+$//;
90  
91 12 my ( $tagname, $value ) = split /=/, $tag, 2;
92 12 ▶ unless ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 12 12
93 0 die "policy syntax error\n";
94 }
95  
96 12 $tagname =~ s/\s+$//;
97 12 $value =~ s/^\s+//;
98 12 $tags{$tagname} = $value;
99 }
100  
101 10 $prms{tags} = \%tags;
102 10 return bless \%prms, $class;
103 }
104  
105  
106 0 ▶sub apply {
Subroutine apply: not called CC=7 SCAR=40.3
Pod documented
107 0 my $self = shift;
108 0 my ($dkim) = @_;
109  
110 0 my $first_party;
111 0 foreach my $signature ( $dkim->signatures ) {
112 0 ▶ next if $signature->result ne 'pass';
Branch: 1 branch
BranchTrueFalseTotal
if $signature->result ne "pass" 0 0 0
113  
114 0 my $oa = $dkim->message_sender->address;
115 0 ▶ if ( $signature->identity_matches($oa) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature->identity_matches($oa)) 0 0 0
116  
117 # found a first party signature
118 0 $first_party = 1;
119 0 last;
120 }
121 }
122  
123 0 ▶ return 'accept' if $first_party;
Branch: 1 branch
BranchTrueFalseTotal
if $first_party 0 0 0
124 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
125 0 return 'neutral';
126 }
127  
128  
129 1 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
130 1 my $self = shift;
131  
132 return join(
133 2 '; ', map { "$_=" . $self->{tags}->{$_} }
134 1 keys %{ $self->{tags} }
135 );
136 }
137  
138  
139 0 ▶sub is_implied_default_policy {
Subroutine is_implied_default_policy: not called CC=1 SCAR=6.9
Pod documented
140 0 my $self = shift;
141 0 my $default_policy = ref($self)->default;
142 0 return ( $self == $default_policy );
143 }
144  
145  
146 0 ▶sub location {
Subroutine location: not called CC=1 SCAR=6.9
Pod documented
147 0 my $self = shift;
148 0 return $self->{Domain};
149 }
150  
151  
152 10 1;
153  
154 __END__
« DKIM/ARC/Verifier.pm ↑ Summary DKIM/DNS.pm »