Mercurial > hg > nginx-tests
annotate grpc_ssl.t @ 1851:0351dee227a8
Tests: unbreak tests with dynamic certificates on stable.
In 74cffa9d4c43, ticket based session reuse is enabled in addition to
using a shared SSL session cache. This changed how a session can be
resumed in a different server:
- for a session ID based resumption, it is resumed in the same context
- when using session tickets, a key name is also checked for matching
- with a ticket callback, this is skipped in favor of callback's logic
This makes 'session id context match' tests fail with session tickets
on stable since ticket key names are unique in distinct SSL contexts.
On the other hand, tests pass on 1.23.2+ due to automatic ticket keys
rotation that installs ticket callback, and using a common shared SSL
session cache.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 28 Mar 2023 01:36:32 +0400 |
parents | b27bcded6449 |
children | 58951cf933e1 |
rev | line source |
---|---|
1303 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for grpc backend with ssl. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 use Test::Nginx::HTTP2; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
1312
6f95c0ed2335
Tests: removed proxy prerequisite from grpc tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1303
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http rewrite http_v2 grpc/) |
1378
ba7e2e60f8b6
Tests: fixed grpc_ssl.t prerequisites.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1376
diff
changeset
|
27 ->has(qw/upstream_keepalive http_ssl/)->has_daemon('openssl'); |
1303 | 28 |
29 $t->{_configure_args} =~ /OpenSSL ([\d\.]+)/; | |
30 plan(skip_all => 'OpenSSL too old') unless defined $1 and $1 ge '1.0.2'; | |
31 | |
1725
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
32 $t->write_file_expand('nginx.conf', <<'EOF')->plan(38); |
1303 | 33 |
34 %%TEST_GLOBALS%% | |
35 | |
36 daemon off; | |
37 | |
38 events { | |
39 } | |
40 | |
41 http { | |
42 %%TEST_GLOBALS_HTTP%% | |
43 | |
44 upstream u { | |
45 server 127.0.0.1:8081; | |
46 keepalive 1; | |
47 } | |
48 | |
49 server { | |
50 listen 127.0.0.1:8081 http2 ssl; | |
51 server_name localhost; | |
52 | |
53 ssl_certificate_key localhost.key; | |
54 ssl_certificate localhost.crt; | |
55 | |
1313
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
56 ssl_verify_client optional; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
57 ssl_client_certificate client.crt; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
58 |
1725
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
59 http2_body_preread_size 128k; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
60 |
1303 | 61 location / { |
62 grpc_pass 127.0.0.1:8082; | |
63 add_header X-Connection $connection; | |
64 } | |
65 } | |
66 | |
67 server { | |
68 listen 127.0.0.1:8080 http2; | |
69 server_name localhost; | |
70 | |
1725
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
71 http2_body_preread_size 128k; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
72 |
1303 | 73 location / { |
74 grpc_pass grpcs://127.0.0.1:8081; | |
1313
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
75 grpc_ssl_name localhost; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
76 grpc_ssl_verify on; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
77 grpc_ssl_trusted_certificate localhost.crt; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
78 |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
79 grpc_ssl_certificate client.crt; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
80 grpc_ssl_certificate_key client.key; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
81 grpc_ssl_password_file password; |
1303 | 82 |
83 if ($arg_if) { | |
84 # nothing | |
85 } | |
86 | |
87 limit_except GET { | |
88 # nothing | |
89 } | |
90 } | |
91 | |
92 location /KeepAlive { | |
93 grpc_pass grpcs://u; | |
94 } | |
95 } | |
96 } | |
97 | |
98 EOF | |
99 | |
100 $t->write_file('openssl.conf', <<EOF); | |
101 [ req ] | |
1488
dbce8fb5f5f8
Tests: align with OpenSSL security level 2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1415
diff
changeset
|
102 default_bits = 2048 |
1303 | 103 encrypt_key = no |
104 distinguished_name = req_distinguished_name | |
105 [ req_distinguished_name ] | |
106 EOF | |
107 | |
108 my $d = $t->testdir(); | |
109 | |
110 foreach my $name ('localhost') { | |
111 system('openssl req -x509 -new ' | |
112 . "-config $d/openssl.conf -subj /CN=$name/ " | |
113 . "-out $d/$name.crt -keyout $d/$name.key " | |
114 . ">>$d/openssl.out 2>&1") == 0 | |
115 or die "Can't create certificate for $name: $!\n"; | |
116 } | |
117 | |
1313
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
118 foreach my $name ('client') { |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
119 system("openssl genrsa -out $d/$name.key -passout pass:$name " |
1488
dbce8fb5f5f8
Tests: align with OpenSSL security level 2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1415
diff
changeset
|
120 . "-aes128 2048 >>$d/openssl.out 2>&1") == 0 |
1313
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
121 or die "Can't create private key: $!\n"; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
122 system('openssl req -x509 -new ' |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
123 . "-config $d/openssl.conf -subj /CN=$name/ " |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
124 . "-out $d/$name.crt " |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
125 . "-key $d/$name.key -passin pass:$name" |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
126 . ">>$d/openssl.out 2>&1") == 0 |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
127 or die "Can't create certificate for $name: $!\n"; |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
128 } |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
129 |
1323
6eb3dd2d4d5a
Tests: postponed grpc_ssl.t startup on win32, see eadd24ccfda1.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
130 sleep 1 if $^O eq 'MSWin32'; |
6eb3dd2d4d5a
Tests: postponed grpc_ssl.t startup on win32, see eadd24ccfda1.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
131 |
1313
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
132 $t->write_file('password', 'client'); |
cc2f17cd9677
Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
133 |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1378
diff
changeset
|
134 $t->run(); |
1303 | 135 |
136 ############################################################################### | |
137 | |
138 my $p = port(8082); | |
139 my $f = grpc(); | |
140 | |
141 my $frames = $f->{http_start}('/SayHello'); | |
142 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
143 is($frame->{flags}, 4, 'request - HEADERS flags'); | |
144 ok((my $sid = $frame->{sid}) % 2, 'request - HEADERS sid odd'); | |
145 is($frame->{headers}{':method'}, 'POST', 'request - method'); | |
146 is($frame->{headers}{':scheme'}, 'http', 'request - scheme'); | |
147 is($frame->{headers}{':path'}, '/SayHello', 'request - path'); | |
148 is($frame->{headers}{':authority'}, "127.0.0.1:$p", 'request - authority'); | |
149 is($frame->{headers}{'content-type'}, 'application/grpc', | |
150 'request - content type'); | |
151 is($frame->{headers}{te}, 'trailers', 'request - te'); | |
152 | |
153 $frames = $f->{data}('Hello'); | |
154 ($frame) = grep { $_->{type} eq "SETTINGS" } @$frames; | |
155 is($frame->{flags}, 1, 'request - SETTINGS ack'); | |
156 is($frame->{sid}, 0, 'request - SETTINGS sid'); | |
157 is($frame->{length}, 0, 'request - SETTINGS length'); | |
158 | |
159 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
160 is($frame->{data}, 'Hello', 'request - DATA'); | |
161 is($frame->{length}, 5, 'request - DATA length'); | |
162 is($frame->{flags}, 1, 'request - DATA flags'); | |
163 is($frame->{sid}, $sid, 'request - DATA sid match'); | |
164 | |
165 $frames = $f->{http_end}(); | |
166 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
167 is($frame->{flags}, 4, 'response - HEADERS flags'); | |
168 is($frame->{sid}, 1, 'response - HEADERS sid'); | |
169 is($frame->{headers}{':status'}, '200', 'response - status'); | |
170 is($frame->{headers}{'content-type'}, 'application/grpc', | |
171 'response - content type'); | |
172 ok($frame->{headers}{server}, 'response - server'); | |
173 ok($frame->{headers}{date}, 'response - date'); | |
174 ok(my $c = $frame->{headers}{'x-connection'}, 'response - connection'); | |
175 | |
176 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
177 is($frame->{data}, 'Hello world', 'response - DATA'); | |
178 is($frame->{length}, 11, 'response - DATA length'); | |
179 is($frame->{flags}, 0, 'response - DATA flags'); | |
180 is($frame->{sid}, 1, 'response - DATA sid'); | |
181 | |
182 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
183 is($frame->{flags}, 5, 'response - trailers flags'); | |
184 is($frame->{sid}, 1, 'response - trailers sid'); | |
185 is($frame->{headers}{'grpc-message'}, '', 'response - trailers message'); | |
186 is($frame->{headers}{'grpc-status'}, '0', 'response - trailers status'); | |
187 | |
188 # next request is on a new backend connection, no sid incremented | |
189 | |
190 $f->{http_start}('/SayHello'); | |
191 $f->{data}('Hello'); | |
192 $frames = $f->{http_end}(); | |
193 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
194 cmp_ok($frame->{headers}{'x-connection'}, '>', $c, 'response 2 - connection'); | |
195 | |
1725
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
196 # flow control |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
197 |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
198 $f->{http_start}('/FlowControl'); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
199 $frames = $f->{data_len}(('Hello' x 13000) . ('x' x 550), 65535); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
200 my $sum = eval join '+', map { $_->{type} eq "DATA" && $_->{length} } @$frames; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
201 is($sum, 65535, 'flow control - iws length'); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
202 |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
203 $f->{update}(10); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
204 $f->{update_sid}(10); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
205 |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
206 $frames = $f->{data_len}(undef, 10); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
207 ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
208 is($frame->{length}, 10, 'flow control - update length'); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
209 is($frame->{flags}, 0, 'flow control - update flags'); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
210 |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
211 $f->{update_sid}(10); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
212 $f->{update}(10); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
213 |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
214 $frames = $f->{data_len}(undef, 5); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
215 ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
216 is($frame->{length}, 5, 'flow control - rest length'); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
217 is($frame->{flags}, 1, 'flow control - rest flags'); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
218 |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
219 $f->{http_end}(); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
220 |
1303 | 221 # upstream keepalive |
222 | |
223 $f->{http_start}('/KeepAlive'); | |
224 $f->{data}('Hello'); | |
225 $frames = $f->{http_end}(); | |
226 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
227 ok($c = $frame->{headers}{'x-connection'}, 'keepalive - connection'); | |
228 | |
229 $f->{http_start}('/KeepAlive'); | |
230 $f->{data}('Hello'); | |
231 $frames = $f->{http_end}(); | |
232 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
233 is($frame->{headers}{'x-connection'}, $c, 'keepalive - connection reuse'); | |
234 | |
235 ############################################################################### | |
236 | |
237 sub grpc { | |
238 my ($server, $client, $f, $s, $c, $sid, $uri); | |
239 | |
240 $server = IO::Socket::INET->new( | |
241 Proto => 'tcp', | |
242 LocalHost => '127.0.0.1', | |
243 LocalPort => $p, | |
244 Listen => 5, | |
245 Reuse => 1 | |
246 ) | |
247 or die "Can't create listening socket: $!\n"; | |
248 | |
249 $f->{http_start} = sub { | |
250 ($uri, my %extra) = @_; | |
251 my $body_more = 1 if $uri !~ /LongHeader/; | |
252 $s = Test::Nginx::HTTP2->new() if !defined $s; | |
253 $s->new_stream({ body_more => $body_more, headers => [ | |
254 { name => ':method', value => 'POST', mode => 0 }, | |
255 { name => ':scheme', value => 'http', mode => 0 }, | |
256 { name => ':path', value => $uri, }, | |
257 { name => ':authority', value => 'localhost' }, | |
258 { name => 'content-type', value => 'application/grpc' }, | |
259 { name => 'te', value => 'trailers', mode => 2 }]}); | |
260 | |
261 if (!$extra{reuse}) { | |
1321
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
262 eval { |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
263 local $SIG{ALRM} = sub { die "timeout\n" }; |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
264 alarm(5); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
265 |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
266 $client = $server->accept() or return; |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
267 |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
268 alarm(0); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
269 }; |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
270 alarm(0); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
271 if ($@) { |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
272 log_in("died: $@"); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
273 return undef; |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
274 } |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1313
diff
changeset
|
275 |
1303 | 276 log2c("(new connection $client)"); |
277 | |
278 $client->sysread(my $buf, 24) == 24 or return; # preface | |
279 | |
280 $c = Test::Nginx::HTTP2->new(1, socket => $client, | |
281 pure => 1, preface => "") or return; | |
282 } | |
283 | |
284 my $frames = $c->read(all => [{ fin => 4 }]); | |
285 | |
286 if (!$extra{reuse}) { | |
287 $c->h2_settings(0); | |
288 $c->h2_settings(1); | |
289 } | |
290 | |
291 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
292 $sid = $frame->{sid}; | |
293 return $frames; | |
294 }; | |
1725
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
295 $f->{data_len} = sub { |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
296 my ($body, $len) = @_; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
297 $s->h2_body($body) if defined $body; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
298 return $c->read(all => [{ sid => $sid, length => $len }]); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
299 }; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
300 $f->{update} = sub { |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
301 $c->h2_window(shift); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
302 }; |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
303 $f->{update_sid} = sub { |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
304 $c->h2_window(shift, $sid); |
f4c79ee52d8f
Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1645
diff
changeset
|
305 }; |
1303 | 306 $f->{data} = sub { |
307 my ($body, %extra) = @_; | |
308 $s->h2_body($body, { %extra }); | |
309 return $c->read(all => [{ sid => $sid, | |
310 length => length($body) }]); | |
311 }; | |
312 $f->{http_end} = sub { | |
313 $c->new_stream({ body_more => 1, headers => [ | |
314 { name => ':status', value => '200', mode => 0 }, | |
315 { name => 'content-type', value => 'application/grpc', | |
316 mode => 1, huff => 1 }, | |
317 ]}, $sid); | |
318 $c->h2_body('Hello world', { body_more => 1 }); | |
319 $c->new_stream({ headers => [ | |
320 { name => 'grpc-status', value => '0', | |
321 mode => 2, huff => 1 }, | |
322 { name => 'grpc-message', value => '', | |
323 mode => 2, huff => 1 }, | |
324 ]}, $sid); | |
325 | |
326 return $s->read(all => [{ fin => 1 }]); | |
327 }; | |
328 return $f; | |
329 } | |
330 | |
331 sub log2i { Test::Nginx::log_core('|| <<', @_); } | |
332 sub log2o { Test::Nginx::log_core('|| >>', @_); } | |
333 sub log2c { Test::Nginx::log_core('||', @_); } | |
334 | |
335 ############################################################################### |