comparison h2_ssl_variables.t @ 985:de513b115e68

Tests: renamed some HTTP/2 tests to follow naming convention.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 20 Jul 2016 11:07:20 +0300
parents h2_ssl.t@882267679006
children 45c80276d691
comparison
equal deleted inserted replaced
984:892737e9fd31 985:de513b115e68
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 ssl;
48 server_name localhost;
49
50 ssl_certificate_key localhost.key;
51 ssl_certificate localhost.crt;
52
53 location /h2 {
54 return 200 $http2;
55 }
56 location /sp {
57 return 200 $server_protocol;
58 }
59 location /scheme {
60 return 200 $scheme;
61 }
62 location /https {
63 return 200 $https;
64 }
65 }
66 }
67
68 EOF
69
70 $t->write_file('openssl.conf', <<EOF);
71 [ req ]
72 default_bits = 2048
73 encrypt_key = no
74 distinguished_name = req_distinguished_name
75 [ req_distinguished_name ]
76 EOF
77
78 my $d = $t->testdir();
79
80 foreach my $name ('localhost') {
81 system('openssl req -x509 -new '
82 . "-config '$d/openssl.conf' -subj '/CN=$name/' "
83 . "-out '$d/$name.crt' -keyout '$d/$name.key' "
84 . ">>$d/openssl.out 2>&1") == 0
85 or die "Can't create certificate for $name: $!\n";
86 }
87
88 open OLDERR, ">&", \*STDERR; close STDERR;
89 $t->run();
90 open STDERR, ">&", \*OLDERR;
91
92 ###############################################################################
93
94 my ($s, $sid, $frames, $frame);
95
96 # SSL/TLS connection, NPN
97
98 SKIP: {
99 eval { IO::Socket::SSL->can_npn() or die; };
100 skip 'OpenSSL NPN support required', 1 if $@;
101
102 $s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, npn => 'h2');
103 $sid = $s->new_stream({ path => '/h2' });
104 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
105
106 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
107 is($frame->{data}, 'h2', 'http variable - npn');
108
109 }
110
111 # SSL/TLS connection, ALPN
112
113 SKIP: {
114 eval { IO::Socket::SSL->can_alpn() or die; };
115 skip 'OpenSSL ALPN support required', 1 if $@;
116
117 $s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, alpn => 'h2');
118 $sid = $s->new_stream({ path => '/h2' });
119 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
120
121 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
122 is($frame->{data}, 'h2', 'http variable - alpn');
123
124 }
125
126 # $server_protocol - SSL/TLS connection, NPN
127
128 SKIP: {
129 eval { IO::Socket::SSL->can_npn() or die; };
130 skip 'OpenSSL NPN support required', 1 if $@;
131
132 $s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, npn => 'h2');
133 $sid = $s->new_stream({ path => '/sp' });
134 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
135
136 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
137 is($frame->{data}, 'HTTP/2.0', 'server_protocol variable - npn');
138
139 }
140
141 # $server_protocol - SSL/TLS connection, ALPN
142
143 SKIP: {
144 eval { IO::Socket::SSL->can_alpn() or die; };
145 skip 'OpenSSL ALPN support required', 1 if $@;
146
147 $s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, alpn => 'h2');
148 $sid = $s->new_stream({ path => '/sp' });
149 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
150
151 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
152 is($frame->{data}, 'HTTP/2.0', 'server_protocol variable - alpn');
153
154 }
155
156 # $scheme - SSL/TLS connection, NPN
157
158 SKIP: {
159 eval { IO::Socket::SSL->can_npn() or die; };
160 skip 'OpenSSL NPN support required', 1 if $@;
161
162 $s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, npn => 'h2');
163 $sid = $s->new_stream({ path => '/scheme' });
164 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
165
166 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
167 is($frame->{data}, 'https', 'scheme variable - npn');
168
169 }
170
171 # $scheme - SSL/TLS connection, ALPN
172
173 SKIP: {
174 eval { IO::Socket::SSL->can_alpn() or die; };
175 skip 'OpenSSL ALPN support required', 1 if $@;
176
177 $s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, alpn => 'h2');
178 $sid = $s->new_stream({ path => '/scheme' });
179 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
180
181 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
182 is($frame->{data}, 'https', 'scheme variable - alpn');
183
184 }
185
186 # $https - SSL/TLS connection, NPN
187
188 SKIP: {
189 eval { IO::Socket::SSL->can_npn() or die; };
190 skip 'OpenSSL NPN support required', 1 if $@;
191
192 $s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, npn => 'h2');
193 $sid = $s->new_stream({ path => '/https' });
194 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
195
196 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
197 is($frame->{data}, 'on', 'https variable - npn');
198
199 }
200
201 # $https - SSL/TLS connection, ALPN
202
203 SKIP: {
204 eval { IO::Socket::SSL->can_alpn() or die; };
205 skip 'OpenSSL ALPN support required', 1 if $@;
206
207 $s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, alpn => 'h2');
208 $sid = $s->new_stream({ path => '/https' });
209 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
210
211 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
212 is($frame->{data}, 'on', 'https variable - alpn');
213
214 }
215
216 ###############################################################################