Mercurial > hg > nginx-tests
annotate grpc_pass.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 11463d379570 |
children |
rev | line source |
---|---|
1547
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for the grpc_pass directive with variables. |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 grpc rewrite/) |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 ->has_daemon('openssl')->write_file_expand('nginx.conf', <<'EOF'); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 events { |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 http { |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 upstream u { |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 server 127.0.0.1:8081; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 resolver 127.0.0.1:%%PORT_8982_UDP%%; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 server { |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 listen 127.0.0.1:8080; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 server_name localhost; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 location / { |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 grpc_pass $host:%%PORT_8081%%; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 location /grpc { |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 grpc_pass grpc://$host:%%PORT_8081%%; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 location /grpcs { |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 grpc_pass grpcs://$host:%%PORT_8082%%; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 location /arg { |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 grpc_pass $arg_b; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 server { |
1986
11463d379570
Tests: reworked HTTP/2 tests to use "http2 on".
Maxim Dounin <mdounin@mdounin.ru>
parents:
1900
diff
changeset
|
66 listen 127.0.0.1:8081; |
11463d379570
Tests: reworked HTTP/2 tests to use "http2 on".
Maxim Dounin <mdounin@mdounin.ru>
parents:
1900
diff
changeset
|
67 listen 127.0.0.1:8082 ssl; |
1547
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 server_name localhost; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 |
1986
11463d379570
Tests: reworked HTTP/2 tests to use "http2 on".
Maxim Dounin <mdounin@mdounin.ru>
parents:
1900
diff
changeset
|
70 http2 on; |
11463d379570
Tests: reworked HTTP/2 tests to use "http2 on".
Maxim Dounin <mdounin@mdounin.ru>
parents:
1900
diff
changeset
|
71 |
1547
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 ssl_certificate_key localhost.key; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 ssl_certificate localhost.crt; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 location / { |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 return 200 $http_host; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 EOF |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 $t->write_file('openssl.conf', <<EOF); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 [ req ] |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 default_bits = 2048 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 encrypt_key = no |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 distinguished_name = req_distinguished_name |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 [ req_distinguished_name ] |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 EOF |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 my $d = $t->testdir(); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 foreach my $name ('localhost') { |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 system('openssl req -x509 -new ' |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 . "-config $d/openssl.conf -subj /CN=$name/ " |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 . "-out $d/$name.crt -keyout $d/$name.key " |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 . ">>$d/openssl.out 2>&1") == 0 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 or die "Can't create certificate for $name: $!\n"; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 $t->run_daemon(\&dns_daemon, port(8982), $t); |
1900
236d038dc04a
Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1860
diff
changeset
|
102 |
1693
5ac6efbe5552
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1547
diff
changeset
|
103 $t->run()->plan(5); |
1547
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 $t->waitforfile($t->testdir . '/' . port(8982)); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 ############################################################################### |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 like(http_get('/basic'), qr/200 OK/, 'no scheme'); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 like(http_get('/grpc'), qr/200 OK/, 'grpc scheme'); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 SKIP: { |
1860
58951cf933e1
Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1693
diff
changeset
|
113 skip 'OpenSSL too old', 1 unless $t->has_feature('openssl:1.0.2'); |
1547
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 like(http_get('/grpcs'), qr/200 OK/, 'grpcs scheme'); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 like(http_get('/arg?b=grpc://127.0.0.1:' . port(8081)), qr/200 OK/, 'addrs'); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 like(http_get('/arg?b=grpc://u'), qr/200 OK/, 'no_port'); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 ############################################################################### |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 sub reply_handler { |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 my ($recv_data) = @_; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 my (@name, @rdata); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 use constant NOERROR => 0; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 use constant A => 1; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 use constant IN => 1; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 # default values |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 my ($hdr, $rcode, $ttl) = (0x8180, NOERROR, 3600); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 # decode name |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 my ($len, $offset) = (undef, 12); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 while (1) { |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 $len = unpack("\@$offset C", $recv_data); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 last if $len == 0; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 $offset++; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 push @name, unpack("\@$offset A$len", $recv_data); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 $offset += $len; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 $offset -= 1; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 my ($id, $type, $class) = unpack("n x$offset n2", $recv_data); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 my $name = join('.', @name); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 if ($name eq 'localhost' && $type == A) { |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 push @rdata, rd_addr($ttl, '127.0.0.1'); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 $len = @name; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 pack("n6 (C/a*)$len x n2", $id, $hdr | $rcode, 1, scalar @rdata, |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 0, 0, @name, $type, $class) . join('', @rdata); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 sub rd_addr { |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 my ($ttl, $addr) = @_; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 my $code = 'split(/\./, $addr)'; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 return pack 'n3N', 0xc00c, A, IN, $ttl if $addr eq ''; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 pack 'n3N nC4', 0xc00c, A, IN, $ttl, eval "scalar $code", eval($code); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 sub dns_daemon { |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 my ($port, $t) = @_; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 my ($data, $recv_data); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 my $socket = IO::Socket::INET->new( |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 LocalAddr => '127.0.0.1', |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 LocalPort => $port, |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 Proto => 'udp', |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 ) |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 or die "Can't create listening socket: $!\n"; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 # signal we are ready |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 open my $fh, '>', $t->testdir() . '/' . $port; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 close $fh; |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 while (1) { |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 $socket->recv($recv_data, 65536); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 $data = reply_handler($recv_data); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 $socket->send($data); |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
192 } |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 |
2d747d967fc0
Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 ############################################################################### |