| 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
MC/DC0%0/1
$ENV{"CONTENT_LENGTH"} // 0
$ENV{"CONTENT_LENGTH"}
Truth table50%1/2
A
A= $ENV{"CONTENT_LENGTH"}
| |||||||||||||
| 17 | 1 | my $body = ''; | |||||||||||
| 18 | 1 | ▶ | if ($len) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 19 | 1 | ▶ | if ($len > $MAX) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 // ""
MC/DC0%0/1
readline STDIN // ""
readline STDIN
Truth table0%0/2
A
A= readline STDIN
| |||||||||||||
| 27 | } | ||||||||||||
| 28 | |||||||||||||
| 29 | 1 | my $rep = eval { Mail::DKIM2::Validate::report($body, DnsPath => $dns_path) }; | |||||||||||
| 30 | 1 | ▶ | if (my $err = $@) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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; | |||||||||||