BIMI/App/Command/checkdomain.pm

filter: Statementstmt 39.3% 26 / 66 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 64.2% 9 / 14 Podpod 100% 5 / 5 totaltotal 34.1% 40 / 117 CC 13 SCAR 36.2
CC
13
Cov
29%
execute
90.0
validate_args
30.0
description
2.0
CRAP 37.5
« BIMI/App/Command/checkvmc.pm ↑ Summary BIMI/VMC/Cert.pm »
1 package Mail::BIMI::App::Command::checkdomain;
2 # ABSTRACT: Validate the BIMI assertion record for a given domain
3 1 our $VERSION = '3.20261116'; # VERSION
4 1 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶BEGIN { $ENV{MAIL_BIMI_CACHE_DEFAULT_BACKEND} = 'Null' };
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Mail::BIMI::Prelude;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Mail::BIMI::App -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Mail::BIMI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Mail::BIMI::Indicator;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Mail::BIMI::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Mail::DMARC;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Term::ANSIColor qw{ :constants };
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 0 ▶sub description { 'Check the BIMI assertion record for a given domain' }
Subroutine description: not called CC=1 SCAR=6.9
Pod documented
16 0 ▶sub usage_desc { "%c checkdomain %o <DOMAIN>" }
Subroutine usage_desc: not called CC=1 SCAR=6.9
Pod documented
17  
18 0 ▶sub opt_spec {
Subroutine opt_spec: not called CC=1 SCAR=6.9
Pod documented
19 return (
20 0 [ 'profile=s', 'SVG Profile to validate against ('.join('|',@Mail::BIMI::Indicator::VALIDATOR_PROFILES).')' ],
21 [ 'selector=s', 'Optional selector' ],
22 );
23 }
24  
25 0 ▶sub validate_args($self,$opt,$args) {
Subroutine validate_args: not called CC=5 SCAR=34.0
Pod documented
26 0 ▶ $self->usage_error('No Domain specified') if !@$args;
Branch: 1 branch
BranchTrueFalseTotal
unless @$args 0 0 0
27 0 ▶ $self->usage_error('Multiple Domains specified') if scalar @$args > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$args > 1 0 0 0
28 0 ▶ $self->usage_error('Unknown SVG Profile') if $opt->profile && !grep {;$_ eq $opt->profile} @Mail::BIMI::Indicator::VALIDATOR_PROFILES;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->profile and not grep({$_ eq $opt->profile;} @Mail::BIMI::Indicator::VALIDATOR_PROFILES) 0 0 0
Condition0%0/3
$opt->profile and not grep({$_ eq $opt->profile;} @Mail::BIMI::Indicator::VALIDATOR_PROFILES)
!ll&&!rl&&r
000
MC/DC0%0/2
$opt->profile and not grep({$_ eq $opt->profile;} @Mail::BIMI::Indicator::VALIDATOR_PROFILES)
$opt->profile not grep({$_ eq $opt->profile;} @Mail::BIMI::Indicator::VALIDATOR_PROFILES)
Truth table0%0/3
A and not(B)
A= $opt->profileB= not grep({$_ eq $opt->profile;} @Mail::BIMI::Indicator::VALIDATOR_PROFILES)
ABresult
0X0
100
111
29 }
30  
31 0 ▶sub execute($self,$opt,$args) {
Subroutine execute: not called CC=9 SCAR=45.0
Pod documented
32 0 my $domain = $args->[0];
33 0 ▶ my $selector = $opt->selector // 'default';
Condition0%0/2
$opt->selector // "default"
l!l
00
MC/DC0%0/1
$opt->selector // "default"
$opt->selector
Truth table0%0/2
A
A= $opt->selector
Aresult
11
00
34  
35 0 my $dmarc = Mail::DMARC::PurePerl->new;
36 0 $dmarc->header_from($domain);
37 0 $dmarc->validate;
38 0 $dmarc->result->result('pass');
39 0 ▶ my $bimi = Mail::BIMI->new(
Branch: 1 branch
BranchTrueFalseTotal
$opt->profile ? : 0 0 0
40 dmarc_object => $dmarc,
41 domain => $domain,
42 selector => $selector,
43 options => {
44 ( $opt->profile ? ( svg_profile => $opt->profile ) : () ),
45 },
46 );
47  
48 0 my $record = $bimi->record;
49 # my $record = Mail::BIMI::Record->new( domain => $domain, selector => $selector );
50 0 say "BIMI domain checker";
51 0 say '';
52 0 say 'Requested:';
53 0 say YELLOW.' Domain '.WHITE.': '.CYAN.$domain.RESET;
54 0 say YELLOW.' Selector '.WHITE.': '.CYAN.$selector.RESET;
55 0 say '';
56 0 $record->app_validate;
57 0 ▶ if ( $record->location && $record->location->indicator ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($record->location and $record->location->indicator) 0 0 0
Condition0%0/3
$record->location and $record->location->indicator
!ll&&!rl&&r
000
MC/DC0%0/2
$record->location and $record->location->indicator
$record->location $record->location->indicator
Truth table0%0/3
A and B
A= $record->locationB= $record->location->indicator
ABresult
0X0
100
111
58 0 say '';
59 0 $record->location->indicator->app_validate;
60 }
61 0 ▶ if ( $record->authority && $record->authority->vmc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($record->authority and $record->authority->vmc) 0 0 0
Condition0%0/3
$record->authority and $record->authority->vmc
!ll&&!rl&&r
000
MC/DC0%0/2
$record->authority and $record->authority->vmc
$record->authority $record->authority->vmc
Truth table0%0/3
A and B
A= $record->authorityB= $record->authority->vmc
ABresult
0X0
100
111
62 0 say '';
63 0 $record->authority->vmc->app_validate;
64 0 ▶ if ( $record->authority->vmc->indicator ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($record->authority->vmc->indicator) 0 0 0
65 0 say '';
66 0 $record->authority->vmc->indicator->app_validate;
67 }
68 }
69 0 say '';
70  
71 0 say 'An authenticated email with this record would receive the following BIMI results:';
72 0 say '';
73 0 my $result = $bimi->result;
74 0 say "Authentication-Results: authservid.example.com; ".$result->get_authentication_results;
75 0 my $headers = $result->headers;
76 0 foreach my $header ( sort keys $headers->%* ) {
77 0 say "$header: ".$headers->{$header};
78 }
79  
80 0 $bimi->finish;
81 }
82  
83 1 1;
84  
85 __END__
« BIMI/App/Command/checkvmc.pm ↑ Summary BIMI/VMC/Cert.pm »