Mercurial > hg > nginx-tests
comparison mail_smtp.t @ 970:c227348453db
Tests: simplified parallel modifications in mail tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 08 Jul 2016 02:21:16 +0300 |
parents | e9064d691790 |
children | a8b8dd6e8ae1 |
comparison
equal
deleted
inserted
replaced
969:1edb092149e2 | 970:c227348453db |
---|---|
27 | 27 |
28 local $SIG{PIPE} = 'IGNORE'; | 28 local $SIG{PIPE} = 'IGNORE'; |
29 | 29 |
30 my $t = Test::Nginx->new() | 30 my $t = Test::Nginx->new() |
31 ->has(qw/mail smtp http rewrite/)->plan(25) | 31 ->has(qw/mail smtp http rewrite/)->plan(25) |
32 ->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon, port(2)) | 32 ->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon, port(8026)) |
33 ->write_file_expand('nginx.conf', <<'EOF')->run(); | 33 ->write_file_expand('nginx.conf', <<'EOF')->run(); |
34 | 34 |
35 %%TEST_GLOBALS%% | 35 %%TEST_GLOBALS%% |
36 | 36 |
37 daemon off; | 37 daemon off; |
39 events { | 39 events { |
40 } | 40 } |
41 | 41 |
42 mail { | 42 mail { |
43 proxy_pass_error_message on; | 43 proxy_pass_error_message on; |
44 auth_http http://127.0.0.1:%%PORT_0%%/mail/auth; | 44 auth_http http://127.0.0.1:8080/mail/auth; |
45 xclient off; | 45 xclient off; |
46 | 46 |
47 server { | 47 server { |
48 listen 127.0.0.1:%%PORT_1%%; | 48 listen 127.0.0.1:8025; |
49 protocol smtp; | 49 protocol smtp; |
50 smtp_auth login plain none; | 50 smtp_auth login plain none; |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 http { | 54 http { |
55 %%TEST_GLOBALS_HTTP%% | 55 %%TEST_GLOBALS_HTTP%% |
56 | 56 |
57 server { | 57 server { |
58 listen 127.0.0.1:%%PORT_0%%; | 58 listen 127.0.0.1:8080; |
59 server_name localhost; | 59 server_name localhost; |
60 | 60 |
61 location = /mail/auth { | 61 location = /mail/auth { |
62 set $reply ERROR; | 62 set $reply ERROR; |
63 | 63 |
70 set $reply OK; | 70 set $reply OK; |
71 } | 71 } |
72 | 72 |
73 add_header Auth-Status $reply; | 73 add_header Auth-Status $reply; |
74 add_header Auth-Server 127.0.0.1; | 74 add_header Auth-Server 127.0.0.1; |
75 add_header Auth-Port %%PORT_2%%; | 75 add_header Auth-Port %%PORT_8026%%; |
76 add_header Auth-Wait 1; | 76 add_header Auth-Wait 1; |
77 return 204; | 77 return 204; |
78 } | 78 } |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 EOF | 82 EOF |
83 | 83 |
84 ############################################################################### | 84 ############################################################################### |
85 | 85 |
86 my $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(1)); | 86 my $s = Test::Nginx::SMTP->new(); |
87 $s->check(qr/^220 /, "greeting"); | 87 $s->check(qr/^220 /, "greeting"); |
88 | 88 |
89 $s->send('EHLO example.com'); | 89 $s->send('EHLO example.com'); |
90 $s->check(qr/^250 /, "ehlo"); | 90 $s->check(qr/^250 /, "ehlo"); |
91 | 91 |
109 $s->send('QUIT'); | 109 $s->send('QUIT'); |
110 $s->ok("quit"); | 110 $s->ok("quit"); |
111 | 111 |
112 # Try auth login in simple form | 112 # Try auth login in simple form |
113 | 113 |
114 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(1)); | 114 $s = Test::Nginx::SMTP->new(); |
115 $s->read(); | 115 $s->read(); |
116 $s->send('EHLO example.com'); | 116 $s->send('EHLO example.com'); |
117 $s->read(); | 117 $s->read(); |
118 | 118 |
119 $s->send('AUTH LOGIN'); | 119 $s->send('AUTH LOGIN'); |
126 # Try auth plain with username. Details: | 126 # Try auth plain with username. Details: |
127 # | 127 # |
128 # [MS-XLOGIN]: SMTP Protocol AUTH LOGIN Extension Specification | 128 # [MS-XLOGIN]: SMTP Protocol AUTH LOGIN Extension Specification |
129 # http://download.microsoft.com/download/5/D/D/5DD33FDF-91F5-496D-9884-0A0B0EE698BB/%5BMS-XLOGIN%5D.pdf | 129 # http://download.microsoft.com/download/5/D/D/5DD33FDF-91F5-496D-9884-0A0B0EE698BB/%5BMS-XLOGIN%5D.pdf |
130 | 130 |
131 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(1)); | 131 $s = Test::Nginx::SMTP->new(); |
132 $s->read(); | 132 $s->read(); |
133 $s->send('EHLO example.com'); | 133 $s->send('EHLO example.com'); |
134 $s->read(); | 134 $s->read(); |
135 | 135 |
136 $s->send('AUTH LOGIN ' . encode_base64('test@example.com', '')); | 136 $s->send('AUTH LOGIN ' . encode_base64('test@example.com', '')); |
138 $s->send(encode_base64('secret', '')); | 138 $s->send(encode_base64('secret', '')); |
139 $s->authok('auth login with username'); | 139 $s->authok('auth login with username'); |
140 | 140 |
141 # Try auth plain with pipelining | 141 # Try auth plain with pipelining |
142 | 142 |
143 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(1)); | 143 $s = Test::Nginx::SMTP->new(); |
144 $s->read(); | 144 $s->read(); |
145 $s->send('EHLO example.com'); | 145 $s->send('EHLO example.com'); |
146 $s->read(); | 146 $s->read(); |
147 | 147 |
148 $s->send('INVALID COMMAND WITH ARGUMENTS' . CRLF | 148 $s->send('INVALID COMMAND WITH ARGUMENTS' . CRLF |
162 $s->read(); | 162 $s->read(); |
163 $s->ok('mail from after pipelined auth'); | 163 $s->ok('mail from after pipelined auth'); |
164 | 164 |
165 # Try auth none | 165 # Try auth none |
166 | 166 |
167 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(1)); | 167 $s = Test::Nginx::SMTP->new(); |
168 $s->read(); | 168 $s->read(); |
169 $s->send('EHLO example.com'); | 169 $s->send('EHLO example.com'); |
170 $s->read(); | 170 $s->read(); |
171 | 171 |
172 $s->send('MAIL FROM:<test@example.com> SIZE=100'); | 172 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
178 $s->send('RSET'); | 178 $s->send('RSET'); |
179 $s->ok('auth none - rset, should go to backend'); | 179 $s->ok('auth none - rset, should go to backend'); |
180 | 180 |
181 # Auth none with pipelining | 181 # Auth none with pipelining |
182 | 182 |
183 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(1)); | 183 $s = Test::Nginx::SMTP->new(); |
184 $s->read(); | 184 $s->read(); |
185 $s->send('EHLO example.com'); | 185 $s->send('EHLO example.com'); |
186 $s->read(); | 186 $s->read(); |
187 | 187 |
188 $s->send('MAIL FROM:<test@example.com> SIZE=100' . CRLF | 188 $s->send('MAIL FROM:<test@example.com> SIZE=100' . CRLF |
193 $s->ok('pipelined rcpt to'); | 193 $s->ok('pipelined rcpt to'); |
194 $s->ok('pipelined rset'); | 194 $s->ok('pipelined rset'); |
195 | 195 |
196 # Connection must stay even if error returned to rcpt to command | 196 # Connection must stay even if error returned to rcpt to command |
197 | 197 |
198 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(1)); | 198 $s = Test::Nginx::SMTP->new(); |
199 $s->read(); | 199 $s->read(); |
200 $s->send('EHLO example.com'); | 200 $s->send('EHLO example.com'); |
201 $s->read(); | 201 $s->read(); |
202 | 202 |
203 $s->send('MAIL FROM:<test@example.com> SIZE=100'); | 203 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
209 $s->send('RCPT TO:<test@example.com>'); | 209 $s->send('RCPT TO:<test@example.com>'); |
210 $s->ok('good rcpt to'); | 210 $s->ok('good rcpt to'); |
211 | 211 |
212 # Make sure command split into many packets processed correctly | 212 # Make sure command split into many packets processed correctly |
213 | 213 |
214 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(1)); | 214 $s = Test::Nginx::SMTP->new(); |
215 $s->read(); | 215 $s->read(); |
216 | 216 |
217 $s->print('HEL'); | 217 $s->print('HEL'); |
218 $s->send('O example.com'); | 218 $s->send('O example.com'); |
219 $s->ok('split command'); | 219 $s->ok('split command'); |