annotate grpc_pass.t @ 1976:4e79bd25642f default tip

Tests: added test for headers without a colon.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 11 May 2024 18:56:23 +0300
parents 236d038dc04a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 {
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 listen 127.0.0.1:8081 http2;
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 listen 127.0.0.1:8082 http2 ssl;
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
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 ssl_certificate_key localhost.key;
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 ssl_certificate localhost.crt;
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 location / {
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 return 200 $http_host;
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 }
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 }
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 EOF
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 $t->write_file('openssl.conf', <<EOF);
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 [ req ]
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 default_bits = 2048
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 encrypt_key = no
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 distinguished_name = req_distinguished_name
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 [ req_distinguished_name ]
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 EOF
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 my $d = $t->testdir();
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 foreach my $name ('localhost') {
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 system('openssl req -x509 -new '
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 . "-config $d/openssl.conf -subj /CN=$name/ "
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 . "-out $d/$name.crt -keyout $d/$name.key "
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 . ">>$d/openssl.out 2>&1") == 0
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 or die "Can't create certificate for $name: $!\n";
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 }
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 $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
100
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1860
diff changeset
101 # suppress deprecation warning
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1860
diff changeset
102
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1860
diff changeset
103 open OLDERR, ">&", \*STDERR; close STDERR;
1693
5ac6efbe5552 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1547
diff changeset
104 $t->run()->plan(5);
1900
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1860
diff changeset
105 open STDERR, ">&", \*OLDERR;
1547
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 $t->waitforfile($t->testdir . '/' . port(8982));
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 ###############################################################################
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 like(http_get('/basic'), qr/200 OK/, 'no scheme');
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 like(http_get('/grpc'), qr/200 OK/, 'grpc scheme');
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 SKIP: {
1860
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1693
diff changeset
115 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
116
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 like(http_get('/grpcs'), qr/200 OK/, 'grpcs scheme');
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 }
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 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
122 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
123
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 ###############################################################################
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 sub reply_handler {
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127 my ($recv_data) = @_;
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 my (@name, @rdata);
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 use constant NOERROR => 0;
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 use constant A => 1;
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133 use constant IN => 1;
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 # default values
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 my ($hdr, $rcode, $ttl) = (0x8180, NOERROR, 3600);
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 # decode name
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141 my ($len, $offset) = (undef, 12);
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142 while (1) {
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143 $len = unpack("\@$offset C", $recv_data);
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
144 last if $len == 0;
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145 $offset++;
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146 push @name, unpack("\@$offset A$len", $recv_data);
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147 $offset += $len;
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148 }
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150 $offset -= 1;
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 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
152
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153 my $name = join('.', @name);
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154 if ($name eq 'localhost' && $type == A) {
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155 push @rdata, rd_addr($ttl, '127.0.0.1');
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156 }
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 $len = @name;
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159 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
160 0, 0, @name, $type, $class) . join('', @rdata);
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
161 }
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
163 sub rd_addr {
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
164 my ($ttl, $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 my $code = 'split(/\./, $addr)';
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 return pack 'n3N', 0xc00c, A, IN, $ttl if $addr eq '';
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 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
171 }
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173 sub dns_daemon {
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
174 my ($port, $t) = @_;
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
176 my ($data, $recv_data);
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177 my $socket = IO::Socket::INET->new(
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
178 LocalAddr => '127.0.0.1',
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179 LocalPort => $port,
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
180 Proto => 'udp',
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 or die "Can't create listening socket: $!\n";
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 # signal we are ready
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
185
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
186 open my $fh, '>', $t->testdir() . '/' . $port;
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
187 close $fh;
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189 while (1) {
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
190 $socket->recv($recv_data, 65536);
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
191 $data = reply_handler($recv_data);
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
192 $socket->send($data);
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 }
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195
2d747d967fc0 Tests: grpc_pass with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196 ###############################################################################