comparison mail_max_errors.t @ 1687:41b213d611f5

Tests: mail max_errors tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 19 May 2021 04:33:16 +0300
parents
children 2a0a6035a1af
comparison
equal deleted inserted replaced
1686:156cb84b3c23 1687:41b213d611f5
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4 # (C) Nginx, Inc.
5
6 # Tests for mail max_errors.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14 use Socket qw/ CRLF /;
15
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
17
18 use lib 'lib';
19 use Test::Nginx;
20 use Test::Nginx::IMAP;
21 use Test::Nginx::POP3;
22 use Test::Nginx::SMTP;
23
24 ###############################################################################
25
26 select STDERR; $| = 1;
27 select STDOUT; $| = 1;
28
29 local $SIG{PIPE} = 'IGNORE';
30
31 my $t = Test::Nginx->new()->has(qw/mail imap pop3 smtp/)
32 ->write_file_expand('nginx.conf', <<'EOF');
33
34 %%TEST_GLOBALS%%
35
36 daemon off;
37
38 events {
39 }
40
41 mail {
42 auth_http http://127.0.0.1:8080; # unused
43
44 max_errors 2;
45
46 server {
47 listen 127.0.0.1:8143;
48 protocol imap;
49 }
50
51 server {
52 listen 127.0.0.1:8110;
53 protocol pop3;
54 }
55
56 server {
57 listen 127.0.0.1:8025;
58 protocol smtp;
59 }
60 }
61
62 EOF
63
64 $t->try_run('no max_errors')->plan(18);
65
66 ###############################################################################
67
68 # imap
69
70 my $s = Test::Nginx::IMAP->new();
71 $s->read();
72
73 $s->send('a01 FOO');
74 $s->check(qr/^a01 BAD/, 'imap first error');
75 $s->send('a02 BAR');
76 $s->check(qr/^a02 BAD/, 'imap second error');
77 $s->send('a03 BAZZ');
78 $s->check(qr/^$/, 'imap max errors');
79
80 $s = Test::Nginx::IMAP->new();
81 $s->read();
82
83 $s->send('a01 FOO' . CRLF . 'a02 BAR' . CRLF . 'a03 BAZZ');
84 $s->check(qr/^a01 BAD/, 'imap pipelined first error');
85 $s->check(qr/^a02 BAD/, 'imap pipelined second error');
86 $s->check(qr/^$/, 'imap pipelined max errors');
87
88 # pop3
89
90 $s = Test::Nginx::POP3->new();
91 $s->read();
92
93 $s->send('FOO');
94 $s->check(qr/^-ERR/, 'pop3 first error');
95 $s->send('BAR');
96 $s->check(qr/^-ERR/, 'pop3 second error');
97 $s->send('BAZZ');
98 $s->check(qr/^$/, 'pop3 max errors');
99
100 $s = Test::Nginx::POP3->new();
101 $s->read();
102
103 $s->send('FOO' . CRLF . 'BAR' . CRLF . 'BAZZ');
104 $s->check(qr/^-ERR/, 'pop3 pipelined first error');
105 $s->check(qr/^-ERR/, 'pop3 pipelined second error');
106 $s->check(qr/^$/, 'pop3 pipelined max errors');
107
108 # smtp
109
110 $s = Test::Nginx::SMTP->new();
111 $s->read();
112
113 $s->send('FOO');
114 $s->check(qr/^5.. /, 'smtp first error');
115 $s->send('BAR');
116 $s->check(qr/^5.. /, 'smtp second error');
117 $s->send('BAZZ');
118 $s->check(qr/^$/, 'smtp max errors');
119
120 $s = Test::Nginx::SMTP->new();
121 $s->read();
122
123 $s->send('FOO' . CRLF . 'BAR' . CRLF . 'BAZZ');
124 $s->check(qr/^5.. /, 'smtp pipelined first error');
125 $s->check(qr/^5.. /, 'smtp pipelined second error');
126 $s->check(qr/^$/, 'smtp pipelined max errors');
127
128 ###############################################################################