Mercurial > hg > nginx-tests
annotate http_host.t @ 1971:ab45ee8011df
Tests: guarded session ticket tests for old OpenSSL versions.
Much like SNI support, TLS session tickets are available starting with
OpenSSL 0.9.8f if TLS extensions support is explicitly configured, and
enabled by default since 0.9.8j. As such, SNI availability is checked
to ensure TLS extensions support is compiled in.
Additionally, the ssl_session_ticket_key.t tests for automatic ticket key
rotation, which uses session ticket key callback, as introduced in
OpenSSL 0.9.8h.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 06 May 2024 00:03:16 +0300 |
parents | 2a0a6035a1af |
children |
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'); |
1716
c48b2b0b8c2a
Tests: added Host header test with control character.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
173 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
|
174 |
183 | 175 ############################################################################### |
176 | |
177 sub http_host_header { | |
178 my ($host, $all) = @_; | |
179 my ($r) = http(<<EOF); | |
180 GET / HTTP/1.0 | |
181 Host: $host | |
182 | |
183 EOF | |
1612
8659123d2d37
Tests: made http_content() exportable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1551
diff
changeset
|
184 return ($all ? $r : http_content($r)); |
183 | 185 } |
186 | |
187 sub http_absolute_path { | |
188 my ($host, $all) = @_; | |
189 my ($r) = http(<<EOF); | |
190 GET http://$host/ HTTP/1.0 | |
191 Host: localhost | |
192 | |
193 EOF | |
1612
8659123d2d37
Tests: made http_content() exportable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1551
diff
changeset
|
194 return ($all ? $r : http_content($r)); |
183 | 195 } |
1451 | 196 |
197 ############################################################################### |