Mercurial > hg > nginx-tests
annotate http_host.t @ 1021:ebdf239722b9
Tests: relaxed proxy_cache_lock.t nolock tests to fix on Solaris.
Assumed that the order of responses being arrived in nolock case may be ignored.
An important part of such case is that the only last response should be cached.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 02 Sep 2016 12:17:35 +0300 |
parents | 882267679006 |
children | 9d579fc770a6 |
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 | |
56 is(http_host_header('www.abcd-ef.g02.xyz'), 'www.abcd-ef.g02.xyz', | |
57 'domain w/o port (host header)'); | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
58 is(http_host_header('abcd-ef.g02.xyz:' . port(8080)), 'abcd-ef.g02.xyz', |
183 | 59 'domain w/port (host header)'); |
60 | |
61 is(http_absolute_path('abcd-ef.g02.xyz'), 'abcd-ef.g02.xyz', | |
62 'domain w/o port (absolute request)'); | |
63 is(http_absolute_path('www.abcd-ef.g02.xyz:10'), 'www.abcd-ef.g02.xyz', | |
64 'domain w/port (absolute request)'); | |
65 | |
66 | |
67 is(http_host_header('www.abcd-ef.g02.xyz.'), 'www.abcd-ef.g02.xyz', | |
68 'domain w/ ending dot w/o port (host header)'); | |
69 | |
70 is(http_host_header('abcd-ef.g02.xyz.:88'), 'abcd-ef.g02.xyz', | |
71 'domain w/ ending dot w/port (host header)'); | |
72 | |
73 is(http_absolute_path('www.abcd-ef.g02.xyz.'), 'www.abcd-ef.g02.xyz', | |
74 'domain w/ ending dot w/o port (absolute request)'); | |
75 is(http_absolute_path('abcd-ef.g02.xyz.:2'), 'abcd-ef.g02.xyz', | |
76 'domain w/ ending dot w/port (absolute request)'); | |
77 | |
78 | |
79 is(http_absolute_path('AbC-d93.0.34ZhGt-s.nk.Ru'), 'abc-d93.0.34zhgt-s.nk.ru', | |
80 'mixed case domain w/o port (absolute request)'); | |
81 is(http_host_header('AbC-d93.0.34ZhGt-s.nk.Ru:88'), 'abc-d93.0.34zhgt-s.nk.ru', | |
82 'mixed case domain w/port (host header)'); | |
83 | |
84 | |
85 is(http_host_header('123.40.56.78'), '123.40.56.78', | |
86 'ipv4 w/o port (host header)'); | |
87 is(http_host_header('123.49.0.78:987'), '123.49.0.78', | |
88 'ipv4 w/port (host header)'); | |
89 | |
90 is(http_absolute_path('123.49.0.78'), '123.49.0.78', | |
91 'ipv4 w/o port (absolute request)'); | |
92 is(http_absolute_path('123.40.56.78:123'), '123.40.56.78', | |
93 'ipv4 w/port (absolute request)'); | |
94 | |
95 is(http_host_header('[abcd::ef98:0:7654:321]'), '[abcd::ef98:0:7654:321]', | |
96 'ipv6 literal w/o port (host header)'); | |
97 is(http_host_header('[abcd::ef98:0:7654:321]:80'), '[abcd::ef98:0:7654:321]', | |
98 'ipv6 literal w/port (host header)'); | |
212 | 99 |
183 | 100 is(http_absolute_path('[abcd::ef98:0:7654:321]'), '[abcd::ef98:0:7654:321]', |
101 'ipv6 literal w/o port (absolute request)'); | |
102 is(http_absolute_path('[abcd::ef98:0:7654:321]:5'), '[abcd::ef98:0:7654:321]', | |
103 'ipv6 literal w/port (absolute request)'); | |
104 | |
105 is(http_host_header('[::ffff:12.30.67.89]'), '[::ffff:12.30.67.89]', | |
106 'ipv4-mapped ipv6 w/o port (host header)'); | |
107 is(http_host_header('[::123.45.67.89]:4321'), '[::123.45.67.89]', | |
108 'ipv4-mapped ipv6 w/port (host header)'); | |
109 | |
110 is(http_absolute_path('[::123.45.67.89]'), '[::123.45.67.89]', | |
111 'ipv4-mapped ipv6 w/o port (absolute request)'); | |
112 is(http_absolute_path('[::ffff:12.30.67.89]:4321'), '[::ffff:12.30.67.89]', | |
113 'ipv4-mapped ipv6 w/port (absolute request)'); | |
114 | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
115 like(http_host_header('example.com/\:552', 1), qr/ 400 /, |
183 | 116 'domain w/ path separators (host header)'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
117 like(http_absolute_path('\e/xample.com', 1), qr/ 400 /, |
183 | 118 'domain w/ path separators (absolute request)'); |
119 | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
120 like(http_host_header('..examp-LE.com', 1), qr/ 400 /, |
183 | 121 'domain w/ double dot (host header)'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
122 like(http_absolute_path('com.exa-m.45..:', 1), qr/ 400 /, |
183 | 123 'domain w/ double dot (absolute request)'); |
124 | |
125 | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
126 like(http_host_header('[abcd::e\f98:0/:7654:321]', 1), qr/ 400 /, |
183 | 127 '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
|
128 like(http_absolute_path('[abcd\::ef98:0:7654:321/]:12', 1), qr/ 400 /, |
183 | 129 'ipv6 literal w/ path separators (absolute request)'); |
130 | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
131 like(http_host_header('[abcd::ef98:0:7654:321]..:98', 1), qr/ 400 /, |
183 | 132 '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
|
133 like(http_absolute_path('[ab..cd::ef98:0:7654:321]', 1), qr/ 400 /, |
183 | 134 'ipv6 literal w/ double dot (absolute request)'); |
135 | |
136 | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
224
diff
changeset
|
137 like(http_host_header('[abcd::ef98:0:7654:321]..:98', 1), qr/ 400 /, |
183 | 138 '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
|
139 like(http_absolute_path('[ab..cd::ef98:0:7654:321]', 1), qr/ 400 /, |
183 | 140 'ipv6 literal w/ double dot (absolute request)'); |
141 | |
142 | |
143 # As per RFC 3986, | |
144 # http://tools.ietf.org/html/rfc3986#section-3.2.2 | |
145 # | |
146 # IP-literal = "[" ( IPv6address / IPvFuture ) "]" | |
147 # | |
148 # IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) | |
149 # | |
150 # sub-delims = "!" / "$" / "&" / "'" / "(" / ")" | |
151 # / "*" / "+" / "," / ";" / "=" | |
152 # | |
153 # unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" | |
154 # | |
155 | |
156 is(http_host_header( | |
157 '[v0123456789aBcDeF.!$&\'()*+,;=-._~AbCdEfGhIjKlMnOpQrStUvWxYz' | |
158 . '0123456789:]'), | |
159 '[v0123456789abcdef.!$&\'()*+,;=-._~abcdefghijklmnopqrstuvwxyz' | |
160 . '0123456789:]', | |
161 'IPvFuture all symbols (host header)'); | |
162 | |
163 is(http_absolute_path( | |
164 '[v0123456789aBcDeF.!$&\'()*+,;=-._~AbCdEfGhIjKlMnOpQrStUvWxYz' | |
165 . '0123456789:]'), | |
166 '[v0123456789abcdef.!$&\'()*+,;=-._~abcdefghijklmnopqrstuvwxyz' | |
167 . '0123456789:]', | |
168 'IPvFuture all symbols (absolute request)'); | |
169 | |
170 is(http_host_header('123.40.56.78:9000:80'), '123.40.56.78', | |
171 'double port hack'); | |
172 | |
173 ############################################################################### | |
174 | |
175 sub http_host_header { | |
176 my ($host, $all) = @_; | |
177 my ($r) = http(<<EOF); | |
178 GET / HTTP/1.0 | |
179 Host: $host | |
180 | |
181 EOF | |
182 return ($all ? $r : Test::Nginx::http_content($r)); | |
183 } | |
184 | |
185 sub http_absolute_path { | |
186 my ($host, $all) = @_; | |
187 my ($r) = http(<<EOF); | |
188 GET http://$host/ HTTP/1.0 | |
189 Host: localhost | |
190 | |
191 EOF | |
192 return ($all ? $r : Test::Nginx::http_content($r)); | |
193 } |