bin/validate.cgi

filter: Statementstmt 85.7% 36 / 42 Branchbran 50.0% 3 / 6 Conditioncond 25.0% 1 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 77.0% 47 / 61 CC 1 SCAR 0.0
CC
1
Cov
77%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Mail/build-fraud-test.pl ↑ Summary blib/lib/Mail/DKIM2.pm »
1 #!/usr/bin/perl
2 1 ▶use 5.020; use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use lib "$FindBin::Bin/../lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use JSON ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Mail::DKIM2::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 binmode STDIN; binmode STDOUT;
9 1 my $MAX = 256 * 1024;
10 # Production validates against LIVE DNS (like the milter and any real-world
11 # verifier), so a broken/truncated key record is surfaced, not masked. The
12 # dns.json override is available ONLY for offline testing via the
13 # DKIM2_DNS_JSON env var, and is deliberately NOT defaulted here.
14 1 my $dns_path = $ENV{DKIM2_DNS_JSON};
15  
16 1 ▶my $len = $ENV{CONTENT_LENGTH} // 0;
Condition50%1/2
$ENV{"CONTENT_LENGTH"} // 0
l!l
10
MC/DC0%0/1
$ENV{"CONTENT_LENGTH"} // 0
$ENV{"CONTENT_LENGTH"}
Truth table50%1/2
A
A= $ENV{"CONTENT_LENGTH"}
Aresult
11
00
17 1 my $body = '';
18 1 ▶if ($len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len) { } 1 0 1
19 1 ▶ if ($len > $MAX) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $MAX) 0 1 1
20 0 print "Status: 413 Payload Too Large\r\nContent-Type: application/json\r\n\r\n";
21 0 print JSON::encode_json({ overall => 'fail', summary => 'message too large (max 256 KB)', levels => [] });
22 0 exit 0;
23 }
24 1 read(STDIN, $body, $len);
25 } else {
26 0 ▶ local $/; $body = <STDIN> // '';
Condition0%0/2
readline STDIN // ""
l!l
00
MC/DC0%0/1
readline STDIN // ""
readline STDIN
Truth table0%0/2
A
A= readline STDIN
Aresult
11
00
27 }
28  
29 1 my $rep = eval { Mail::DKIM2::Validate::report($body, DnsPath => $dns_path) };
30 1 ▶if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 1 1
31 0 $rep = { overall => 'fail', summary => "internal error: $err", counts => {}, levels => [] };
32 }
33  
34 1 my $json = JSON->new->canonical(1)->encode($rep);
35 1 print "Status: 200 OK\r\nContent-Type: application/json\r\nAccess-Control-Allow-Origin: *\r\n\r\n";
36 1 print $json;
37 1 exit 0;
« blib/lib/Mail/build-fraud-test.pl ↑ Summary blib/lib/Mail/DKIM2.pm »