]> Sergey Matveev's repositories - public-inbox.git/blob - t/precheck.t
www: remove Plack::Request dependency entirely
[public-inbox.git] / t / precheck.t
1 # Copyright (C) 2014-2015 all contributors <meta@public-inbox.org>
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
3 use strict;
4 use warnings;
5 use Test::More;
6 use Email::Simple;
7 use PublicInbox::MDA;
8
9 sub do_checks {
10         my ($s) = @_;
11
12         my $recipient = 'foo@example.com';
13         ok(!PublicInbox::MDA->precheck($s, $recipient),
14                 "wrong ORIGINAL_RECIPIENT rejected");
15
16         $recipient = 'b@example.com';
17         ok(PublicInbox::MDA->precheck($s, $recipient),
18                 "ORIGINAL_RECIPIENT in To: is OK");
19
20         $recipient = 'c@example.com';
21         ok(PublicInbox::MDA->precheck($s, $recipient),
22                 "ORIGINAL_RECIPIENT in Cc: is OK");
23
24         $recipient = [ 'c@example.com', 'd@example.com' ];
25         ok(PublicInbox::MDA->precheck($s, $recipient),
26                 "alias list is OK");
27 }
28
29 {
30         do_checks(Email::Simple->create(
31                 header => [
32                         From => 'a@example.com',
33                         To => 'b@example.com',
34                         Cc => 'c@example.com',
35                         'Content-Type' => 'text/plain',
36                         Subject => 'this is a subject',
37                         'Message-ID' => '<MID@host>',
38                         Date => 'Wed, 09 Apr 2014 01:28:34 +0000',
39                 ],
40                 body => "hello world\n",
41         ));
42 }
43
44 {
45         do_checks(Email::Simple->create(
46                 header => [
47                         From => 'a@example.com',
48                         To => 'b+plus@example.com',
49                         Cc => 'John Doe <c@example.com>',
50                         'Content-Type' => 'text/plain',
51                         Subject => 'this is a subject',
52                         'Message-ID' => '<MID@host>',
53                         Date => 'Wed, 09 Apr 2014 01:28:34 +0000',
54                 ],
55                 body => "hello world\n",
56         ));
57 }
58
59 {
60         my $recipient = 'b@example.com';
61         my $s = Email::Simple->create(
62                 header => [
63                         To => 'b@example.com',
64                         Cc => 'c@example.com',
65                         'Content-Type' => 'text/plain',
66                         Subject => 'this is a subject',
67                         'Message-ID' => '<MID@host>',
68                         Date => 'Wed, 09 Apr 2014 01:28:34 +0000',
69                 ],
70                 body => "hello world\n",
71         );
72         ok(!PublicInbox::MDA->precheck($s, $recipient),
73                 "missing From: is rejected");
74 }
75
76 done_testing();