Mercurial > hg > nginx-tests
comparison http_resolver.t @ 823:9623d353f066
Tests: http resolver tests with format error response code.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 27 Jan 2016 13:56:40 +0300 |
parents | a6764c2a9f12 |
children | 9caacdb56b53 |
comparison
equal
deleted
inserted
replaced
822:92e20c77c916 | 823:9623d353f066 |
---|---|
89 | 89 |
90 $t->run_daemon(\&dns_daemon, 8081, $t); | 90 $t->run_daemon(\&dns_daemon, 8081, $t); |
91 $t->run_daemon(\&dns_daemon, 8082, $t); | 91 $t->run_daemon(\&dns_daemon, 8082, $t); |
92 $t->run_daemon(\&dns_daemon, 8089, $t); | 92 $t->run_daemon(\&dns_daemon, 8089, $t); |
93 | 93 |
94 $t->run()->plan(32); | 94 $t->run()->plan(34); |
95 | 95 |
96 $t->waitforfile($t->testdir . '/8081'); | 96 $t->waitforfile($t->testdir . '/8081'); |
97 $t->waitforfile($t->testdir . '/8082'); | 97 $t->waitforfile($t->testdir . '/8082'); |
98 $t->waitforfile($t->testdir . '/8089'); | 98 $t->waitforfile($t->testdir . '/8089'); |
99 | 99 |
100 ############################################################################### | 100 ############################################################################### |
101 | 101 |
102 # schedule resend test, which takes about 5 seconds to complete | 102 # schedule resend test, which takes about 5 seconds to complete |
103 | 103 |
104 my $s = http_host_header('id.example.net', '/resend', start => 1); | 104 my $s = http_host_header('id.example.net', '/resend', start => 1); |
105 my $fe = http_host_header('fe.example.net', '/resend', start => 1); | |
105 | 106 |
106 like(http_host_header('a.example.net', '/'), qr/200 OK/, 'A'); | 107 like(http_host_header('a.example.net', '/'), qr/200 OK/, 'A'); |
107 | 108 |
108 # ensure that resolver serves queries from cache in a case-insensitive manner | 109 # ensure that resolver serves queries from cache in a case-insensitive manner |
109 # we check this by marking 2nd and subsequent queries on backend with SERVFAIL | 110 # we check this by marking 2nd and subsequent queries on backend with SERVFAIL |
227 'CNAME + A with expired CNAME ttl'); | 228 'CNAME + A with expired CNAME ttl'); |
228 | 229 |
229 like(http_host_header('example.net', '/invalid'), qr/502 Bad/, 'no resolver'); | 230 like(http_host_header('example.net', '/invalid'), qr/502 Bad/, 'no resolver'); |
230 | 231 |
231 like(http_end($s), qr/200 OK/, 'resend after malformed response'); | 232 like(http_end($s), qr/200 OK/, 'resend after malformed response'); |
233 like(http_end($fe), qr/200 OK/, 'resend after format error'); | |
232 | 234 |
233 $s = http_get('/bad', start => 1); | 235 $s = http_get('/bad', start => 1); |
234 my $s2 = http_get('/bad', start => 1); | 236 my $s2 = http_get('/bad', start => 1); |
235 | 237 |
236 http_end($s); | 238 http_end($s); |
237 ok(http_end($s2), 'timeout handler on 2nd request'); | 239 ok(http_end($s2), 'timeout handler on 2nd request'); |
240 | |
241 like(http_host_header('fe_id.example.net', '/'), qr/502 Bad/, 'format error'); | |
238 | 242 |
239 ############################################################################### | 243 ############################################################################### |
240 | 244 |
241 sub http_host_header { | 245 sub http_host_header { |
242 my ($host, $uri, %extra) = @_; | 246 my ($host, $uri, %extra) = @_; |
262 my ($recv_data, $port, $state) = @_; | 266 my ($recv_data, $port, $state) = @_; |
263 | 267 |
264 my (@name, @rdata); | 268 my (@name, @rdata); |
265 | 269 |
266 use constant NOERROR => 0; | 270 use constant NOERROR => 0; |
271 use constant FORMERR => 1; | |
267 use constant SERVFAIL => 2; | 272 use constant SERVFAIL => 2; |
268 use constant NXDOMAIN => 3; | 273 use constant NXDOMAIN => 3; |
269 | 274 |
270 use constant A => 1; | 275 use constant A => 1; |
271 use constant CNAME => 5; | 276 use constant CNAME => 5; |
294 my $name = join('.', @name); | 299 my $name = join('.', @name); |
295 if (($name eq 'a.example.net') || ($name eq 'alias.example.net')) { | 300 if (($name eq 'a.example.net') || ($name eq 'alias.example.net')) { |
296 if ($type == A || $type == CNAME) { | 301 if ($type == A || $type == CNAME) { |
297 push @rdata, rd_addr($ttl, '127.0.0.1'); | 302 push @rdata, rd_addr($ttl, '127.0.0.1'); |
298 } | 303 } |
304 | |
305 } elsif ($name eq 'fe.example.net' && $type == A) { | |
306 if (++$state->{fecnt} > 1) { | |
307 $rcode = FORMERR; | |
308 } | |
309 | |
310 push @rdata, rd_addr($ttl, '127.0.0.1'); | |
311 | |
312 } elsif ($name eq 'fe_id.example.net' && $type == A) { | |
313 $id = 42; | |
314 $rcode = FORMERR; | |
299 | 315 |
300 } elsif ($name eq 'case.example.net' && $type == A) { | 316 } elsif ($name eq 'case.example.net' && $type == A) { |
301 if (++$state->{casecnt} > 1) { | 317 if (++$state->{casecnt} > 1) { |
302 $rcode = SERVFAIL; | 318 $rcode = SERVFAIL; |
303 } | 319 } |
464 cttlcnt => 0, | 480 cttlcnt => 0, |
465 cttl2cnt => 0, | 481 cttl2cnt => 0, |
466 manycnt => 0, | 482 manycnt => 0, |
467 casecnt => 0, | 483 casecnt => 0, |
468 idcnt => 0, | 484 idcnt => 0, |
485 fecnt => 0, | |
469 ); | 486 ); |
470 | 487 |
471 # signal we are ready | 488 # signal we are ready |
472 | 489 |
473 open my $fh, '>', $t->testdir() . '/' . $port; | 490 open my $fh, '>', $t->testdir() . '/' . $port; |