annotate grpc_ssl.t @ 1303:42577a840a7d

Tests: grpc module tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 20 Mar 2018 18:56:33 +0300
parents
children 6f95c0ed2335
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
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 my $t = Test::Nginx->new()->has(qw/http proxy rewrite http_v2 grpc/)
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 ->has(qw/upstream_keepalive http_ssl/);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 $t->{_configure_args} =~ /OpenSSL ([\d\.]+)/;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 plan(skip_all => 'OpenSSL too old') unless defined $1 and $1 ge '1.0.2';
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 $t->write_file_expand('nginx.conf', <<'EOF');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 %%TEST_GLOBALS%%
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 daemon off;
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 events {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 }
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 http {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 %%TEST_GLOBALS_HTTP%%
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 upstream u {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 server 127.0.0.1:8081;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 keepalive 1;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 server {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 listen 127.0.0.1:8081 http2 ssl;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 server_name localhost;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 ssl_certificate_key localhost.key;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 ssl_certificate localhost.crt;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 http2_max_field_size 128k;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 http2_max_header_size 128k;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 http2_body_preread_size 128k;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 location / {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 grpc_pass 127.0.0.1:8082;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 add_header X-Connection $connection;
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 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 server {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 listen 127.0.0.1:8080 http2;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 server_name localhost;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 http2_max_field_size 128k;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 http2_max_header_size 128k;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 http2_body_preread_size 128k;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 location / {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 grpc_pass grpcs://127.0.0.1:8081;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 if ($arg_if) {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 # nothing
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
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 limit_except GET {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 # nothing
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 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 location /KeepAlive {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 grpc_pass grpcs://u;
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 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 }
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 EOF
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 $t->write_file('openssl.conf', <<EOF);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 [ req ]
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 default_bits = 1024
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 encrypt_key = no
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 distinguished_name = req_distinguished_name
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 [ req_distinguished_name ]
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 EOF
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 my $d = $t->testdir();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 foreach my $name ('localhost') {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 system('openssl req -x509 -new '
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 . "-config $d/openssl.conf -subj /CN=$name/ "
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 . "-out $d/$name.crt -keyout $d/$name.key "
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 . ">>$d/openssl.out 2>&1") == 0
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 or die "Can't create certificate for $name: $!\n";
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 $t->try_run('no grpc')->plan(33);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113
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
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 my $p = port(8082);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 my $f = grpc();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 my $frames = $f->{http_start}('/SayHello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 is($frame->{flags}, 4, 'request - HEADERS flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 ok((my $sid = $frame->{sid}) % 2, 'request - HEADERS sid odd');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 is($frame->{headers}{':method'}, 'POST', 'request - method');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 is($frame->{headers}{':scheme'}, 'http', 'request - scheme');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125 is($frame->{headers}{':path'}, '/SayHello', 'request - path');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 is($frame->{headers}{':authority'}, "127.0.0.1:$p", 'request - authority');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127 is($frame->{headers}{'content-type'}, 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 'request - content type');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 is($frame->{headers}{te}, 'trailers', 'request - te');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 $frames = $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 ($frame) = grep { $_->{type} eq "SETTINGS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133 is($frame->{flags}, 1, 'request - SETTINGS ack');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134 is($frame->{sid}, 0, 'request - SETTINGS sid');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135 is($frame->{length}, 0, 'request - SETTINGS length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138 is($frame->{data}, 'Hello', 'request - DATA');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139 is($frame->{length}, 5, 'request - DATA length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140 is($frame->{flags}, 1, 'request - DATA flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141 is($frame->{sid}, $sid, 'request - DATA sid match');
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 $frames = $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
144 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145 is($frame->{flags}, 4, 'response - HEADERS flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146 is($frame->{sid}, 1, 'response - HEADERS sid');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147 is($frame->{headers}{':status'}, '200', 'response - status');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148 is($frame->{headers}{'content-type'}, 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149 'response - content type');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150 ok($frame->{headers}{server}, 'response - server');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 ok($frame->{headers}{date}, 'response - date');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152 ok(my $c = $frame->{headers}{'x-connection'}, 'response - connection');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155 is($frame->{data}, 'Hello world', 'response - DATA');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156 is($frame->{length}, 11, 'response - DATA length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157 is($frame->{flags}, 0, 'response - DATA flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 is($frame->{sid}, 1, 'response - DATA sid');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
160 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
161 is($frame->{flags}, 5, 'response - trailers flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162 is($frame->{sid}, 1, 'response - trailers sid');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
163 is($frame->{headers}{'grpc-message'}, '', 'response - trailers message');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
164 is($frame->{headers}{'grpc-status'}, '0', 'response - trailers status');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
165
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
166 # next request is on a new backend connection, no sid incremented
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
167
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
168 $f->{http_start}('/SayHello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
169 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
170 $frames = $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172 cmp_ok($frame->{headers}{'x-connection'}, '>', $c, 'response 2 - connection');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
174 # upstream keepalive
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
176 $f->{http_start}('/KeepAlive');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
178 $frames = $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
180 ok($c = $frame->{headers}{'x-connection'}, 'keepalive - connection');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
181
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
182 TODO: {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
183 local $TODO = 'not yet' if $^O eq 'MSWin32';
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
184
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
185 $f->{http_start}('/KeepAlive');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
186 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
187 $frames = $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189 is($frame->{headers}{'x-connection'}, $c, 'keepalive - connection reuse');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
190
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
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
193 ###############################################################################
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195 sub grpc {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196 my ($server, $client, $f, $s, $c, $sid, $uri);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
197
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
198 $server = IO::Socket::INET->new(
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
199 Proto => 'tcp',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
200 LocalHost => '127.0.0.1',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
201 LocalPort => $p,
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
202 Listen => 5,
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
203 Reuse => 1
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
204 )
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
205 or die "Can't create listening socket: $!\n";
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
206
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
207 $f->{http_start} = sub {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
208 ($uri, my %extra) = @_;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
209 my $body_more = 1 if $uri !~ /LongHeader/;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
210 $s = Test::Nginx::HTTP2->new() if !defined $s;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
211 $s->new_stream({ body_more => $body_more, headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
212 { name => ':method', value => 'POST', mode => 0 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
213 { name => ':scheme', value => 'http', mode => 0 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
214 { name => ':path', value => $uri, },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
215 { name => ':authority', value => 'localhost' },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
216 { name => 'content-type', value => 'application/grpc' },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
217 { name => 'te', value => 'trailers', mode => 2 }]});
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
218
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
219 if (!$extra{reuse}) {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
220 $client = $server->accept() or return;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
221 log2c("(new connection $client)");
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
222
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
223 $client->sysread(my $buf, 24) == 24 or return; # preface
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 $c = Test::Nginx::HTTP2->new(1, socket => $client,
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
226 pure => 1, preface => "") or return;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
227 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
228
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
229 my $frames = $c->read(all => [{ fin => 4 }]);
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 if (!$extra{reuse}) {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
232 $c->h2_settings(0);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
233 $c->h2_settings(1);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
234 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
235
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
236 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
237 $sid = $frame->{sid};
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
238 return $frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
239 };
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
240 $f->{data} = sub {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
241 my ($body, %extra) = @_;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
242 $s->h2_body($body, { %extra });
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
243 return $c->read(all => [{ sid => $sid,
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
244 length => length($body) }]);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
245 };
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
246 $f->{http_end} = sub {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
247 $c->new_stream({ body_more => 1, headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
248 { name => ':status', value => '200', mode => 0 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
249 { name => 'content-type', value => 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
250 mode => 1, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
251 ]}, $sid);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
252 $c->h2_body('Hello world', { body_more => 1 });
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
253 $c->new_stream({ headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
254 { name => 'grpc-status', value => '0',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
255 mode => 2, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
256 { name => 'grpc-message', value => '',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
257 mode => 2, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
258 ]}, $sid);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
259
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
260 return $s->read(all => [{ fin => 1 }]);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
261 };
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
262 return $f;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
263 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
264
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
265 sub log2i { Test::Nginx::log_core('|| <<', @_); }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
266 sub log2o { Test::Nginx::log_core('|| >>', @_); }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
267 sub log2c { Test::Nginx::log_core('||', @_); }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
268
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
269 ###############################################################################