Mercurial > hg > nginx-tests
annotate stream_resolver.t @ 1995:d329b05e20fa
Tests: removed usage of "cat" and "grep" in tests.
Both "cat" and "grep" might not be available on Windows. Instead,
$t->read_file() is used, as it is already used in other places. To
simplify checking logs as previously done with "grep", $t->grep_file()
helper function is introduced.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 09 Aug 2024 05:18:51 +0300 |
parents | f3ba4c74de31 |
children |
rev | line source |
---|---|
988
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream upstream name resolved, proxy_next_upstream_tries. |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::Stream qw/ stream /; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/stream stream_map stream_return/) |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 ->write_file_expand('nginx.conf', <<'EOF'); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1251
diff
changeset
|
37 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1251
diff
changeset
|
38 |
988
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 map $server_port $upstream { |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 %%PORT_8081%% a.example.com:%%PORT_8090%%; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 %%PORT_8082%% a.example.com; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 %%PORT_8083%% nx.example.com:%%PORT_8082%%; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 map $server_port $many { |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 default $server_port.many.example.com; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
992
diff
changeset
|
49 resolver 127.0.0.1:%%PORT_8980_UDP%%; |
988
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server { |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 listen 127.0.0.1:8081; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 listen 127.0.0.1:8082; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 listen 127.0.0.1:8083; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 proxy_pass $upstream; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 server { |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 listen 127.0.0.1:8084; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 proxy_pass $many:%%PORT_8090%%; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 proxy_next_upstream_tries 3; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 proxy_connect_timeout 1s; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 server { |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 listen 127.0.0.1:8085; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 proxy_pass $many:%%PORT_8090%%; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 proxy_next_upstream_tries 2; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 proxy_connect_timeout 1s; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 server { |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 listen 127.0.0.1:8086; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 proxy_pass $many:%%PORT_8090%%; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 proxy_next_upstream_tries 0; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 proxy_connect_timeout 1s; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 server { |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 listen 127.0.0.1:8090; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 return SEE-THIS; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 EOF |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
992
diff
changeset
|
90 $t->run_daemon(\&dns_daemon, port(8980), $t); |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
91 $t->run()->plan(8); |
988
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
992
diff
changeset
|
93 $t->waitforfile($t->testdir . '/' . port(8980)); |
988
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 ############################################################################### |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
992
1beb641e21c9
Tests: fixed tests on win32 with stream return module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
988
diff
changeset
|
97 ok(stream('127.0.0.1:' . port(8081))->read(), 'resolver'); |
1beb641e21c9
Tests: fixed tests on win32 with stream return module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
988
diff
changeset
|
98 ok(!stream('127.0.0.1:' . port(8082))->read(), 'upstream no port'); |
1beb641e21c9
Tests: fixed tests on win32 with stream return module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
988
diff
changeset
|
99 ok(!stream('127.0.0.1:' . port(8083))->read(), 'name not found'); |
988
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
992
1beb641e21c9
Tests: fixed tests on win32 with stream return module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
988
diff
changeset
|
101 ok(stream('127.0.0.1:' . port(8084))->read(), 'resolved tries'); |
1beb641e21c9
Tests: fixed tests on win32 with stream return module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
988
diff
changeset
|
102 ok(!stream('127.0.0.1:' . port(8085))->read(), 'resolved tries limited'); |
1beb641e21c9
Tests: fixed tests on win32 with stream return module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
988
diff
changeset
|
103 ok(stream('127.0.0.1:' . port(8086))->read(), 'resolved tries zero'); |
988
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 $t->stop(); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 SKIP: { |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 skip "relies on error log contents", 2 unless $ENV{TEST_NGINX_UNSAFE}; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
1995
d329b05e20fa
Tests: removed usage of "cat" and "grep" in tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1609
diff
changeset
|
110 my $log = $t->grep_file('error.log', '[error]'); |
988
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 like($log, qr/no port in upstream "a.example.com"/, 'log - no port'); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 like($log, qr/nx.example.com could not be resolved/, 'log - not found'); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 ############################################################################### |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 sub reply_handler { |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 my ($recv_data, $port) = @_; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 my (@name, @rdata); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 use constant NOERROR => 0; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 use constant A => 1; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 use constant IN => 1; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 # default values |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 my ($hdr, $rcode, $ttl) = (0x8180, NOERROR, 3600); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 # decode name |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 my ($len, $offset) = (undef, 12); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 while (1) { |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 $len = unpack("\@$offset C", $recv_data); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 last if $len == 0; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 $offset++; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 push @name, unpack("\@$offset A$len", $recv_data); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 $offset += $len; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 $offset -= 1; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 my ($id, $type, $class) = unpack("n x$offset n2", $recv_data); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 my $name = join('.', @name); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 if ($name eq 'a.example.com' && $type == A) { |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 push @rdata, rd_addr($ttl, '127.0.0.1'); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 } elsif ($name =~ qr/many.example.com/ && $type == A) { |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 push @rdata, rd_addr($ttl, '127.0.0.2'); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 push @rdata, rd_addr($ttl, '127.0.0.2'); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 push @rdata, rd_addr($ttl, '127.0.0.1'); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 $len = @name; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 pack("n6 (C/a*)$len x n2", $id, $hdr | $rcode, 1, scalar @rdata, |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 0, 0, @name, $type, $class) . join('', @rdata); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 sub rd_addr { |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 my ($ttl, $addr) = @_; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 my $code = 'split(/\./, $addr)'; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 return pack 'n3N', 0xc00c, A, IN, $ttl if $addr eq ''; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 pack 'n3N nC4', 0xc00c, A, IN, $ttl, eval "scalar $code", eval($code); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 sub dns_daemon { |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 my ($port, $t) = @_; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 my ($data, $recv_data); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 my $socket = IO::Socket::INET->new( |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 LocalAddr => '127.0.0.1', |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 LocalPort => $port, |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 Proto => 'udp', |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 ) |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 or die "Can't create listening socket: $!\n"; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 local $SIG{PIPE} = 'IGNORE'; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 # signal we are ready |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 open my $fh, '>', $t->testdir() . '/' . $port; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 close $fh; |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 while (1) { |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 $socket->recv($recv_data, 65536); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 $data = reply_handler($recv_data, $port); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 $socket->send($data); |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
192 } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 } |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 |
64505109060c
Tests: simple stream proxy tests with resolver.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 ############################################################################### |