Mercurial > hg > nginx-tests
annotate http_host.t @ 1619:436d0ffc2ea3
Tests: correctly shutdown ssl for reproducible session reuse tests.
Previously, session reuse tests in stream_ssl_certificate.t were prone
to testing errors, since the client doesn't write any application data
before closing a connection, which is done so to pass tests on win32.
In this case, the server may happened to get an unexpected eof meaning
that it will abandon that session. This is specific to stream testing
pattern, changes to ssl_certificate.t are applied too for consistency.
This is also specific to SSL_R_UNEXPECTED_EOF_WHILE_READING, which is
implemented in OpenSSL 3.0.0.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 23 Nov 2020 22:46:06 +0000 |
parents | 8659123d2d37 |
children | 5ac6efbe5552 |
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 | |
1551
27237569776f
Tests: additional Transfer-Encoding and Host headers tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1451
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(36); |
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 TODO: { |
27237569776f
Tests: additional Transfer-Encoding and Host headers tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1451
diff
changeset
|
173 local $TODO = 'not yet' unless $t->has_version('1.17.9'); |
27237569776f
Tests: additional Transfer-Encoding and Host headers tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1451
diff
changeset
|
174 |
27237569776f
Tests: additional Transfer-Encoding and Host headers tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1451
diff
changeset
|
175 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
|
176 |
27237569776f
Tests: additional Transfer-Encoding and Host headers tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1451
diff
changeset
|
177 } |
27237569776f
Tests: additional Transfer-Encoding and Host headers tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1451
diff
changeset
|
178 |
183 | 179 ############################################################################### |
180 | |
181 sub http_host_header { | |
182 my ($host, $all) = @_; | |
183 my ($r) = http(<<EOF); | |
184 GET / HTTP/1.0 | |
185 Host: $host | |
186 | |
187 EOF | |
1612
8659123d2d37
Tests: made http_content() exportable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1551
diff
changeset
|
188 return ($all ? $r : http_content($r)); |
183 | 189 } |
190 | |
191 sub http_absolute_path { | |
192 my ($host, $all) = @_; | |
193 my ($r) = http(<<EOF); | |
194 GET http://$host/ HTTP/1.0 | |
195 Host: localhost | |
196 | |
197 EOF | |
1612
8659123d2d37
Tests: made http_content() exportable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1551
diff
changeset
|
198 return ($all ? $r : http_content($r)); |
183 | 199 } |
1451 | 200 |
201 ############################################################################### |