1#!perl
2use 5.008;
3use strict;
4use warnings FATAL => 'all';
5use lib 't';
6use Test::More;
7use Test::Exception;
8
9use lib 'lib';
10use Mail::AuthenticationResults::Parser;
11
12my $Input = [
13  'iprev=fail policy.iprev=123.123.123.123 (NOT FOUND)',
14  'x-ptr=fail x-ptr-helo=bad.name.google.com x-ptr-lookup=',
15  'spf=fail smtp.mailfrom=test@goestheweasel.com smtp.helo=bad.name.google.com',
16  'dkim=none (no signatures found)',
17  'x-google-dkim=none (no signatures found)',
18  'dmarc=fail (p=none,d=none) header.from=marcbradshaw.net',
19  'dmarc=fail (p=reject,d=reject) header.from=goestheweasel.com',
20  'dmarc=none (p=none,d=none) header.from=example.com'
21];
22
23my $InputARHeader = join( ";\n", 'test.example.com', @$Input );
24
25my $Parser = Mail::AuthenticationResults::Parser->new( $InputARHeader );
26my $Parsed = $Parser->parsed();
27
28my $None = 'test.example.com; iprev=fail policy.iprev=123.123.123.123 (NOT FOUND); x-ptr=fail x-ptr-helo=bad.name.google.com x-ptr-lookup=""; spf=fail smtp.mailfrom=test@goestheweasel.com smtp.helo=bad.name.google.com; dkim=none (no signatures found); x-google-dkim=none (no signatures found); dmarc=fail (p=none,d=none) header.from=marcbradshaw.net; dmarc=fail (p=reject,d=reject) header.from=goestheweasel.com; dmarc=none (p=none,d=none) header.from=example.com';
29
30my $Entry = 'test.example.com;
31    iprev=fail policy.iprev=123.123.123.123 (NOT FOUND);
32    x-ptr=fail x-ptr-helo=bad.name.google.com x-ptr-lookup="";
33    spf=fail smtp.mailfrom=test@goestheweasel.com smtp.helo=bad.name.google.com;
34    dkim=none (no signatures found);
35    x-google-dkim=none (no signatures found);
36    dmarc=fail (p=none,d=none) header.from=marcbradshaw.net;
37    dmarc=fail (p=reject,d=reject) header.from=goestheweasel.com;
38    dmarc=none (p=none,d=none) header.from=example.com';
39
40my $SubEntry = 'test.example.com;
41    iprev=fail
42        policy.iprev=123.123.123.123 (NOT FOUND);
43    x-ptr=fail
44        x-ptr-helo=bad.name.google.com
45        x-ptr-lookup="";
46    spf=fail
47        smtp.mailfrom=test@goestheweasel.com
48        smtp.helo=bad.name.google.com;
49    dkim=none (no signatures found);
50    x-google-dkim=none (no signatures found);
51    dmarc=fail (p=none,d=none)
52        header.from=marcbradshaw.net;
53    dmarc=fail (p=reject,d=reject)
54        header.from=goestheweasel.com;
55    dmarc=none (p=none,d=none)
56        header.from=example.com';
57
58my $Full = 'test.example.com;
59    iprev=fail
60        policy.iprev=123.123.123.123
61            (NOT FOUND);
62    x-ptr=fail
63        x-ptr-helo=bad.name.google.com
64        x-ptr-lookup="";
65    spf=fail
66        smtp.mailfrom=test@goestheweasel.com
67        smtp.helo=bad.name.google.com;
68    dkim=none
69        (no signatures found);
70    x-google-dkim=none
71        (no signatures found);
72    dmarc=fail
73        (p=none,d=none)
74        header.from=marcbradshaw.net;
75    dmarc=fail
76        (p=reject,d=reject)
77        header.from=goestheweasel.com;
78    dmarc=none
79        (p=none,d=none)
80        header.from=example.com';
81
82
83is( $Parsed->set_indent_style( 'none' )->as_string(), $None, 'None stringifies correctly' );
84is( $Parsed->set_indent_style( 'entry' )->as_string(), $Entry, 'Entry stringifies correctly' );
85is( $Parsed->set_indent_style( 'subentry' )->as_string(), $SubEntry, 'SubEntry stringifies correctly' );
86is( $Parsed->set_indent_style( 'full' )->as_string(), $Full, 'Full stringifies correctly' );
87dies_ok( sub{ $Parsed->set_indent_style( 'bogus_indent_style' ); }, 'invalid style dies' );
88
89done_testing();
90
91