Mercurial > hg > nginx-tests
comparison h2_ssl.t @ 876:a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Wed, 23 Mar 2016 17:23:08 +0300 |
parents | |
children | 724fcee9a355 |
comparison
equal
deleted
inserted
replaced
875:c380b4b7e2e4 | 876:a6abbfed42c0 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for HTTP/2 protocol 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 | |
26 eval { require IO::Socket::SSL; }; | |
27 plan(skip_all => 'IO::Socket::SSL not installed') if $@; | |
28 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); }; | |
29 plan(skip_all => 'IO::Socket::SSL too old') if $@; | |
30 | |
31 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 rewrite/) | |
32 ->has_daemon('openssl')->plan(8); | |
33 | |
34 $t->write_file_expand('nginx.conf', <<'EOF'); | |
35 | |
36 %%TEST_GLOBALS%% | |
37 | |
38 daemon off; | |
39 | |
40 events { | |
41 } | |
42 | |
43 http { | |
44 %%TEST_GLOBALS_HTTP%% | |
45 | |
46 server { | |
47 listen 127.0.0.1:8080 http2; | |
48 listen 127.0.0.1:8081 http2 ssl; | |
49 server_name localhost; | |
50 | |
51 ssl_certificate_key localhost.key; | |
52 ssl_certificate localhost.crt; | |
53 | |
54 location /h2 { | |
55 return 200 $http2; | |
56 } | |
57 location /sp { | |
58 return 200 $server_protocol; | |
59 } | |
60 location /scheme { | |
61 return 200 $scheme; | |
62 } | |
63 location /https { | |
64 return 200 $https; | |
65 } | |
66 } | |
67 } | |
68 | |
69 EOF | |
70 | |
71 $t->write_file('openssl.conf', <<EOF); | |
72 [ req ] | |
73 default_bits = 2048 | |
74 encrypt_key = no | |
75 distinguished_name = req_distinguished_name | |
76 [ req_distinguished_name ] | |
77 EOF | |
78 | |
79 my $d = $t->testdir(); | |
80 | |
81 foreach my $name ('localhost') { | |
82 system('openssl req -x509 -new ' | |
83 . "-config '$d/openssl.conf' -subj '/CN=$name/' " | |
84 . "-out '$d/$name.crt' -keyout '$d/$name.key' " | |
85 . ">>$d/openssl.out 2>&1") == 0 | |
86 or die "Can't create certificate for $name: $!\n"; | |
87 } | |
88 | |
89 open OLDERR, ">&", \*STDERR; close STDERR; | |
90 $t->run(); | |
91 open STDERR, ">&", \*OLDERR; | |
92 | |
93 ############################################################################### | |
94 | |
95 my ($sess, $sid, $frames, $frame); | |
96 | |
97 # SSL/TLS connection, NPN | |
98 | |
99 SKIP: { | |
100 eval { IO::Socket::SSL->can_npn() or die; }; | |
101 skip 'OpenSSL NPN support required', 1 if $@; | |
102 | |
103 $sess = new_session(8081, SSL => 1, npn => 'h2'); | |
104 $sid = new_stream($sess, { path => '/h2' }); | |
105 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
106 | |
107 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
108 is($frame->{data}, 'h2', 'http variable - npn'); | |
109 | |
110 } | |
111 | |
112 # SSL/TLS connection, ALPN | |
113 | |
114 SKIP: { | |
115 eval { IO::Socket::SSL->can_alpn() or die; }; | |
116 skip 'OpenSSL ALPN support required', 1 if $@; | |
117 | |
118 $sess = new_session(8081, SSL => 1, alpn => 'h2'); | |
119 $sid = new_stream($sess, { path => '/h2' }); | |
120 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
121 | |
122 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
123 is($frame->{data}, 'h2', 'http variable - alpn'); | |
124 | |
125 } | |
126 | |
127 # $server_protocol - SSL/TLS connection, NPN | |
128 | |
129 SKIP: { | |
130 eval { IO::Socket::SSL->can_npn() or die; }; | |
131 skip 'OpenSSL NPN support required', 1 if $@; | |
132 | |
133 $sess = new_session(8081, SSL => 1, npn => 'h2'); | |
134 $sid = new_stream($sess, { path => '/sp' }); | |
135 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
136 | |
137 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
138 is($frame->{data}, 'HTTP/2.0', 'server_protocol variable - npn'); | |
139 | |
140 } | |
141 | |
142 # $server_protocol - SSL/TLS connection, ALPN | |
143 | |
144 SKIP: { | |
145 eval { IO::Socket::SSL->can_alpn() or die; }; | |
146 skip 'OpenSSL ALPN support required', 1 if $@; | |
147 | |
148 $sess = new_session(8081, SSL => 1, alpn => 'h2'); | |
149 $sid = new_stream($sess, { path => '/sp' }); | |
150 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
151 | |
152 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
153 is($frame->{data}, 'HTTP/2.0', 'server_protocol variable - alpn'); | |
154 | |
155 } | |
156 | |
157 # $scheme - SSL/TLS connection, NPN | |
158 | |
159 SKIP: { | |
160 eval { IO::Socket::SSL->can_npn() or die; }; | |
161 skip 'OpenSSL NPN support required', 1 if $@; | |
162 | |
163 $sess = new_session(8081, SSL => 1, npn => 'h2'); | |
164 $sid = new_stream($sess, { path => '/scheme' }); | |
165 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
166 | |
167 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
168 is($frame->{data}, 'https', 'scheme variable - npn'); | |
169 | |
170 } | |
171 | |
172 # $scheme - SSL/TLS connection, ALPN | |
173 | |
174 SKIP: { | |
175 eval { IO::Socket::SSL->can_alpn() or die; }; | |
176 skip 'OpenSSL ALPN support required', 1 if $@; | |
177 | |
178 $sess = new_session(8081, SSL => 1, alpn => 'h2'); | |
179 $sid = new_stream($sess, { path => '/scheme' }); | |
180 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
181 | |
182 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
183 is($frame->{data}, 'https', 'scheme variable - alpn'); | |
184 | |
185 } | |
186 | |
187 # $https - SSL/TLS connection, NPN | |
188 | |
189 SKIP: { | |
190 eval { IO::Socket::SSL->can_npn() or die; }; | |
191 skip 'OpenSSL NPN support required', 1 if $@; | |
192 | |
193 $sess = new_session(8081, SSL => 1, npn => 'h2'); | |
194 $sid = new_stream($sess, { path => '/https' }); | |
195 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
196 | |
197 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
198 is($frame->{data}, 'on', 'https variable - npn'); | |
199 | |
200 } | |
201 | |
202 # $https - SSL/TLS connection, ALPN | |
203 | |
204 SKIP: { | |
205 eval { IO::Socket::SSL->can_alpn() or die; }; | |
206 skip 'OpenSSL ALPN support required', 1 if $@; | |
207 | |
208 $sess = new_session(8081, SSL => 1, alpn => 'h2'); | |
209 $sid = new_stream($sess, { path => '/https' }); | |
210 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
211 | |
212 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
213 is($frame->{data}, 'on', 'https variable - alpn'); | |
214 | |
215 } | |
216 | |
217 ############################################################################### |