Mercurial > hg > nginx-tests
annotate http_host.t @ 1542:451e787aad76
Tests: reworked libgd version detection.
The "libgd-config" binary is deprecated in recent versions and may not exist
or have unexpected output. More, it may not present within older versions,
as well, if installed separately, which previously broke test assumptions.
The fix is change the fallback to skip tests. In addition, recent Perl GD
module (2.57) started to export libgd version, which is now also consulted.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 13 Jan 2020 18:15:35 +0300 |
parents | 9d579fc770a6 |
children | 27237569776f |
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'; | |
18 use Test::Nginx; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
25 my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(35); | |
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 | |
172 ############################################################################### | |
173 | |
174 sub http_host_header { | |
175 my ($host, $all) = @_; | |
176 my ($r) = http(<<EOF); | |
177 GET / HTTP/1.0 | |
178 Host: $host | |
179 | |
180 EOF | |
181 return ($all ? $r : Test::Nginx::http_content($r)); | |
182 } | |
183 | |
184 sub http_absolute_path { | |
185 my ($host, $all) = @_; | |
186 my ($r) = http(<<EOF); | |
187 GET http://$host/ HTTP/1.0 | |
188 Host: localhost | |
189 | |
190 EOF | |
191 return ($all ? $r : Test::Nginx::http_content($r)); | |
192 } | |
1451 | 193 |
194 ############################################################################### |