Mercurial > hg > nginx-tests
annotate http_resolver.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | e4974af3fb12 |
children |
rev | line source |
---|---|
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for http resolver. |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
834
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
15 use IO::Select; |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
16 |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
438
60888e2c3f5a
Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
436
diff
changeset
|
20 use Test::Nginx qw/ :DEFAULT http_end /; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 ############################################################################### |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 $t->write_file_expand('nginx.conf', <<'EOF'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 events { |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 http { |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
958
diff
changeset
|
42 listen 127.0.0.1:8080; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server_name localhost; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 location / { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
46 resolver 127.0.0.1:%%PORT_8981_UDP%%; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 resolver_timeout 1s; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
958
diff
changeset
|
48 proxy_pass http://$host:%%PORT_8080%%/backend; |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
49 |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
50 proxy_next_upstream http_504 timeout error; |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
51 proxy_intercept_errors on; |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
52 proxy_connect_timeout 1s; |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
53 error_page 504 502 /50x; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 } |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
55 location /two { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
56 resolver 127.0.0.1:%%PORT_8981_UDP%% 127.0.0.1:%%PORT_8982_UDP%%; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
958
diff
changeset
|
57 proxy_pass http://$host:%%PORT_8080%%/backend; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 location /valid { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
60 resolver 127.0.0.1:%%PORT_8981_UDP%% valid=5s; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
958
diff
changeset
|
61 proxy_pass http://$host:%%PORT_8080%%/backend; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 } |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
63 location /case { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
64 resolver 127.0.0.1:%%PORT_8981_UDP%%; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
958
diff
changeset
|
65 proxy_pass http://$http_x_name:%%PORT_8080%%/backend; |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
66 } |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 location /invalid { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
958
diff
changeset
|
68 proxy_pass http://$host:%%PORT_8080%%/backend; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 } |
824
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
70 location /long { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
71 resolver 127.0.0.1:%%PORT_8981_UDP%%; |
824
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
72 resolver_timeout 4s; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
958
diff
changeset
|
73 proxy_pass http://$host:%%PORT_8080%%/backend; |
824
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
74 } |
436
4984dac109db
Tests: added test for resolver resend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
75 location /resend { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
76 resolver 127.0.0.1:%%PORT_8981_UDP%%; |
550
a04b8b9537cd
Tests: adjusted resolver test timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents:
544
diff
changeset
|
77 resolver_timeout 8s; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
958
diff
changeset
|
78 proxy_pass http://$host:%%PORT_8080%%/backend; |
436
4984dac109db
Tests: added test for resolver resend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
79 } |
449
0bc79a098213
Tests: added resolver timeout test with multiple requests sent.
Sergey Kandaurov <pluknet@nginx.com>
parents:
438
diff
changeset
|
80 location /bad { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
81 resolver 127.0.0.1:%%PORT_8984_UDP%%; |
449
0bc79a098213
Tests: added resolver timeout test with multiple requests sent.
Sergey Kandaurov <pluknet@nginx.com>
parents:
438
diff
changeset
|
82 resolver_timeout 1s; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
958
diff
changeset
|
83 proxy_pass http://$host:%%PORT_8080%%/backend; |
449
0bc79a098213
Tests: added resolver timeout test with multiple requests sent.
Sergey Kandaurov <pluknet@nginx.com>
parents:
438
diff
changeset
|
84 } |
834
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
85 location /tcp { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
86 resolver 127.0.0.1:%%PORT_8983_UDP%% 127.0.0.1:%%PORT_8982_UDP%%; |
834
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
87 resolver_timeout 1s; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
958
diff
changeset
|
88 proxy_pass http://$host:%%PORT_8080%%/backend; |
834
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
89 proxy_connect_timeout 1s; |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
90 add_header X-IP $upstream_addr; |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
91 error_page 504 502 /50x; |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
92 |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
93 location /tcp2 { |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
94 resolver_timeout 8s; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
958
diff
changeset
|
95 proxy_pass http://$host:%%PORT_8080%%/backend; |
834
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
96 } |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
97 } |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 location /backend { |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 return 200; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 location /50x { |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 return 200 $upstream_addr; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 EOF |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
110 $t->run_daemon(\&dns_daemon, port(8981), $t); |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
111 $t->run_daemon(\&dns_daemon, port(8982), $t); |
958
0a87d9bcfb26
Tests: fixed TCP resolver test hang on win32.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
956
diff
changeset
|
112 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
113 $t->run_daemon(\&dns_daemon, port(8983), $t, tcp => 1); |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
114 $t->waitforfile($t->testdir . '/' . port(8983)); |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
115 port(8983, socket => 1)->close(); |
958
0a87d9bcfb26
Tests: fixed TCP resolver test hang on win32.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
956
diff
changeset
|
116 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
117 $t->run_daemon(\&dns_daemon, port(8984), $t); |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
118 |
834
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
119 $t->run()->plan(38); |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
120 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
121 $t->waitforfile($t->testdir . '/' . port(8981)); |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
122 $t->waitforfile($t->testdir . '/' . port(8982)); |
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
123 $t->waitforfile($t->testdir . '/' . port(8984)); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 ############################################################################### |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
958
diff
changeset
|
127 my $p0 = port(8080); |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
937
diff
changeset
|
128 |
450 | 129 # schedule resend test, which takes about 5 seconds to complete |
436
4984dac109db
Tests: added test for resolver resend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
130 |
438
60888e2c3f5a
Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
436
diff
changeset
|
131 my $s = http_host_header('id.example.net', '/resend', start => 1); |
823
9623d353f066
Tests: http resolver tests with format error response code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
132 my $fe = http_host_header('fe.example.net', '/resend', start => 1); |
436
4984dac109db
Tests: added test for resolver resend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
133 |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 like(http_host_header('a.example.net', '/'), qr/200 OK/, 'A'); |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
135 |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
136 # ensure that resolver serves queries from cache in a case-insensitive manner |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
137 # we check this by marking 2nd and subsequent queries on backend with SERVFAIL |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
138 |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
139 http_x_name_header('case.example.net', '/case'); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
140 like(http_x_name_header('CASE.example.net', '/case'), qr/200 OK/, |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
141 'A case-insensitive'); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
142 |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
143 like(http_host_header('awide.example.net', '/'), qr/200 OK/, 'A uncompressed'); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 like(http_host_header('short.example.net', '/'), qr/502 Bad/, |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 'A short dns response'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 like(http_host_header('nx.example.net', '/'), qr/502 Bad/, 'NXDOMAIN'); |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
148 like(http_host_header('cname.example.net', '/'), qr/200 OK/, 'CNAME'); |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
149 like(http_host_header('cname.example.net', '/'), qr/200 OK/, |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 'CNAME cached'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 |
356
7a472e46772c
Tests: added http resolver test for CNAME + A combined answer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
352
diff
changeset
|
152 # CNAME + A combined answer |
7a472e46772c
Tests: added http resolver test for CNAME + A combined answer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
352
diff
changeset
|
153 # demonstrates the name in answer section different from what is asked |
7a472e46772c
Tests: added http resolver test for CNAME + A combined answer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
352
diff
changeset
|
154 |
7a472e46772c
Tests: added http resolver test for CNAME + A combined answer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
352
diff
changeset
|
155 like(http_host_header('cname_a.example.net', '/'), qr/200 OK/, 'CNAME + A'); |
7a472e46772c
Tests: added http resolver test for CNAME + A combined answer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
352
diff
changeset
|
156 |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 # CNAME refers to non-existing A |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 like(http_host_header('cname2.example.net', '/'), qr/502 Bad/, 'CNAME bad'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 like(http_host_header('long.example.net', '/'), qr/200 OK/, 'long label'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 like(http_host_header('long2.example.net', '/'), qr/200 OK/, 'long name'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 # take into account DNAME |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 like(http_host_header('alias.example.com', '/'), qr/200 OK/, 'DNAME'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 # many A records in round robin |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 # nonexisting IPs enumerated with proxy_next_upstream |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
170 like(http_host_header('many.example.net', '/'), |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
937
diff
changeset
|
171 qr/^127.0.0.20(1:$p0, 127.0.0.202:$p0|2:$p0, 127.0.0.201:$p0)$/m, |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 'A many'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
174 like(http_host_header('many.example.net', '/'), |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
937
diff
changeset
|
175 qr/^127.0.0.20(1:$p0, 127.0.0.202:$p0|2:$p0, 127.0.0.201:$p0)$/m, |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 'A many cached'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
178 # tests for several resolvers specified in directive |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
179 # query bad ns, make sure that error responses are not cached |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 like(http_host_header('2.example.net', '/two'), qr/502 Bad/, 'two ns bad'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
183 # now get correct response |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 like(http_host_header('2.example.net', '/two'), qr/200 OK/, 'two ns good'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
187 # response is cached, actual request would get error |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 like(http_host_header('2.example.net', '/two'), qr/200 OK/, 'two ns cached'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
191 # ttl tested with 1st req good and 2nd req bad |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
192 # send 1st request and cache its good response |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
194 like(http_host_header('ttl.example.net', '/'), qr/200 OK/, 'ttl'); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
196 # response is cached, actual request would get error |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
198 like(http_host_header('ttl.example.net', '/'), qr/200 OK/, 'ttl cached 1'); |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
199 like(http_host_header('ttl.example.net', '/'), qr/200 OK/, 'ttl cached 2'); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
200 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
201 sleep 2; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
203 # expired ttl causes nginx to make actual query |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
204 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
205 like(http_host_header('ttl.example.net', '/'), qr/502 Bad/, 'ttl expired'); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
206 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
207 # zero ttl prohibits response caching |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
208 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
209 like(http_host_header('ttl0.example.net', '/'), qr/200 OK/, 'zero ttl'); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
210 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
211 TODO: { |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
212 local $TODO = 'support for zero ttl'; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
213 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
214 like(http_host_header('ttl0.example.net', '/'), qr/502 Bad/, |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
215 'zero ttl not cached'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
216 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
217 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
218 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
219 # "valid" parameter tested with 1st req good and 2nd req bad |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
220 # send 1st request and cache its good response |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
221 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
222 like(http_host_header('ttl.example.net', '/valid'), qr/200 OK/, 'valid'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
223 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
224 # response is cached, actual request would get error |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
225 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
226 like(http_host_header('ttl.example.net', '/valid'), qr/200 OK/, |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
227 'valid cached 1'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
228 like(http_host_header('ttl.example.net', '/valid'), qr/200 OK/, |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
229 'valid cached 2'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
230 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
231 sleep 2; |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
232 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
233 # expired ttl is overridden with "valid" parameter |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
234 # response is taken from cache |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
235 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
236 like(http_host_header('ttl.example.net', '/valid'), qr/200 OK/, |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
237 'valid overrides ttl'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
238 |
678
99233cfefbbe
Tests: adjusted test timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
550
diff
changeset
|
239 sleep 4; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
240 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
241 # expired "valid" value causes nginx to make actual query |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
242 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
243 like(http_host_header('ttl.example.net', '/valid'), qr/502 Bad/, |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
244 'valid expired'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
245 |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
246 # Ensure that resolver respects expired CNAME in CNAME + A combined response. |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
247 # When ttl in CNAME is expired, the answer should not be served from cache. |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
248 # Catch this by returning SERVFAIL on the 2nd and subsequent queries. |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
249 |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
250 http_host_header('cname_a_ttl2.example.net', '/'); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
251 |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
252 sleep 2; |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
253 |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
254 like(http_host_header('cname_a_ttl2.example.net', '/'), qr/502 Bad/, |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
255 'CNAME + A with expired CNAME ttl'); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
256 |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
257 like(http_host_header('example.net', '/invalid'), qr/502 Bad/, 'no resolver'); |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
258 |
436
4984dac109db
Tests: added test for resolver resend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
259 like(http_end($s), qr/200 OK/, 'resend after malformed response'); |
823
9623d353f066
Tests: http resolver tests with format error response code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
260 like(http_end($fe), qr/200 OK/, 'resend after format error'); |
436
4984dac109db
Tests: added test for resolver resend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
261 |
449
0bc79a098213
Tests: added resolver timeout test with multiple requests sent.
Sergey Kandaurov <pluknet@nginx.com>
parents:
438
diff
changeset
|
262 $s = http_get('/bad', start => 1); |
0bc79a098213
Tests: added resolver timeout test with multiple requests sent.
Sergey Kandaurov <pluknet@nginx.com>
parents:
438
diff
changeset
|
263 my $s2 = http_get('/bad', start => 1); |
0bc79a098213
Tests: added resolver timeout test with multiple requests sent.
Sergey Kandaurov <pluknet@nginx.com>
parents:
438
diff
changeset
|
264 |
0bc79a098213
Tests: added resolver timeout test with multiple requests sent.
Sergey Kandaurov <pluknet@nginx.com>
parents:
438
diff
changeset
|
265 http_end($s); |
0bc79a098213
Tests: added resolver timeout test with multiple requests sent.
Sergey Kandaurov <pluknet@nginx.com>
parents:
438
diff
changeset
|
266 ok(http_end($s2), 'timeout handler on 2nd request'); |
0bc79a098213
Tests: added resolver timeout test with multiple requests sent.
Sergey Kandaurov <pluknet@nginx.com>
parents:
438
diff
changeset
|
267 |
823
9623d353f066
Tests: http resolver tests with format error response code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
268 like(http_host_header('fe_id.example.net', '/'), qr/502 Bad/, 'format error'); |
9623d353f066
Tests: http resolver tests with format error response code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
269 |
824
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
270 # several requests waiting on same name query |
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
271 # 1st request aborts before name is resolved |
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
272 # 2nd request completes on resolver timeout |
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
273 |
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
274 $s = http_host_header('timeout.example.net', '/long', start => 1); |
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
275 $s2 = http_host_header('timeout.example.net', '/long', start => 1); |
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
276 |
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
277 select undef, undef, undef, 1.1; |
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
278 |
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
279 close $s; |
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
280 |
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
281 like(http_end($s2), qr/502 Bad/, 'timeout after aborted request'); |
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
282 |
834
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
283 # resend DNS query over TCP once UDP response came truncated |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
284 |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
285 unlike(http_host_header('tcp.example.net', '/tcp'), qr/127.0.0.201/, 'tc'); |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
286 like(http_host_header('tcp.example.net', '/tcp'), qr/X-IP: 127.0.0.1/, 'tcp'); |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
287 like(http_host_header('tcp2.example.net', '/tcp2'), qr/X-IP: 127.0.0.1/, |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
288 'tcp with resend'); |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
289 |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
290 ############################################################################### |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
291 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
292 sub http_host_header { |
438
60888e2c3f5a
Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
436
diff
changeset
|
293 my ($host, $uri, %extra) = @_; |
60888e2c3f5a
Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
436
diff
changeset
|
294 return http(<<EOF, %extra); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
295 GET $uri HTTP/1.0 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
296 Host: $host |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
297 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
298 EOF |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
299 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
300 |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
301 sub http_x_name_header { |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
302 my ($host, $uri) = @_; |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
303 return http(<<EOF); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
304 GET $uri HTTP/1.0 |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
305 X-Name: $host |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
306 |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
307 EOF |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
308 } |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
309 |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
310 ############################################################################### |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
311 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
312 sub reply_handler { |
834
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
313 my ($recv_data, $port, $state, %extra) = @_; |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
314 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
315 my (@name, @rdata); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
316 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
317 use constant NOERROR => 0; |
823
9623d353f066
Tests: http resolver tests with format error response code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
318 use constant FORMERR => 1; |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
319 use constant SERVFAIL => 2; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
320 use constant NXDOMAIN => 3; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
321 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
322 use constant A => 1; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
323 use constant CNAME => 5; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
324 use constant DNAME => 39; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
325 |
937
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
836
diff
changeset
|
326 use constant IN => 1; |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
327 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
328 # default values |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
329 |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
330 my ($hdr, $rcode, $ttl) = (0x8180, NOERROR, 3600); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
331 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
332 # decode name |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
333 |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
334 my ($len, $offset) = (undef, 12); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
335 while (1) { |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
336 $len = unpack("\@$offset C", $recv_data); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
337 last if $len == 0; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
338 $offset++; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
339 push @name, unpack("\@$offset A$len", $recv_data); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
340 $offset += $len; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
341 } |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
342 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
343 $offset -= 1; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
344 my ($id, $type, $class) = unpack("n x$offset n2", $recv_data); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
345 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
346 my $name = join('.', @name); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
347 if (($name eq 'a.example.net') || ($name eq 'alias.example.net')) { |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
348 if ($type == A || $type == CNAME) { |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
349 push @rdata, rd_addr($ttl, '127.0.0.1'); |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
350 } |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
351 |
823
9623d353f066
Tests: http resolver tests with format error response code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
352 } elsif ($name eq 'fe.example.net' && $type == A) { |
9623d353f066
Tests: http resolver tests with format error response code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
353 if (++$state->{fecnt} > 1) { |
9623d353f066
Tests: http resolver tests with format error response code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
354 $rcode = FORMERR; |
9623d353f066
Tests: http resolver tests with format error response code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
355 } |
9623d353f066
Tests: http resolver tests with format error response code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
356 |
9623d353f066
Tests: http resolver tests with format error response code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
357 push @rdata, rd_addr($ttl, '127.0.0.1'); |
9623d353f066
Tests: http resolver tests with format error response code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
358 |
9623d353f066
Tests: http resolver tests with format error response code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
359 } elsif ($name eq 'fe_id.example.net' && $type == A) { |
9623d353f066
Tests: http resolver tests with format error response code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
360 $id = 42; |
9623d353f066
Tests: http resolver tests with format error response code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
361 $rcode = FORMERR; |
9623d353f066
Tests: http resolver tests with format error response code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
775
diff
changeset
|
362 |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
363 } elsif ($name eq 'case.example.net' && $type == A) { |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
364 if (++$state->{casecnt} > 1) { |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
365 $rcode = SERVFAIL; |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
366 } |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
367 |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
368 push @rdata, rd_addr($ttl, '127.0.0.1'); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
369 |
436
4984dac109db
Tests: added test for resolver resend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
370 } elsif ($name eq 'id.example.net' && $type == A) { |
4984dac109db
Tests: added test for resolver resend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
371 if (++$state->{idcnt} == 1) { |
4984dac109db
Tests: added test for resolver resend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
372 $id++; |
4984dac109db
Tests: added test for resolver resend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
373 } |
4984dac109db
Tests: added test for resolver resend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
374 |
4984dac109db
Tests: added test for resolver resend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
375 push @rdata, rd_addr($ttl, '127.0.0.1'); |
4984dac109db
Tests: added test for resolver resend.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
376 |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
377 } elsif ($name eq 'awide.example.net' && $type == A) { |
775
a6764c2a9f12
Tests: fixed DNS label coding in resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
678
diff
changeset
|
378 push @rdata, pack '(C/a*)3x n2N nC4', |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
379 ('awide', 'example', 'net'), A, IN, $ttl, |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
380 4, (127, 0, 0, 1); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
381 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
382 } elsif (($name eq 'many.example.net') && $type == A) { |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
383 $state->{manycnt}++; |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
384 if ($state->{manycnt} > 1) { |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
385 $rcode = SERVFAIL; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
386 } |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
387 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
388 push @rdata, rd_addr($ttl, '127.0.0.201'); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
389 push @rdata, rd_addr($ttl, '127.0.0.202'); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
390 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
391 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
392 } elsif (($name eq 'short.example.net')) { |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
393 # zero length RDATA in DNS response |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
394 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
395 if ($type == A) { |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
396 push @rdata, rd_addr($ttl, ''); |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
397 } |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
398 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
399 } elsif (($name eq 'alias.example.com')) { |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
400 # example.com. 3600 IN DNAME example.net. |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
401 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
402 my @dname = ('example', 'net'); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
403 my $rdlen = length(join '', @dname) + @dname + 1; |
775
a6764c2a9f12
Tests: fixed DNS label coding in resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
678
diff
changeset
|
404 push @rdata, pack("n3N n(C/a*)* x", 0xc012, DNAME, IN, $ttl, |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
405 $rdlen, @dname); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
406 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
407 # alias.example.com. 3600 IN CNAME alias.example.net. |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
408 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
409 push @rdata, pack("n3N nCa5n", 0xc00c, CNAME, IN, $ttl, |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
410 8, 5, 'alias', 0xc02f); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
411 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
412 } elsif ($name eq 'cname.example.net') { |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
413 $state->{cnamecnt}++; |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
414 if ($state->{cnamecnt} > 2) { |
937
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
836
diff
changeset
|
415 $rcode = SERVFAIL; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
416 } |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
417 push @rdata, pack("n3N nCa5n", 0xc00c, CNAME, IN, $ttl, |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
418 8, 5, 'alias', 0xc012); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
419 |
824
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
420 } elsif ($name eq 'timeout.example.net') { |
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
421 select undef, undef, undef, 2.1; |
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
422 return; |
9caacdb56b53
Tests: added test for resolver timeout after aborted request.
Sergey Kandaurov <pluknet@nginx.com>
parents:
823
diff
changeset
|
423 |
356
7a472e46772c
Tests: added http resolver test for CNAME + A combined answer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
352
diff
changeset
|
424 } elsif ($name eq 'cname_a.example.net') { |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
425 push @rdata, pack("n3N nCa5n", 0xc00c, CNAME, IN, $ttl, |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
426 8, 5, 'alias', 0xc014); |
356
7a472e46772c
Tests: added http resolver test for CNAME + A combined answer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
352
diff
changeset
|
427 |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
428 # points to "alias" set in previous rdata |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
429 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
430 if ($type == A) { |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
431 push @rdata, pack('n3N nC4', 0xc031, A, IN, $ttl, |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
432 4, split(/\./, '127.0.0.1')); |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
433 } |
356
7a472e46772c
Tests: added http resolver test for CNAME + A combined answer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
352
diff
changeset
|
434 |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
435 } elsif ($name eq 'cname_a_ttl2.example.net' && $type == A) { |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
436 push @rdata, pack("n3N nCa18n", 0xc00c, CNAME, IN, 1, |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
437 21, 18, 'cname_a_ttl2_alias', 0xc019); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
438 if (++$state->{cttl2cnt} >= 2) { |
937
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
836
diff
changeset
|
439 $rcode = SERVFAIL; |
362
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
440 } |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
441 push @rdata, pack('n3N nC4', 0xc036, A, IN, $ttl, |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
442 4, split(/\./, '127.0.0.1')); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
443 |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
444 } elsif ($name eq 'cname_a_ttl_alias.example.net' && $type == A) { |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
445 push @rdata, rd_addr($ttl, '127.0.0.1'); |
8ca9c75c97d2
Tests: more resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
359
diff
changeset
|
446 |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
447 } elsif ($name eq 'cname2.example.net') { |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
448 # points to non-existing A |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
449 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
450 push @rdata, pack("n3N nCa2n", 0xc00c, CNAME, IN, $ttl, |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
451 5, 2, 'nx', 0xc02f); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
452 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
453 } elsif ($name eq 'long.example.net') { |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
454 push @rdata, pack("n3N nCA63x", 0xc00c, CNAME, IN, $ttl, |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
455 65, 63, 'a' x 63); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
456 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
457 } elsif (($name eq 'a' x 63) && $type == A) { |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
458 push @rdata, rd_addr($ttl, '127.0.0.1'); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
459 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
460 } elsif ($name eq 'long2.example.net') { |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
461 push @rdata, pack("n3N n(CA63)4x", 0xc00c, CNAME, IN, $ttl, 257, |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
462 63, 'a' x 63, 63, 'a' x 63, 63, 'a' x 63, 63, 'a' x 63); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
463 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
464 } elsif (($name eq 'a' x 63 . '.' . 'a' x 63 . '.' . 'a' x 63 . '.' |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
465 . 'a' x 63) && $type == A) |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
466 { |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
467 push @rdata, rd_addr($ttl, '127.0.0.1'); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
468 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
469 } elsif ($name eq 'ttl.example.net' && $type == A) { |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
470 $state->{ttlcnt}++; |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
471 if ($state->{ttlcnt} == 2 || $state->{ttlcnt} == 4) { |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
472 $rcode = SERVFAIL; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
473 } |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
474 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
475 push @rdata, rd_addr(1, '127.0.0.1'); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
476 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
477 } elsif ($name eq 'ttl0.example.net' && $type == A) { |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
478 $state->{ttl0cnt}++; |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
479 if ($state->{ttl0cnt} == 2) { |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
480 $rcode = SERVFAIL; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
481 } |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
482 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
483 push @rdata, rd_addr(0, '127.0.0.1'); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
484 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
485 } elsif ($name eq '2.example.net') { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
486 if ($port == port(8981)) { |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
487 $state->{twocnt}++; |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
488 } |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
489 if ($state->{twocnt} & 1) { |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
490 $rcode = SERVFAIL; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
491 } |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
492 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
493 if ($type == A) { |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
494 push @rdata, rd_addr($ttl, '127.0.0.1'); |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
495 } |
834
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
496 |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
497 } elsif ($name =~ /tcp2?.example.net/) { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
498 $rcode = FORMERR if $port == port(8982); |
834
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
499 $hdr |= 0x0300 unless $extra{tcp}; |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
500 push @rdata, rd_addr($ttl, $extra{tcp} |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
501 ? '127.0.0.1' : '127.0.0.201') if $type == A; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
502 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
503 |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
504 $len = @name; |
775
a6764c2a9f12
Tests: fixed DNS label coding in resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
678
diff
changeset
|
505 pack("n6 (C/a*)$len x n2", $id, $hdr | $rcode, 1, scalar @rdata, |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
506 0, 0, @name, $type, $class) . join('', @rdata); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
507 } |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
508 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
509 sub rd_addr { |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
510 my ($ttl, $addr) = @_; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
511 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
512 my $code = 'split(/\./, $addr)'; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
513 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
514 return pack 'n3N', 0xc00c, A, IN, $ttl if $addr eq ''; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
515 |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
516 pack 'n3N nC4', 0xc00c, A, IN, $ttl, eval "scalar $code", eval($code); |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
517 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
518 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
519 sub dns_daemon { |
834
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
520 my ($port, $t, %extra) = @_; |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
521 |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
522 my ($data, $recv_data); |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
523 my $socket = IO::Socket::INET->new( |
937
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
836
diff
changeset
|
524 LocalAddr => '127.0.0.1', |
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
836
diff
changeset
|
525 LocalPort => $port, |
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
836
diff
changeset
|
526 Proto => 'udp', |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
527 ) |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
528 or die "Can't create listening socket: $!\n"; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
529 |
834
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
530 my $sel = IO::Select->new($socket); |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
531 my $tcp = 0; |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
532 |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
533 if ($extra{tcp}) { |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1020
diff
changeset
|
534 $tcp = port(8983, socket => 1); |
834
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
535 $sel->add($tcp); |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
536 } |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
537 |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
538 local $SIG{PIPE} = 'IGNORE'; |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
539 |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
540 # track number of relevant queries |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
541 |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
542 my %state = ( |
937
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
836
diff
changeset
|
543 cnamecnt => 0, |
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
836
diff
changeset
|
544 twocnt => 0, |
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
836
diff
changeset
|
545 ttlcnt => 0, |
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
836
diff
changeset
|
546 ttl0cnt => 0, |
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
836
diff
changeset
|
547 cttlcnt => 0, |
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
836
diff
changeset
|
548 cttl2cnt => 0, |
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
836
diff
changeset
|
549 manycnt => 0, |
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
836
diff
changeset
|
550 casecnt => 0, |
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
836
diff
changeset
|
551 idcnt => 0, |
b1fa8e0cc27b
Tests: whitespaces fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
836
diff
changeset
|
552 fecnt => 0, |
359
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
553 ); |
cdab739eb6ea
Tests: resolver tests enabled to work with AAAA capable resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
357
diff
changeset
|
554 |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
555 # signal we are ready |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
556 |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
557 open my $fh, '>', $t->testdir() . '/' . $port; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
558 close $fh; |
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
559 |
834
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
560 while (my @ready = $sel->can_read) { |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
561 foreach my $fh (@ready) { |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
562 if ($tcp == $fh) { |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
563 my $new = $fh->accept; |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
564 $new->autoflush(1); |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
565 $sel->add($new); |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
566 |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
567 } elsif ($socket == $fh) { |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
568 $fh->recv($recv_data, 65536); |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
569 $data = reply_handler($recv_data, $port, |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
570 \%state); |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
571 $fh->send($data); |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
572 |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
573 } else { |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
574 $fh->recv($recv_data, 65536); |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
575 unless (length $recv_data) { |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
576 $sel->remove($fh); |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
577 $fh->close; |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
578 next; |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
579 } |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
580 |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
581 again: |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
582 my $len = unpack("n", $recv_data); |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
583 $data = substr $recv_data, 2, $len; |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
584 $data = reply_handler($data, $port, \%state, |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
585 tcp => 1); |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
586 $data = pack("n", length $data) . $data; |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
587 $fh->send($data); |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
588 $recv_data = substr $recv_data, 2 + $len; |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
589 goto again if length $recv_data; |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
590 } |
37747a4ff78e
Tests: simple http resolver tests over TCP.
Sergey Kandaurov <pluknet@nginx.com>
parents:
824
diff
changeset
|
591 } |
357
e0c00e695cb5
Tests: removed Net::DNS dependency.
Sergey Kandaurov <pluknet@nginx.com>
parents:
356
diff
changeset
|
592 } |
352
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
593 } |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
594 |
145c37f27c5a
Tests: added resolver tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
595 ############################################################################### |