Mercurial > hg > nginx-tests
annotate http_host.t @ 1689:dbd19195df8a
Tests: adjusted mail_smtp.t "long pipelined" TODO.
Prior to fixed reading with fully filled buffer in 2851e4c7de03 (1.21.0),
test for long pipelined commands leads to connection close by nginx, which
can result in RST and no response seen by the client, notably on win32.
While here, cleaned up permitted smtp_auth methods in that particular server.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 24 May 2021 22:09:54 +0300 |
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 ############################################################################### |