Mercurial > hg > nginx-tests
annotate h2_http2.t @ 1999:15f538440a77 default tip
Tests: adjusted proxy_cache_use_stale.t cache validity.
At least the "s-w-r - updating stale" test sometimes fails on slow
hosts due to "stale-while-revalidate=4" being not enough, so the request
returns with the EXPIRED cache status instead of STALE.
Fix is to use larger "stale-while-revalidate=" times where it is not
significant.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 09 Aug 2024 18:37:25 +0300 |
parents | a095b971fbcc |
children |
rev | line source |
---|---|
1902
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for HTTP/2 protocol, http2 directive. |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::HTTP2; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 socket_ssl_alpn/) |
1987
a095b971fbcc
Tests: removed TODO and try_run() checks for legacy versions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1921
diff
changeset
|
27 ->has_daemon('openssl') |
a095b971fbcc
Tests: removed TODO and try_run() checks for legacy versions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1921
diff
changeset
|
28 ->plan(11); |
1902
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 $t->write_file_expand('nginx.conf', <<'EOF'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 %%TEST_GLOBALS%% |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 daemon off; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 events { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 http { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 %%TEST_GLOBALS_HTTP%% |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 ssl_certificate_key localhost.key; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 ssl_certificate localhost.crt; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 server { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 listen 127.0.0.1:8443 ssl; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 server_name default; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 http2 on; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 server { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 listen 127.0.0.1:8443; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 server_name http2; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 http2 on; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 server { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 listen 127.0.0.1:8443; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 server_name disabled; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 http2 off; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 server { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 listen 127.0.0.1:8444 ssl; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 server_name default; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 server { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 listen 127.0.0.1:8444; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 server_name http2; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 http2 on; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 server { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 listen 127.0.0.1:8080; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 server_name localhost; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 http2 on; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 server { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 listen 127.0.0.1:8081 http2; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 server_name localhost; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 EOF |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 $t->write_file('openssl.conf', <<EOF); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 [ req ] |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 default_bits = 2048 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 encrypt_key = no |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 distinguished_name = req_distinguished_name |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 [ req_distinguished_name ] |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 EOF |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 my $d = $t->testdir(); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 foreach my $name ('localhost') { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 system('openssl req -x509 -new ' |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 . "-config $d/openssl.conf -subj /CN=$name/ " |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 . "-out $d/$name.crt -keyout $d/$name.key " |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 . ">>$d/openssl.out 2>&1") == 0 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 or die "Can't create certificate for $name: $!\n"; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 $t->write_file('index.html', ''); |
1987
a095b971fbcc
Tests: removed TODO and try_run() checks for legacy versions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1921
diff
changeset
|
112 $t->try_run(); |
1902
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 ############################################################################### |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 # make sure HTTP/2 can be disabled selectively on virtual servers |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 ok(get_ssl_socket(8443), 'default to enabled'); |
1907
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
119 |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
120 TODO: { |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
121 local $TODO = 'broken ALPN/SNI order in LibreSSL' |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
122 if $t->has_module('LibreSSL'); |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
123 local $TODO = 'OpenSSL too old' |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
124 if $t->has_module('OpenSSL') |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
125 and not $t->has_feature('openssl:1.1.0'); |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
126 |
1902
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 ok(!get_ssl_socket(8443, 'disabled'), 'sni to disabled'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 |
1907
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
129 } |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
130 |
1920
79ca9ab75310
Tests: fixed h2_http2.t when nginx compiled without ALPN support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1907
diff
changeset
|
131 TODO: { |
79ca9ab75310
Tests: fixed h2_http2.t when nginx compiled without ALPN support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1907
diff
changeset
|
132 local $TODO = 'OpenSSL too old' |
79ca9ab75310
Tests: fixed h2_http2.t when nginx compiled without ALPN support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1907
diff
changeset
|
133 if $t->has_module('OpenSSL') |
79ca9ab75310
Tests: fixed h2_http2.t when nginx compiled without ALPN support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1907
diff
changeset
|
134 and not $t->has_feature('openssl:1.0.2'); |
79ca9ab75310
Tests: fixed h2_http2.t when nginx compiled without ALPN support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1907
diff
changeset
|
135 |
1902
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 is(get_https(8443, 'http2'), 200, 'host to enabled'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 is(get_https(8443, 'disabled', 'http2'), 421, 'host to disabled'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 |
1920
79ca9ab75310
Tests: fixed h2_http2.t when nginx compiled without ALPN support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1907
diff
changeset
|
139 } |
79ca9ab75310
Tests: fixed h2_http2.t when nginx compiled without ALPN support.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1907
diff
changeset
|
140 |
1902
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 # make sure HTTP/2 can be enabled selectively on virtual servers |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 |
1907
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
143 TODO: { |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
144 local $TODO = 'OpenSSL too old' |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
145 if $t->has_module('OpenSSL') |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
146 and not $t->has_feature('openssl:1.1.0'); |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
147 |
1902
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 ok(!get_ssl_socket(8444), 'default to disabled'); |
1907
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
149 |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
150 } |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
151 |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
152 TODO: { |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
153 local $TODO = 'broken ALPN/SNI order in LibreSSL' |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
154 if $t->has_module('LibreSSL'); |
1921
07656d303199
Tests: adjusted TODO for OpenSSL 1.0.2h and up in h2_http2.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1920
diff
changeset
|
155 local $TODO = 'broken ALPN/SNI order in OpenSSL before 1.0.2h' |
1907
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
156 if $t->has_module('OpenSSL') |
1921
07656d303199
Tests: adjusted TODO for OpenSSL 1.0.2h and up in h2_http2.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1920
diff
changeset
|
157 and not $t->has_feature('openssl:1.0.2h'); |
1907
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
158 |
1902
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 is(get_https(8444, 'http2'), 200, 'sni to enabled'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 |
1907
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
161 } |
034c9121b9d1
Tests: added h2_http2.t TODOs for LibreSSL and older OpenSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1902
diff
changeset
|
162 |
1902
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 # http2 detection on plain tcp socket by connection preface |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 like(http_get('/'), qr/200 OK/, 'non-ssl http'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 is(get_http(8080), 200, 'non-ssl http2'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 like(http_get('/', socket => IO::Socket::INET->new('127.0.0.1:' . port(8081))), |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 qr/200 OK/, 'non-ssl http deprecated'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 is(get_http(8081), 200, 'non-ssl http2 deprecated'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 my $sock = http("PRI * HTTP/2.0\r\n\r\n", start => 1); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 select undef, undef, undef, 0.2; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 is(get_http(8080, 'localhost', $sock, "SM\r\n\r\n"), 200, |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 'preface with multiple packets'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 ############################################################################### |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 sub get_http { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 my ($port, $host, $sock, $preface) = @_; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 my $s = Test::Nginx::HTTP2->new(port($port), |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 socket => $sock, preface => $preface); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 my $sid = $s->new_stream({ host => $host }); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 return $frame->{headers}->{':status'}; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 sub get_https { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 my ($port, $host, $sni, $alpn) = @_; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
191 my $sock = get_ssl_socket($port, $sni || $host, $alpn); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
192 return get_http($port, $host, $sock); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
193 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 sub get_ssl_socket { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 my ($port, $sni, $alpn) = @_; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 return http('', PeerAddr => '127.0.0.1:' . port($port), start => 1, |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
198 SSL => 1, |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 SSL_hostname => $sni, |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
200 SSL_alpn_protocols => $alpn || ['h2']); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
201 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
202 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 ############################################################################### |