comparison mail_smtp.t @ 148:b714d6df958c

Tests: rename some tests for better sorting. Use underscore instead of dash. Addtionally, rename some tests to better match "module" + "details" scheme used: use "http_" prefix for http core module tests, use "mail_" prefix for mail module tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 04 Mar 2011 16:07:15 +0300
parents smtp.t@8ac1faaddd2c
children c0ae29632905
comparison
equal deleted inserted replaced
147:fd865ada95c8 148:b714d6df958c
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Tests for nginx mail smtp module.
6
7 ###############################################################################
8
9 use warnings;
10 use strict;
11
12 use Test::More;
13
14 use MIME::Base64;
15 use Socket qw/ CRLF /;
16
17 BEGIN { use FindBin; chdir($FindBin::Bin); }
18
19 use lib 'lib';
20 use Test::Nginx;
21 use Test::Nginx::SMTP;
22
23 ###############################################################################
24
25 select STDERR; $| = 1;
26 select STDOUT; $| = 1;
27
28 local $SIG{PIPE} = 'IGNORE';
29
30 my $t = Test::Nginx->new()
31 ->has(qw/mail smtp http rewrite/)->plan(25)
32 ->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon)
33 ->write_file_expand('nginx.conf', <<'EOF')->run();
34
35 %%TEST_GLOBALS%%
36
37 master_process off;
38 daemon off;
39
40 events {
41 }
42
43 mail {
44 proxy_pass_error_message on;
45 auth_http http://127.0.0.1:8080/mail/auth;
46 xclient off;
47
48 server {
49 listen 127.0.0.1:8025;
50 protocol smtp;
51 smtp_auth login plain none;
52 }
53 }
54
55 http {
56 %%TEST_GLOBALS_HTTP%%
57
58 server {
59 listen 127.0.0.1:8080;
60 server_name localhost;
61
62 location = /mail/auth {
63 set $reply ERROR;
64
65 if ($http_auth_smtp_to ~ example.com) {
66 set $reply OK;
67 }
68
69 set $userpass "$http_auth_user:$http_auth_pass";
70 if ($userpass ~ '^test@example.com:secret$') {
71 set $reply OK;
72 }
73
74 add_header Auth-Status $reply;
75 add_header Auth-Server 127.0.0.1;
76 add_header Auth-Port 8026;
77 add_header Auth-Wait 1;
78 return 204;
79 }
80 }
81 }
82
83 EOF
84
85 ###############################################################################
86
87 my $s = Test::Nginx::SMTP->new();
88 $s->check(qr/^220 /, "greeting");
89
90 $s->send('EHLO example.com');
91 $s->check(qr/^250 /, "ehlo");
92
93 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0bad", ''));
94 $s->check(qr/^5.. /, 'auth plain with bad password');
95
96 $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
97 $s->authok('auth plain');
98
99 # We are talking to backend from this point
100
101 $s->send('MAIL FROM:<test@example.com> SIZE=100');
102 $s->ok('mail from after auth');
103
104 $s->send('RSET');
105 $s->ok('rset');
106
107 $s->send('MAIL FROM:<test@xn--e1afmkfd.xn--80akhbyknj4f> SIZE=100');
108 $s->ok("idn mail from (example.test in russian)");
109
110 $s->send('QUIT');
111 $s->ok("quit");
112
113 # Try auth login in simple form
114
115 $s = Test::Nginx::SMTP->new();
116 $s->read();
117 $s->send('EHLO example.com');
118 $s->read();
119
120 $s->send('AUTH LOGIN');
121 $s->check(qr/^334 VXNlcm5hbWU6/, 'auth login simple username challenge');
122 $s->send(encode_base64('test@example.com', ''));
123 $s->check(qr/^334 UGFzc3dvcmQ6/, 'auth login simple password challenge');
124 $s->send(encode_base64('secret', ''));
125 $s->authok('auth login simple');
126
127 # Try auth plain with username. Details:
128 #
129 # [MS-XLOGIN]: SMTP Protocol AUTH LOGIN Extension Specification
130 # http://download.microsoft.com/download/5/D/D/5DD33FDF-91F5-496D-9884-0A0B0EE698BB/%5BMS-XLOGIN%5D.pdf
131
132 $s = Test::Nginx::SMTP->new();
133 $s->read();
134 $s->send('EHLO example.com');
135 $s->read();
136
137 $s->send('AUTH LOGIN ' . encode_base64('test@example.com', ''));
138 $s->check(qr/^334 UGFzc3dvcmQ6/, 'auth login with username password challenge');
139 $s->send(encode_base64('secret', ''));
140 $s->authok('auth login with username');
141
142 # Try auth plain with pipelining
143
144 TODO: {
145 local $TODO = 'pipelining not in official nginx';
146 local $SIG{__WARN__} = sub {};
147
148 $s = Test::Nginx::SMTP->new();
149 $s->read();
150 $s->send('EHLO example.com');
151 $s->read();
152
153 $s->send('INVALID COMMAND WITH ARGUMENTS' . CRLF
154 . 'RSET');
155 $s->read();
156 $s->ok('pipelined rset after invalid command');
157
158 $s->send('AUTH PLAIN '
159 . encode_base64("\0test\@example.com\0bad", '') . CRLF
160 . 'MAIL FROM:<test@example.com> SIZE=100');
161 $s->read();
162 $s->ok('mail from after failed pipelined auth');
163
164 $s->send('AUTH PLAIN '
165 . encode_base64("\0test\@example.com\0secret", '') . CRLF
166 . 'MAIL FROM:<test@example.com> SIZE=100');
167 $s->read();
168 $s->ok('mail from after pipelined auth');
169
170 }
171
172 # Try auth none
173
174 $s = Test::Nginx::SMTP->new();
175 $s->read();
176 $s->send('EHLO example.com');
177 $s->read();
178
179 $s->send('MAIL FROM:<test@example.com> SIZE=100');
180 $s->ok('auth none - mail from');
181
182 $s->send('RCPT TO:<test@example.com>');
183 $s->ok('auth none - rcpt to');
184
185 $s->send('RSET');
186 $s->ok('auth none - rset, should go to backend');
187
188 # Auth none with pipelining
189
190 $s = Test::Nginx::SMTP->new();
191 $s->read();
192 $s->send('EHLO example.com');
193 $s->read();
194
195 $s->send('MAIL FROM:<test@example.com> SIZE=100' . CRLF
196 . 'RCPT TO:<test@example.com>' . CRLF
197 . 'RSET');
198
199 $s->ok('pipelined mail from');
200
201 TODO: {
202 local $TODO = 'pipelining not in official nginx';
203 local $SIG{__WARN__} = sub {};
204
205 $s->ok('pipelined rcpt to');
206 $s->ok('pipelined rset');
207
208 }
209
210 # Connection must stay even if error returned to rcpt to command
211
212 $s = Test::Nginx::SMTP->new();
213 $s->read();
214 $s->send('EHLO example.com');
215 $s->read();
216
217 $s->send('MAIL FROM:<test@example.com> SIZE=100');
218 $s->read(); # skip mail from reply
219
220 $s->send('RCPT TO:<example.com>');
221 $s->check(qr/^5.. /, "bad rcpt to");
222
223 $s->send('RCPT TO:<test@example.com>');
224 $s->ok('good rcpt to');
225
226 # Make sure command splitted into many packets processed correctly
227
228 $s = Test::Nginx::SMTP->new();
229 $s->read();
230
231 log_out('HEL');
232 $s->print('HEL');
233 $s->send('O example.com');
234 $s->ok('splitted command');
235
236 ###############################################################################