annotate grpc_ssl.t @ 1974:b5036a0f9ae0

Tests: improved compatibility when using recent "openssl" app. Starting with OpenSSL 3.0, "openssl genrsa" generates encrypted keys in PKCS#8 format instead of previously used PKCS#1 format. Further, since OpenSSL 1.1.0 such keys are using PBKDF2 hmacWithSHA256. Such keys are not supported by old SSL libraries, notably by OpenSSL before 1.0.0 (OpenSSL 0.9.8 only supports hmacWithSHA1) and by BoringSSL before May 21, 2019 (support for hmacWithSHA256 was added in 302a4dee6c), and trying to load such keys into nginx compiled with an old SSL library results in "unsupported prf" errors. To facilitate testing with old SSL libraries, keys are now generated with "openssl genrsa -traditional" if the flag is available.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 06 May 2024 00:04:26 +0300
parents 236d038dc04a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1303
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for grpc backend with ssl.
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use Test::Nginx::HTTP2;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 ###############################################################################
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDERR; $| = 1;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
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/)
1860
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1748
diff changeset
27 ->has(qw/upstream_keepalive http_ssl openssl:1.0.2/)
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1748
diff changeset
28 ->has_daemon('openssl')
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1748
diff changeset
29 ->write_file_expand('nginx.conf', <<'EOF')->plan(38);
1303
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 %%TEST_GLOBALS%%
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 daemon off;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 events {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 http {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 %%TEST_GLOBALS_HTTP%%
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 upstream u {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 server 127.0.0.1:8081;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 keepalive 1;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 server {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 listen 127.0.0.1:8081 http2 ssl;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 server_name localhost;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 ssl_certificate_key localhost.key;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 ssl_certificate localhost.crt;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52
1313
cc2f17cd9677 Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1312
diff changeset
53 ssl_verify_client optional;
cc2f17cd9677 Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1312
diff changeset
54 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
55
1725
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
56 http2_body_preread_size 128k;
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
57
1303
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 location / {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 grpc_pass 127.0.0.1:8082;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 add_header X-Connection $connection;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 server {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 listen 127.0.0.1:8080 http2;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 server_name localhost;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67
1725
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
68 http2_body_preread_size 128k;
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
69
1303
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 location / {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 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
72 grpc_ssl_name localhost;
cc2f17cd9677 Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1312
diff changeset
73 grpc_ssl_verify on;
cc2f17cd9677 Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1312
diff changeset
74 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
75
cc2f17cd9677 Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1312
diff changeset
76 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
77 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
78 grpc_ssl_password_file password;
1303
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 if ($arg_if) {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 # nothing
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 limit_except GET {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 # nothing
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 location /KeepAlive {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 grpc_pass grpcs://u;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 EOF
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 $t->write_file('openssl.conf', <<EOF);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 [ req ]
1488
dbce8fb5f5f8 Tests: align with OpenSSL security level 2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1415
diff changeset
99 default_bits = 2048
1303
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 encrypt_key = no
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 distinguished_name = req_distinguished_name
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 [ req_distinguished_name ]
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 EOF
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 my $d = $t->testdir();
1974
b5036a0f9ae0 Tests: improved compatibility when using recent "openssl" app.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1900
diff changeset
106 my $tr = `openssl genrsa -help 2>&1` =~ /-traditional/ ? '-traditional' : '';
1303
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 foreach my $name ('localhost') {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 system('openssl req -x509 -new '
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 . "-config $d/openssl.conf -subj /CN=$name/ "
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 . "-out $d/$name.crt -keyout $d/$name.key "
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 . ">>$d/openssl.out 2>&1") == 0
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 or die "Can't create certificate for $name: $!\n";
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115
1313
cc2f17cd9677 Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1312
diff changeset
116 foreach my $name ('client') {
cc2f17cd9677 Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1312
diff changeset
117 system("openssl genrsa -out $d/$name.key -passout pass:$name "
1974
b5036a0f9ae0 Tests: improved compatibility when using recent "openssl" app.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1900
diff changeset
118 . "-aes128 $tr 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
119 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
120 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
121 . "-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
122 . "-out $d/$name.crt "
cc2f17cd9677 Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1312
diff changeset
123 . "-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
124 . ">>$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
125 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
126 }
cc2f17cd9677 Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1312
diff changeset
127
1323
6eb3dd2d4d5a Tests: postponed grpc_ssl.t startup on win32, see eadd24ccfda1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1321
diff changeset
128 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
129
1313
cc2f17cd9677 Tests: very basic grpc ssl verify and passphrase tests added.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1312
diff changeset
130 $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
131
1900
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1860
diff changeset
132 # suppress deprecation warning
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1860
diff changeset
133
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1860
diff changeset
134 open OLDERR, ">&", \*STDERR; close STDERR;
1381
97c8280de681 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1378
diff changeset
135 $t->run();
1900
236d038dc04a Tests: suppress "listen .. http2;" deprecation warnings.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1860
diff changeset
136 open STDERR, ">&", \*OLDERR;
1303
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138 ###############################################################################
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140 my $p = port(8082);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141 my $f = grpc();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143 my $frames = $f->{http_start}('/SayHello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
144 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145 is($frame->{flags}, 4, 'request - HEADERS flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146 ok((my $sid = $frame->{sid}) % 2, 'request - HEADERS sid odd');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147 is($frame->{headers}{':method'}, 'POST', 'request - method');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148 is($frame->{headers}{':scheme'}, 'http', 'request - scheme');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149 is($frame->{headers}{':path'}, '/SayHello', 'request - path');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150 is($frame->{headers}{':authority'}, "127.0.0.1:$p", 'request - authority');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 is($frame->{headers}{'content-type'}, 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152 'request - content type');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153 is($frame->{headers}{te}, 'trailers', 'request - te');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155 $frames = $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156 ($frame) = grep { $_->{type} eq "SETTINGS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157 is($frame->{flags}, 1, 'request - SETTINGS ack');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 is($frame->{sid}, 0, 'request - SETTINGS sid');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159 is($frame->{length}, 0, 'request - SETTINGS length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
160
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
161 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162 is($frame->{data}, 'Hello', 'request - DATA');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
163 is($frame->{length}, 5, 'request - DATA length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
164 is($frame->{flags}, 1, 'request - DATA flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
165 is($frame->{sid}, $sid, 'request - DATA sid match');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
166
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
167 $frames = $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
168 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
169 is($frame->{flags}, 4, 'response - HEADERS flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
170 is($frame->{sid}, 1, 'response - HEADERS sid');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171 is($frame->{headers}{':status'}, '200', 'response - status');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172 is($frame->{headers}{'content-type'}, 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173 'response - content type');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
174 ok($frame->{headers}{server}, 'response - server');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175 ok($frame->{headers}{date}, 'response - date');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
176 ok(my $c = $frame->{headers}{'x-connection'}, 'response - connection');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
178 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179 is($frame->{data}, 'Hello world', 'response - DATA');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
180 is($frame->{length}, 11, 'response - DATA length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
181 is($frame->{flags}, 0, 'response - DATA flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
182 is($frame->{sid}, 1, 'response - DATA sid');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
183
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
184 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
185 is($frame->{flags}, 5, 'response - trailers flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
186 is($frame->{sid}, 1, 'response - trailers sid');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
187 is($frame->{headers}{'grpc-message'}, '', 'response - trailers message');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188 is($frame->{headers}{'grpc-status'}, '0', 'response - trailers status');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
190 # next request is on a new backend connection, no sid incremented
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
191
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
192 $f->{http_start}('/SayHello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
193 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194 $frames = $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196 cmp_ok($frame->{headers}{'x-connection'}, '>', $c, 'response 2 - connection');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
197
1725
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
198 # flow control
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
199
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
200 $f->{http_start}('/FlowControl');
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
201 $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
202 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
203 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
204
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
205 $f->{update}(10);
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
206 $f->{update_sid}(10);
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
207
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
208 $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
209 ($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
210 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
211 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
212
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
213 $f->{update_sid}(10);
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
214 $f->{update}(10);
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
215
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
216 $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
217 ($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
218 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
219 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
220
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
221 $f->{http_end}();
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
222
1303
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
223 # upstream keepalive
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
224
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
225 $f->{http_start}('/KeepAlive');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
226 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
227 $frames = $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
228 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
229 ok($c = $frame->{headers}{'x-connection'}, 'keepalive - connection');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
230
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
231 $f->{http_start}('/KeepAlive');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
232 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
233 $frames = $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
234 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
235 is($frame->{headers}{'x-connection'}, $c, 'keepalive - connection reuse');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
236
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
237 ###############################################################################
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
238
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
239 sub grpc {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
240 my ($server, $client, $f, $s, $c, $sid, $uri);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
241
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
242 $server = IO::Socket::INET->new(
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
243 Proto => 'tcp',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
244 LocalHost => '127.0.0.1',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
245 LocalPort => $p,
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
246 Listen => 5,
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
247 Reuse => 1
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
248 )
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
249 or die "Can't create listening socket: $!\n";
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
250
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
251 $f->{http_start} = sub {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
252 ($uri, my %extra) = @_;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
253 my $body_more = 1 if $uri !~ /LongHeader/;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
254 $s = Test::Nginx::HTTP2->new() if !defined $s;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
255 $s->new_stream({ body_more => $body_more, headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
256 { name => ':method', value => 'POST', mode => 0 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
257 { name => ':scheme', value => 'http', mode => 0 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
258 { name => ':path', value => $uri, },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
259 { name => ':authority', value => 'localhost' },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
260 { name => 'content-type', value => 'application/grpc' },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
261 { name => 'te', value => 'trailers', mode => 2 }]});
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
262
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
263 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
264 eval {
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1313
diff changeset
265 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
266 alarm(5);
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 $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
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 };
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1313
diff changeset
272 alarm(0);
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1313
diff changeset
273 if ($@) {
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1313
diff changeset
274 log_in("died: $@");
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1313
diff changeset
275 return undef;
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1313
diff changeset
276 }
351b95be742b Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1313
diff changeset
277
1303
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
278 log2c("(new connection $client)");
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
279
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
280 $client->sysread(my $buf, 24) == 24 or return; # preface
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
281
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
282 $c = Test::Nginx::HTTP2->new(1, socket => $client,
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
283 pure => 1, preface => "") or return;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
284 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
285
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
286 my $frames = $c->read(all => [{ fin => 4 }]);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
287
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
288 if (!$extra{reuse}) {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
289 $c->h2_settings(0);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
290 $c->h2_settings(1);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
291 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
292
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
293 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
294 $sid = $frame->{sid};
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
295 return $frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
296 };
1725
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
297 $f->{data_len} = sub {
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
298 my ($body, $len) = @_;
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
299 $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
300 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
301 };
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
302 $f->{update} = sub {
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
303 $c->h2_window(shift);
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
304 };
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
305 $f->{update_sid} = sub {
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
306 $c->h2_window(shift, $sid);
f4c79ee52d8f Tests: added grpcs tests with flow control (ticket #2229).
Sergey Kandaurov <pluknet@nginx.com>
parents: 1645
diff changeset
307 };
1303
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
308 $f->{data} = sub {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
309 my ($body, %extra) = @_;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
310 $s->h2_body($body, { %extra });
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
311 return $c->read(all => [{ sid => $sid,
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
312 length => length($body) }]);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
313 };
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
314 $f->{http_end} = sub {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
315 $c->new_stream({ body_more => 1, headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
316 { name => ':status', value => '200', mode => 0 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
317 { name => 'content-type', value => 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
318 mode => 1, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
319 ]}, $sid);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
320 $c->h2_body('Hello world', { body_more => 1 });
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
321 $c->new_stream({ headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
322 { name => 'grpc-status', value => '0',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
323 mode => 2, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
324 { name => 'grpc-message', value => '',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
325 mode => 2, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
326 ]}, $sid);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
327
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
328 return $s->read(all => [{ fin => 1 }]);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
329 };
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
330 return $f;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
331 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
332
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
333 sub log2i { Test::Nginx::log_core('|| <<', @_); }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
334 sub log2o { Test::Nginx::log_core('|| >>', @_); }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
335 sub log2c { Test::Nginx::log_core('||', @_); }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
336
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
337 ###############################################################################