comparison http_resolver.t @ 356:7a472e46772c

Tests: added http resolver test for CNAME + A combined answer.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 21 Nov 2013 15:20:10 +0400
parents 145c37f27c5a
children e0c00e695cb5
comparison
equal deleted inserted replaced
355:14eba1ad0880 356:7a472e46772c
99 plan(skip_all => 'no inet6 support') if $@; 99 plan(skip_all => 'no inet6 support') if $@;
100 100
101 $t->waitforsocket('127.0.0.1:8081'); 101 $t->waitforsocket('127.0.0.1:8081');
102 $t->waitforsocket('127.0.0.1:8082'); 102 $t->waitforsocket('127.0.0.1:8082');
103 103
104 $t->plan(27); 104 $t->plan(28);
105 105
106 ############################################################################### 106 ###############################################################################
107 107
108 like(http_host_header('a.example.net', '/'), qr/200 OK/, 'A'); 108 like(http_host_header('a.example.net', '/'), qr/200 OK/, 'A');
109 like(http_host_header('short.example.net', '/'), qr/502 Bad/, 109 like(http_host_header('short.example.net', '/'), qr/502 Bad/,
119 like(http_host_header('nx.example.net', '/'), qr/502 Bad/, 'NXDOMAIN'); 119 like(http_host_header('nx.example.net', '/'), qr/502 Bad/, 'NXDOMAIN');
120 like(http_host_header('cname.example.net', '/cached'), qr/200 OK/, 'CNAME'); 120 like(http_host_header('cname.example.net', '/cached'), qr/200 OK/, 'CNAME');
121 like(http_host_header('cname.example.net', '/cached'), qr/200 OK/, 121 like(http_host_header('cname.example.net', '/cached'), qr/200 OK/,
122 'CNAME cached'); 122 'CNAME cached');
123 123
124 # CNAME + A combined answer
125 # demonstrates the name in answer section different from what is asked
126
127 like(http_host_header('cname_a.example.net', '/'), qr/200 OK/, 'CNAME + A');
128
124 # CNAME refers to non-existing A 129 # CNAME refers to non-existing A
125 130
126 like(http_host_header('cname2.example.net', '/'), qr/502 Bad/, 'CNAME bad'); 131 like(http_host_header('cname2.example.net', '/'), qr/502 Bad/, 'CNAME bad');
127 like(http_host_header('long.example.net', '/'), qr/200 OK/, 'long label'); 132 like(http_host_header('long.example.net', '/'), qr/200 OK/, 'long label');
128 like(http_host_header('long2.example.net', '/'), qr/200 OK/, 'long name'); 133 like(http_host_header('long2.example.net', '/'), qr/200 OK/, 'long name');
167 172
168 sleep 2; 173 sleep 2;
169 174
170 # expired ttl causes nginx to query the next (bad) ns 175 # expired ttl causes nginx to query the next (bad) ns
171 176
172 skip:
173 like(http_host_header('ttl.example.net', '/two'), qr/502 Bad/, 'ttl expired'); 177 like(http_host_header('ttl.example.net', '/two'), qr/502 Bad/, 'ttl expired');
174 178
175 # zero ttl prohibits response caching 179 # zero ttl prohibits response caching
176 180
177 like(http_host_header('ttl0.example.net', '/two'), qr/200 OK/, 'zero ttl'); 181 like(http_host_header('ttl0.example.net', '/two'), qr/200 OK/, 'zero ttl');
265 } elsif ($name eq 'cname.example.net') { 269 } elsif ($name eq 'cname.example.net') {
266 if ($conn->{sockport} == 8082) { 270 if ($conn->{sockport} == 8082) {
267 return 'SERVFAIL'; 271 return 'SERVFAIL';
268 } 272 }
269 ($type, $rdata) = ('CNAME', 'alias.example.net'); 273 ($type, $rdata) = ('CNAME', 'alias.example.net');
274 push @ans, Net::DNS::RR->new("$name $ttl $class $type $rdata");
275
276 } elsif ($name eq 'cname_a.example.net') {
277 ($type, $rdata) = ('CNAME', 'alias.example.net');
278 push @ans, Net::DNS::RR->new("$name $ttl $class $type $rdata");
279
280 ($name, $type, $rdata) = ('alias.example.net', 'A', '127.0.0.1');
270 push @ans, Net::DNS::RR->new("$name $ttl $class $type $rdata"); 281 push @ans, Net::DNS::RR->new("$name $ttl $class $type $rdata");
271 282
272 } elsif ($name eq 'cname2.example.net') { 283 } elsif ($name eq 'cname2.example.net') {
273 # points to non-existing A 284 # points to non-existing A
274 ($type, $rdata) = ('CNAME', 'nx.example.net'); 285 ($type, $rdata) = ('CNAME', 'nx.example.net');