File: 15.Report.Aggregate.Record.t

package info (click to toggle)
libmail-dmarc-perl 1.20240314-1
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 1,852 kB
  • sloc: perl: 4,944; xml: 13; makefile: 10; sh: 1
file content (93 lines) | stat: -rw-r--r-- 3,013 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use strict;
use warnings;

use Data::Dumper;
use Test::More;

use lib 'lib';

my $mod = 'Mail::DMARC::Report::Aggregate::Record';
use_ok($mod);
my $rec = $mod->new;
isa_ok( $rec, $mod );

my $ip = '192.2.1.1';

test_identifiers();
test_auth_results();
test_row();

done_testing();
exit;

sub test_identifiers {
    my $id = $rec->identifiers;

    ok( $id->envelope_to( 'to.example.com' ), "envelope_to, set");
    ok( $id->envelope_to eq 'to.example.com', "envelope_to, get");

    ok( $id->header_from( 'from.example.com' ), "header_from, set");
    ok( $id->header_from eq 'from.example.com', "header_from, get");

    ok( $id->envelope_from( 'from.example.com' ), "envelope_from, set");
    ok( $id->envelope_from eq 'from.example.com', "envelope_from, get");

    # one shot
    $id = $rec->identifiers(
        envelope_to  => 'to.example.com',
        header_from  => 'from.example.com',
        envelope_from=> 'from.example.com',
    );
    ok( $id->envelope_to eq 'to.example.com', "envelope_to, get");
    ok( $id->header_from eq 'from.example.com', "header_from, get");
    ok( $id->envelope_from eq 'from.example.com', "envelope_from, get");
};

sub test_auth_results {
    my $ar = $rec->auth_results;

    my $expected = bless { dkim => [], spf => [] }, 'Mail::DMARC::Report::Aggregate::Record::Auth_Results';
    is_deeply( $ar, $expected, "auth_results, empty");

    my $spf1 = { domain => 'first', result => 'none', scope => 'helo' };
    $expected = { dkim => [], spf => [ $spf1 ]};
    $ar->spf( { domain => 'first', result => 'none', scope => 'helo' } );
    is_deeply( $ar, $expected, "auth_results, one SPF");

    my $spf2 = { domain => 'second', scope => 'helo', result => 'temperror' };
    $expected = { dkim => [], spf => [ $spf1, $spf2 ] };
    $ar->spf( { domain => 'second', result => 'temperror', scope => 'helo' } );
    is_deeply( $ar, $expected, "auth_results, two SPF");

    my $dkim1 = { domain => 'first', result => 'none' };
    $expected = { dkim => [ $dkim1 ], spf => [ $spf1, $spf2 ] };
    $ar->dkim( $dkim1 );
    is_deeply( $ar, $expected, "auth_results, two SPF, one DKIM");

    my $dkim2 = { domain => 'second', result => 'none' };
    $expected = { dkim => [ $dkim1, $dkim2 ], spf => [ $spf1, $spf2 ] };
    $ar->dkim( $dkim2 );
    is_deeply( $ar, $expected, "auth_results, two SPF, two DKIM");
};

sub test_row {
    my $ar = $rec->row;

    my $expected = bless {}, 'Mail::DMARC::Report::Aggregate::Record::Row';
    is_deeply( $ar, $expected, "row, empty");

    $ar->source_ip( $ip );
    $expected = { source_ip => $ip };
    is_deeply( $ar, $expected, "row, source_ip");

    $ar->count( 1 );
    $expected = { count => 1, source_ip => $ip };
    is_deeply( $ar, $expected, "row, count");

    my $pe = { disposition => 'none', spf => 'fail', dkim => 'fail' };
    $ar->policy_evaluated( $pe );
    $pe->{reason} = [];
    $expected = { policy_evaluated => $pe, count => 1, source_ip => $ip };
    is_deeply( $ar, $expected, "row, policy_evaluated");
};