comparison mail_resolver.t @ 952:e9064d691790

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