Mercurial > hg > nginx-tests
annotate http_host.t @ 1829:a78c32419f02
Tests: separate SSL session reuse tests.
Instead of being mixed with generic SSL tests, session reuse variants
are now tested in a separate file.
In the generic SSL tests only basic session reuse is now tested,
notably with session tickets enabled and a shared SSL session cache.
This should make it possible to reuse sessions in all cases (except
when it's not supported, such as with LibreSSL with TLSv1.3).
Note that session reuse with tickets implies that $ssl_session_id
is selected by the client and therefore is not available on the
initial connection. Relevant test is modified to handle this.
Further, BoringSSL does not use legacy session ID with TLSv1.3 even
if it is sent by the client. In contrast, OpenSSL always generates
an unique legacy session id, so it is available with TLSv1.3 even if
session resumption does not work (such as with old Net::SSLeay and
IO::Socket::SSL modules).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 23 Mar 2023 19:49:47 +0300 |
parents | c48b2b0b8c2a |
children | 2a0a6035a1af |
rev | line source |
---|---|
183 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 # (C) Valentin Bartenev | |
5 | |
6 # Tests for host parsing in requests. | |
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'; | |
1612
8659123d2d37
Tests: made http_content() exportable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1551
diff
changeset
|
18 use Test::Nginx qw/ :DEFAULT http_content /; |
183 | 19 |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
1716
c48b2b0b8c2a
Tests: added Host header test with control character.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(37); |
183 | 26 |
27 $t->write_file_expand('nginx.conf', <<'EOF'); | |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 http { | |
37 %%TEST_GLOBALS_HTTP%% | |
38 | |
39 server { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
40 listen 127.0.0.1:8080; |
183 | 41 server_name localhost; |
42 | |
43 location / { | |
44 return 200 $host; | |
45 } | |
46 } | |
47 } | |
48 | |
49 EOF | |
50 | |
51 $t->run(); | |
52 | |
53 ############################################################################### | |
54 | |
55 is(http_host_header('www.abcd-ef.g02.xyz'), 'www.abcd-ef.g02.xyz', | |
56 'domain w/o port (host header)'); | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
57 is(http_host_header('abcd-ef.g02.xyz:' . port(8080)), 'abcd-ef.g02.xyz', |
183 | 58 'domain w/port (host header)'); |
59 | |
60 is(http_absolute_path('abcd-ef.g02.xyz'), 'abcd-ef.g02.xyz', | |
61 'domain w/o port (absolute request)'); | |
62 is(http_absolute_path('www.abcd-ef.g02.xyz:10'), 'www.abcd-ef.g02.xyz', | |
63 'domain w/port (absolute request)'); | |
64 | |
65 | |
66 is(http_host_header('www.abcd-ef.g02.xyz.'), 'www.abcd-ef.g02.xyz', | |
67 'domain w/ ending dot w/o port (host header)'); | |
68 | |
69 is(http_host_header('abcd-ef.g02.xyz.:88'), 'abcd-ef.g02.xyz', | |
70 'domain w/ ending dot w/port (host header)'); | |
71 | |
72 is(http_absolute_path('www.abcd-ef.g02.xyz.'), 'www.abcd-ef.g02.xyz', | |
73 'domain w/ ending dot w/o port (absolute request)'); | |
74 is(http_absolute_path('abcd-ef.g02.xyz.:2'), 'abcd-ef.g02.xyz', | |
75 'domain w/ ending dot w/port (absolute request)'); | |
76 | |
77 | |
78 is(http_absolute_path('AbC-d93.0.34ZhGt-s.nk.Ru'), 'abc-d93.0.34zhgt-s.nk.ru', | |
79 'mixed case domain w/o port (absolute request)'); | |
80 is(http_host_header('AbC-d93.0.34ZhGt-s.nk.Ru:88'), 'abc-d93.0.34zhgt-s.nk.ru', | |
81 'mixed case domain w/port (host header)'); | |
82 | |
83 | |
84 is(http_host_header('123.40.56.78'), '123.40.56.78', | |
85 'ipv4 w/o port (host header)'); | |
86 is(http_host_header('123.49.0.78:987'), '123.49.0.78', | |
87 'ipv4 w/port (host header)'); | |
88 | |
89 is(http_absolute_path('123.49.0.78'), '123.49.0.78', | |
90 'ipv4 w/o port (absolute request)'); | |
91 is(http_absolute_path('123.40.56.78:123'), '123.40.56.78', | |
92 'ipv4 w/port (absolute request)'); | |
93 | |
94 is(http_host_header('[abcd::ef98:0:7654:321]'), '[abcd::ef98:0:7654:321]', | |
95 'ipv6 literal w/o port (host header)'); | |
96 is(http_host_header('[abcd::ef98:0:7654:321]:80'), '[abcd::ef98:0:7654:321]', | |
97 'ipv6 literal w/port (host header)'); | |
212 | 98 |
183 | 99 is(http_absolute_path('[abcd::ef98:0:7654:321]'), '[abcd::ef98:0:7654:321]', |
100 'ipv6 literal w/o port (absolute request)'); | |
101 is(http_absolute_path('[abcd::ef98:0:7654:321]:5'), '[abcd::ef98:0:7654:321]', | |
102 'ipv6 literal w/port (absolute request)'); | |
103 | |
104 is(http_host_header('[::ffff:12.30.67.89]'), '[::ffff:12.30.67.89]', | |
105 'ipv4-mapped ipv6 w/o port (host header)'); | |
106 is(http_host_header('[::123.45.67.89]:4321'), '[::123.45.67.89]', | |
107 'ipv4-mapped ipv6 w/port (host header)'); | |
108 | |
109 is(http_absolute_path('[::123.45.67.89]'), '[::123.45.67.89]', | |
110 'ipv4-mapped ipv6 w/o port (absolute request)'); | |
111 is(http_absolute_path('[::ffff:12.30.67.89]:4321'), '[::ffff:12.30.67.89]', | |
112 'ipv4-mapped ipv6 w/port (absolute request)'); | |
113 | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
114 like(http_host_header('example.com/\:552', 1), qr/ 400 /, |
183 | 115 'domain w/ path separators (host header)'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
116 like(http_absolute_path('\e/xample.com', 1), qr/ 400 /, |
183 | 117 'domain w/ path separators (absolute request)'); |
118 | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
119 like(http_host_header('..examp-LE.com', 1), qr/ 400 /, |
183 | 120 'domain w/ double dot (host header)'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
121 like(http_absolute_path('com.exa-m.45..:', 1), qr/ 400 /, |
183 | 122 'domain w/ double dot (absolute request)'); |
123 | |
124 | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
125 like(http_host_header('[abcd::e\f98:0/:7654:321]', 1), qr/ 400 /, |
183 | 126 'ipv6 literal w/ path separators (host header)'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
127 like(http_absolute_path('[abcd\::ef98:0:7654:321/]:12', 1), qr/ 400 /, |
183 | 128 'ipv6 literal w/ path separators (absolute request)'); |
129 | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
130 like(http_host_header('[abcd::ef98:0:7654:321]..:98', 1), qr/ 400 /, |
183 | 131 'ipv6 literal w/ double dot (host header)'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
132 like(http_absolute_path('[ab..cd::ef98:0:7654:321]', 1), qr/ 400 /, |
183 | 133 'ipv6 literal w/ double dot (absolute request)'); |
134 | |
135 | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
136 like(http_host_header('[abcd::ef98:0:7654:321]..:98', 1), qr/ 400 /, |
183 | 137 'ipv6 literal w/ double dot (host header)'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
138 like(http_absolute_path('[ab..cd::ef98:0:7654:321]', 1), qr/ 400 /, |
183 | 139 'ipv6 literal w/ double dot (absolute request)'); |
140 | |
141 | |
142 # As per RFC 3986, | |
143 # http://tools.ietf.org/html/rfc3986#section-3.2.2 | |
144 # | |
145 # IP-literal = "[" ( IPv6address / IPvFuture ) "]" | |
146 # | |
147 # IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) | |
148 # | |
149 # sub-delims = "!" / "$" / "&" / "'" / "(" / ")" | |
150 # / "*" / "+" / "," / ";" / "=" | |
151 # | |
152 # unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" | |
153 # | |
154 | |
155 is(http_host_header( | |
156 '[v0123456789aBcDeF.!$&\'()*+,;=-._~AbCdEfGhIjKlMnOpQrStUvWxYz' | |
157 . '0123456789:]'), | |
158 '[v0123456789abcdef.!$&\'()*+,;=-._~abcdefghijklmnopqrstuvwxyz' | |
159 . '0123456789:]', | |
160 'IPvFuture all symbols (host header)'); | |
161 | |
162 is(http_absolute_path( | |
163 '[v0123456789aBcDeF.!$&\'()*+,;=-._~AbCdEfGhIjKlMnOpQrStUvWxYz' | |
164 . '0123456789:]'), | |
165 '[v0123456789abcdef.!$&\'()*+,;=-._~abcdefghijklmnopqrstuvwxyz' | |
166 . '0123456789:]', | |
167 'IPvFuture all symbols (absolute request)'); | |
168 | |
169 is(http_host_header('123.40.56.78:9000:80'), '123.40.56.78', | |
170 'double port hack'); | |
171 | |
1551
27237569776f
Tests: additional Transfer-Encoding and Host headers tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1451
diff
changeset
|
172 like(http_host_header("localhost\nHost: again", 1), qr/ 400 /, 'host repeat'); |
27237569776f
Tests: additional Transfer-Encoding and Host headers tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1451
diff
changeset
|
173 |
1716
c48b2b0b8c2a
Tests: added Host header test with control character.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
174 TODO: { |
c48b2b0b8c2a
Tests: added Host header test with control character.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
175 local $TODO = 'not yet' unless $t->has_version('1.21.1'); |
c48b2b0b8c2a
Tests: added Host header test with control character.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
176 |
c48b2b0b8c2a
Tests: added Host header test with control character.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
177 like(http_host_header("localhost\x02", 1), qr/ 400 /, 'control'); |
c48b2b0b8c2a
Tests: added Host header test with control character.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
178 |
c48b2b0b8c2a
Tests: added Host header test with control character.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
179 } |
c48b2b0b8c2a
Tests: added Host header test with control character.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
180 |
183 | 181 ############################################################################### |
182 | |
183 sub http_host_header { | |
184 my ($host, $all) = @_; | |
185 my ($r) = http(<<EOF); | |
186 GET / HTTP/1.0 | |
187 Host: $host | |
188 | |
189 EOF | |
1612
8659123d2d37
Tests: made http_content() exportable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1551
diff
changeset
|
190 return ($all ? $r : http_content($r)); |
183 | 191 } |
192 | |
193 sub http_absolute_path { | |
194 my ($host, $all) = @_; | |
195 my ($r) = http(<<EOF); | |
196 GET http://$host/ HTTP/1.0 | |
197 Host: localhost | |
198 | |
199 EOF | |
1612
8659123d2d37
Tests: made http_content() exportable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1551
diff
changeset
|
200 return ($all ? $r : http_content($r)); |
183 | 201 } |
1451 | 202 |
203 ############################################################################### |