Mercurial > hg > nginx-tests
comparison mail_resolver.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 |
---|---|
24 select STDOUT; $| = 1; | 24 select STDOUT; $| = 1; |
25 | 25 |
26 local $SIG{PIPE} = 'IGNORE'; | 26 local $SIG{PIPE} = 'IGNORE'; |
27 | 27 |
28 my $t = Test::Nginx->new()->has(qw/mail smtp http rewrite/) | 28 my $t = Test::Nginx->new()->has(qw/mail smtp http rewrite/) |
29 ->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon, port(15)); | 29 ->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon, port(8026)); |
30 | 30 |
31 $t->write_file_expand('nginx.conf', <<'EOF'); | 31 $t->write_file_expand('nginx.conf', <<'EOF'); |
32 | 32 |
33 %%TEST_GLOBALS%% | 33 %%TEST_GLOBALS%% |
34 | 34 |
36 | 36 |
37 events { | 37 events { |
38 } | 38 } |
39 | 39 |
40 mail { | 40 mail { |
41 auth_http http://127.0.0.1:%%PORT_0%%/mail/auth; | 41 auth_http http://127.0.0.1:8080/mail/auth; |
42 smtp_auth none; | 42 smtp_auth none; |
43 server_name locahost; | 43 server_name locahost; |
44 | 44 |
45 # prevent useless resend | 45 # prevent useless resend |
46 resolver_timeout 2s; | 46 resolver_timeout 2s; |
47 | 47 |
48 server { | 48 server { |
49 listen 127.0.0.1:%%PORT_1%%; | 49 listen 127.0.0.1:8025; |
50 protocol smtp; | 50 protocol smtp; |
51 resolver 127.0.0.1:%%PORT_8_UDP%% 127.0.0.1:%%PORT_9_UDP%% | 51 resolver 127.0.0.1:%%PORT_8081_UDP%% |
52 127.0.0.1:%%PORT_10_UDP%%; | 52 127.0.0.1:%%PORT_8082_UDP%% |
53 } | 53 127.0.0.1:%%PORT_8083_UDP%%; |
54 | 54 } |
55 server { | 55 |
56 listen 127.0.0.1:%%PORT_2%%; | 56 server { |
57 protocol smtp; | 57 listen 127.0.0.1:8027; |
58 resolver 127.0.0.1:%%PORT_9_UDP%%; | 58 protocol smtp; |
59 } | 59 resolver 127.0.0.1:%%PORT_8082_UDP%%; |
60 | 60 } |
61 server { | 61 |
62 listen 127.0.0.1:%%PORT_3%%; | 62 server { |
63 protocol smtp; | 63 listen 127.0.0.1:8028; |
64 resolver 127.0.0.1:%%PORT_10_UDP%%; | 64 protocol smtp; |
65 | 65 resolver 127.0.0.1:%%PORT_8083_UDP%%; |
66 } | 66 |
67 | 67 } |
68 server { | 68 |
69 listen 127.0.0.1:%%PORT_4%%; | 69 server { |
70 protocol smtp; | 70 listen 127.0.0.1:8029; |
71 resolver 127.0.0.1:%%PORT_11_UDP%%; | 71 protocol smtp; |
72 } | 72 resolver 127.0.0.1:%%PORT_8084_UDP%%; |
73 | 73 } |
74 server { | 74 |
75 listen 127.0.0.1:%%PORT_5%%; | 75 server { |
76 protocol smtp; | 76 listen 127.0.0.1:8030; |
77 resolver 127.0.0.1:%%PORT_12_UDP%%; | 77 protocol smtp; |
78 } | 78 resolver 127.0.0.1:%%PORT_8085_UDP%%; |
79 | 79 } |
80 server { | 80 |
81 listen 127.0.0.1:%%PORT_6%%; | 81 server { |
82 protocol smtp; | 82 listen 127.0.0.1:8031; |
83 resolver 127.0.0.1:%%PORT_13_UDP%%; | 83 protocol smtp; |
84 } | 84 resolver 127.0.0.1:%%PORT_8086_UDP%%; |
85 | 85 } |
86 server { | 86 |
87 listen 127.0.0.1:%%PORT_7%%; | 87 server { |
88 protocol smtp; | 88 listen 127.0.0.1:8032; |
89 resolver 127.0.0.1:%%PORT_14_UDP%%; | 89 protocol smtp; |
90 resolver 127.0.0.1:%%PORT_8087_UDP%%; | |
90 } | 91 } |
91 | 92 |
92 } | 93 } |
93 | 94 |
94 http { | 95 http { |
95 %%TEST_GLOBALS_HTTP%% | 96 %%TEST_GLOBALS_HTTP%% |
96 | 97 |
97 server { | 98 server { |
98 listen 127.0.0.1:%%PORT_0%%; | 99 listen 127.0.0.1:8080; |
99 server_name localhost; | 100 server_name localhost; |
100 | 101 |
101 location = /mail/auth { | 102 location = /mail/auth { |
102 set $reply $http_client_host; | 103 set $reply $http_client_host; |
103 | 104 |
105 set $reply OK; | 106 set $reply OK; |
106 } | 107 } |
107 | 108 |
108 add_header Auth-Status $reply; | 109 add_header Auth-Status $reply; |
109 add_header Auth-Server 127.0.0.1; | 110 add_header Auth-Server 127.0.0.1; |
110 add_header Auth-Port %%PORT_15%%; | 111 add_header Auth-Port %%PORT_8026%%; |
111 return 204; | 112 return 204; |
112 } | 113 } |
113 } | 114 } |
114 } | 115 } |
115 | 116 |
116 EOF | 117 EOF |
117 | 118 |
118 for (8 .. 14) { | 119 for (8081 .. 8087) { |
119 $t->run_daemon(\&dns_daemon, port($_), $t); | 120 $t->run_daemon(\&dns_daemon, port($_), $t); |
120 } | 121 } |
121 $t->run(); | 122 $t->run(); |
122 | 123 |
123 for (8 .. 14) { | 124 for (8081 .. 8087) { |
124 $t->waitforfile($t->testdir . '/' . port($_)); | 125 $t->waitforfile($t->testdir . '/' . port($_)); |
125 } | 126 } |
126 | 127 |
127 $t->plan(8); | 128 $t->plan(8); |
128 | 129 |
129 ############################################################################### | 130 ############################################################################### |
130 | 131 |
131 # PTR | 132 # PTR |
132 | 133 |
133 my $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(1)); | 134 my $s = Test::Nginx::SMTP->new(); |
134 $s->read(); | 135 $s->read(); |
135 $s->send('EHLO example.com'); | 136 $s->send('EHLO example.com'); |
136 $s->read(); | 137 $s->read(); |
137 $s->send('MAIL FROM:<test@example.com> SIZE=100'); | 138 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
138 $s->read(); | 139 $s->read(); |
141 $s->ok('PTR'); | 142 $s->ok('PTR'); |
142 | 143 |
143 $s->send('QUIT'); | 144 $s->send('QUIT'); |
144 $s->read(); | 145 $s->read(); |
145 | 146 |
146 # Cached PTR prevents from querying bad ns on the first port | 147 # Cached PTR prevents from querying bad ns on port 8083 |
147 | 148 |
148 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(1)); | 149 $s = Test::Nginx::SMTP->new(); |
149 $s->read(); | 150 $s->read(); |
150 $s->send('EHLO example.com'); | 151 $s->send('EHLO example.com'); |
151 $s->read(); | 152 $s->read(); |
152 $s->send('MAIL FROM:<test@example.com> SIZE=100'); | 153 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
153 $s->read(); | 154 $s->read(); |
158 $s->send('QUIT'); | 159 $s->send('QUIT'); |
159 $s->read(); | 160 $s->read(); |
160 | 161 |
161 # SERVFAIL | 162 # SERVFAIL |
162 | 163 |
163 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(2)); | 164 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8027)); |
164 $s->read(); | 165 $s->read(); |
165 $s->send('EHLO example.com'); | 166 $s->send('EHLO example.com'); |
166 $s->read(); | 167 $s->read(); |
167 $s->send('MAIL FROM:<test@example.com> SIZE=100'); | 168 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
168 $s->read(); | 169 $s->read(); |
173 $s->send('QUIT'); | 174 $s->send('QUIT'); |
174 $s->read(); | 175 $s->read(); |
175 | 176 |
176 # PTR with zero length RDATA | 177 # PTR with zero length RDATA |
177 | 178 |
178 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(3)); | 179 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8028)); |
179 $s->read(); | 180 $s->read(); |
180 $s->send('EHLO example.com'); | 181 $s->send('EHLO example.com'); |
181 $s->read(); | 182 $s->read(); |
182 $s->send('MAIL FROM:<test@example.com> SIZE=100'); | 183 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
183 $s->read(); | 184 $s->read(); |
191 # CNAME | 192 # CNAME |
192 | 193 |
193 TODO: { | 194 TODO: { |
194 local $TODO = 'support for CNAME RR'; | 195 local $TODO = 'support for CNAME RR'; |
195 | 196 |
196 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(4)); | 197 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8029)); |
197 $s->read(); | 198 $s->read(); |
198 $s->send('EHLO example.com'); | 199 $s->send('EHLO example.com'); |
199 $s->read(); | 200 $s->read(); |
200 $s->send('MAIL FROM:<test@example.com> SIZE=100'); | 201 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
201 $s->read(); | 202 $s->read(); |
212 | 213 |
213 TODO: { | 214 TODO: { |
214 local $TODO = 'support for uncompressed name in PTR' | 215 local $TODO = 'support for uncompressed name in PTR' |
215 unless $t->has_version('1.9.11'); | 216 unless $t->has_version('1.9.11'); |
216 | 217 |
217 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(5)); | 218 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8030)); |
218 $s->read(); | 219 $s->read(); |
219 $s->send('EHLO example.com'); | 220 $s->send('EHLO example.com'); |
220 $s->read(); | 221 $s->read(); |
221 $s->send('MAIL FROM:<test@example.com> SIZE=100'); | 222 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
222 $s->read(); | 223 $s->read(); |
230 } | 231 } |
231 | 232 |
232 TODO: { | 233 TODO: { |
233 local $TODO = 'PTR type checking' unless $t->has_version('1.9.11'); | 234 local $TODO = 'PTR type checking' unless $t->has_version('1.9.11'); |
234 | 235 |
235 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(6)); | 236 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8031)); |
236 $s->read(); | 237 $s->read(); |
237 $s->send('EHLO example.com'); | 238 $s->send('EHLO example.com'); |
238 $s->read(); | 239 $s->read(); |
239 $s->send('MAIL FROM:<test@example.com> SIZE=100'); | 240 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
240 $s->read(); | 241 $s->read(); |
250 # CNAME and PTR in one answer section | 251 # CNAME and PTR in one answer section |
251 | 252 |
252 TODO: { | 253 TODO: { |
253 local $TODO = 'not yet' unless $t->has_version('1.9.11'); | 254 local $TODO = 'not yet' unless $t->has_version('1.9.11'); |
254 | 255 |
255 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(7)); | 256 $s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8032)); |
256 $s->read(); | 257 $s->read(); |
257 $s->send('EHLO example.com'); | 258 $s->send('EHLO example.com'); |
258 $s->read(); | 259 $s->read(); |
259 $s->send('MAIL FROM:<test@example.com> SIZE=100'); | 260 $s->send('MAIL FROM:<test@example.com> SIZE=100'); |
260 $s->read(); | 261 $s->read(); |
306 my $name = join('.', @name); | 307 my $name = join('.', @name); |
307 if ($name eq 'a.example.net' && $type == A) { | 308 if ($name eq 'a.example.net' && $type == A) { |
308 push @rdata, rd_addr($ttl, '127.0.0.1'); | 309 push @rdata, rd_addr($ttl, '127.0.0.1'); |
309 | 310 |
310 } elsif ($name eq '1.0.0.127.in-addr.arpa' && $type == PTR) { | 311 } elsif ($name eq '1.0.0.127.in-addr.arpa' && $type == PTR) { |
311 if ($port == port(8)) { | 312 if ($port == port(8081)) { |
312 push @rdata, rd_name(PTR, $ttl, 'a.example.net'); | 313 push @rdata, rd_name(PTR, $ttl, 'a.example.net'); |
313 | 314 |
314 } elsif ($port == port(9)) { | 315 } elsif ($port == port(8082)) { |
315 $rcode = SERVFAIL; | 316 $rcode = SERVFAIL; |
316 | 317 |
317 } elsif ($port == port(10)) { | 318 } elsif ($port == port(8083)) { |
318 # zero length RDATA | 319 # zero length RDATA |
319 | 320 |
320 push @rdata, pack("n3N n", 0xc00c, PTR, IN, $ttl, 0); | 321 push @rdata, pack("n3N n", 0xc00c, PTR, IN, $ttl, 0); |
321 | 322 |
322 } elsif ($port == port(11)) { | 323 } elsif ($port == port(8084)) { |
323 # PTR answered with CNAME | 324 # PTR answered with CNAME |
324 | 325 |
325 push @rdata, rd_name(CNAME, $ttl, | 326 push @rdata, rd_name(CNAME, $ttl, |
326 '1.1.0.0.127.in-addr.arpa'); | 327 '1.1.0.0.127.in-addr.arpa'); |
327 | 328 |
328 } elsif ($port == port(12)) { | 329 } elsif ($port == port(8085)) { |
329 # uncompressed answer | 330 # uncompressed answer |
330 | 331 |
331 push @rdata, pack("(C/a*)6x n2N n(C/a*)3x", | 332 push @rdata, pack("(C/a*)6x n2N n(C/a*)3x", |
332 ('1', '0', '0', '127', 'in-addr', 'arpa'), | 333 ('1', '0', '0', '127', 'in-addr', 'arpa'), |
333 PTR, IN, $ttl, 15, ('a', 'example', 'net')); | 334 PTR, IN, $ttl, 15, ('a', 'example', 'net')); |
334 | 335 |
335 } elsif ($port == port(13)) { | 336 } elsif ($port == port(8086)) { |
336 push @rdata, rd_name(DNAME, $ttl, 'a.example.net'); | 337 push @rdata, rd_name(DNAME, $ttl, 'a.example.net'); |
337 | 338 |
338 } elsif ($port == port(14)) { | 339 } elsif ($port == port(8087)) { |
339 # PTR answered with CNAME+PTR | 340 # PTR answered with CNAME+PTR |
340 | 341 |
341 push @rdata, rd_name(CNAME, $ttl, | 342 push @rdata, rd_name(CNAME, $ttl, |
342 '1.1.0.0.127.in-addr.arpa'); | 343 '1.1.0.0.127.in-addr.arpa'); |
343 push @rdata, pack("n3N n(C/a*)3 x", 0xc034, | 344 push @rdata, pack("n3N n(C/a*)3 x", 0xc034, |