Annotation of embedaddon/lighttpd/tests/core-request.t, revision 1.1.1.1
1.1 misho 1: #!/usr/bin/env perl
2: BEGIN {
3: # add current source dir to the include-path
4: # we need this for make distcheck
5: (my $srcdir = $0) =~ s,/[^/]+$,/,;
6: unshift @INC, $srcdir;
7: }
8:
9: use strict;
10: use IO::Socket;
11: use Test::More tests => 36;
12: use LightyTest;
13:
14: my $tf = LightyTest->new();
15: my $t;
16:
17: ok($tf->start_proc == 0, "Starting lighttpd") or die();
18:
19: ## Low-Level Request-Header Parsing - URI
20:
21: $t->{REQUEST} = ( <<EOF
22: GET /index%2ehtml HTTP/1.0
23: EOF
24: );
25: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
26: ok($tf->handle_http($t) == 0, 'URL-encoding');
27:
28: $t->{REQUEST} = ( <<EOF
29: GET /index.html%00 HTTP/1.0
30: EOF
31: );
32: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
33: ok($tf->handle_http($t) == 0, 'URL-encoding, %00');
34:
35:
36:
37: ## Low-Level Request-Header Parsing - Host
38:
39: $t->{REQUEST} = ( <<EOF
40: GET / HTTP/1.0
41: Host: www.example.org
42: EOF
43: );
44: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
45: ok($tf->handle_http($t) == 0, 'hostname');
46:
47: $t->{REQUEST} = ( <<EOF
48: GET / HTTP/1.0
49: Host: 127.0.0.1
50: EOF
51: );
52: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
53: ok($tf->handle_http($t) == 0, 'IPv4 address');
54:
55: $t->{REQUEST} = ( <<EOF
56: GET / HTTP/1.0
57: Host: [::1]
58: EOF
59: );
60: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
61: ok($tf->handle_http($t) == 0, 'IPv6 address');
62:
63: $t->{REQUEST} = ( <<EOF
64: GET / HTTP/1.0
65: Host: www.example.org:80
66: EOF
67: );
68: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
69: ok($tf->handle_http($t) == 0, 'hostname + port');
70:
71: $t->{REQUEST} = ( <<EOF
72: GET / HTTP/1.0
73: Host: 127.0.0.1:80
74: EOF
75: );
76: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
77: ok($tf->handle_http($t) == 0, 'IPv4 address + port');
78:
79: $t->{REQUEST} = ( <<EOF
80: GET / HTTP/1.0
81: Host: [::1]:80
82: EOF
83: );
84: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
85: ok($tf->handle_http($t) == 0, 'IPv6 address + port');
86:
87: $t->{REQUEST} = ( <<EOF
88: GET / HTTP/1.0
89: Host: ../123.org
90: EOF
91: );
92: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
93: ok($tf->handle_http($t) == 0, 'directory traversal');
94:
95: $t->{REQUEST} = ( <<EOF
96: GET / HTTP/1.0
97: Host: .jsdh.sfdg.sdfg.
98: EOF
99: );
100: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
101: ok($tf->handle_http($t) == 0, 'leading and trailing dot');
102:
103: $t->{REQUEST} = ( <<EOF
104: GET / HTTP/1.0
105: Host: jsdh.sfdg.sdfg.
106: EOF
107: );
108: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
109: ok($tf->handle_http($t) == 0, 'trailing dot is ok');
110:
111: $t->{REQUEST} = ( <<EOF
112: GET / HTTP/1.0
113: Host: .jsdh.sfdg.sdfg
114: EOF
115: );
116: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
117: ok($tf->handle_http($t) == 0, 'leading dot');
118:
119:
120: $t->{REQUEST} = ( <<EOF
121: GET / HTTP/1.0
122: Host: jsdh..sfdg.sdfg
123: EOF
124: );
125: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
126: ok($tf->handle_http($t) == 0, 'two dots');
127:
128: $t->{REQUEST} = ( <<EOF
129: GET / HTTP/1.0
130: Host: jsdh.sfdg.sdfg:asd
131: EOF
132: );
133: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
134: ok($tf->handle_http($t) == 0, 'broken port-number');
135:
136: $t->{REQUEST} = ( <<EOF
137: GET / HTTP/1.0
138: Host: jsdh.sfdg.sdfg:-1
139: EOF
140: );
141: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
142: ok($tf->handle_http($t) == 0, 'negative port-number');
143:
144:
145: $t->{REQUEST} = ( <<EOF
146: GET / HTTP/1.0
147: Host: :80
148: EOF
149: );
150: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
151: ok($tf->handle_http($t) == 0, 'port given but host missing');
152:
153: $t->{REQUEST} = ( <<EOF
154: GET / HTTP/1.0
155: Host: .jsdh.sfdg.:sdfg.
156: EOF
157: );
158: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
159: ok($tf->handle_http($t) == 0, 'port and host are broken');
160:
161: $t->{REQUEST} = ( <<EOF
162: GET / HTTP/1.0
163: Host: a.b-c.d123
164: EOF
165: );
166: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
167: ok($tf->handle_http($t) == 0, 'allowed characters in host-name');
168:
169: $t->{REQUEST} = ( <<EOF
170: GET / HTTP/1.0
171: Host: -a.c
172: EOF
173: );
174: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
175: ok($tf->handle_http($t) == 0, 'leading dash');
176:
177: $t->{REQUEST} = ( <<EOF
178: GET / HTTP/1.0
179: Host: .
180: EOF
181: );
182: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
183: ok($tf->handle_http($t) == 0, 'dot only');
184:
185: $t->{REQUEST} = ( <<EOF
186: GET / HTTP/1.0
187: Host: a192.168.2.10:1234
188: EOF
189: );
190: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
191: ok($tf->handle_http($t) == 0, 'broken IPv4 address - non-digit');
192:
193: $t->{REQUEST} = ( <<EOF
194: GET / HTTP/1.0
195: Host: 192.168.2:1234
196: EOF
197: );
198: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
199: ok($tf->handle_http($t) == 0, 'broken IPv4 address - too short');
200:
201:
202:
203: ## Low-Level Request-Header Parsing - Content-Length
204:
205:
206: $t->{REQUEST} = ( <<EOF
207: GET /index.html HTTP/1.0
208: Content-Length: -2
209: EOF
210: );
211: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
212: ok($tf->handle_http($t) == 0, 'negative Content-Length');
213:
214: $t->{REQUEST} = ( <<EOF
215: POST /12345.txt HTTP/1.0
216: Host: 123.example.org
217: Content-Length: 2147483648
218: EOF
219: );
220: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 413 } ];
221: ok($tf->handle_http($t) == 0, 'Content-Length > max-request-size');
222:
223: $t->{REQUEST} = ( <<EOF
224: POST /12345.txt HTTP/1.0
225: Host: 123.example.org
226: Content-Length:
227: EOF
228: );
229: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 411 } ];
230: ok($tf->handle_http($t) == 0, 'Content-Length is empty');
231:
232: print "\nLow-Level Request-Header Parsing - HTTP/1.1\n";
233: $t->{REQUEST} = ( <<EOF
234: GET / HTTP/1.1
235: EOF
236: );
237: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 400 } ];
238: ok($tf->handle_http($t) == 0, 'Host missing');
239:
240: print "\nContent-Type\n";
241: $t->{REQUEST} = ( <<EOF
242: GET /image.jpg HTTP/1.0
243: EOF
244: );
245: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Type' => 'image/jpeg' } ];
246: ok($tf->handle_http($t) == 0, 'Content-Type - image/jpeg');
247:
248: $t->{REQUEST} = ( <<EOF
249: GET /image.JPG HTTP/1.0
250: EOF
251: );
252: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Type' => 'image/jpeg' } ];
253: ok($tf->handle_http($t) == 0, 'Content-Type - image/jpeg (upper case)');
254:
255: $t->{REQUEST} = ( <<EOF
256: GET /a HTTP/1.0
257: EOF
258: );
259: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Type' => 'application/octet-stream' } ];
260: ok($tf->handle_http($t) == 0, 'Content-Type - unknown');
261:
262: $t->{REQUEST} = ( <<EOF
263: GET HTTP/1.0
264: EOF
265: );
266: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
267: ok($tf->handle_http($t) == 0, 'empty request-URI');
268:
269: $t->{REQUEST} = ( <<EOF
270: GET /Foo.txt HTTP/1.0
271: EOF
272: );
273: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
274: ok($tf->handle_http($t) == 0, 'uppercase filenames');
275:
276: $t->{REQUEST} = ( <<EOF
277: GET / HTTP/1.0
278: Location: foo
279: Location: foobar
280: baz
281: EOF
282: );
283: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
284: ok($tf->handle_http($t) == 0, '#1232 - duplicate headers with line-wrapping');
285:
286: $t->{REQUEST} = ( <<EOF
287: GET / HTTP/1.0
288: Location:
289: Location: foobar
290: baz
291: EOF
292: );
293: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
294: ok($tf->handle_http($t) == 0, '#1232 - duplicate headers with line-wrapping - test 2');
295:
296: $t->{REQUEST} = ( <<EOF
297: GET / HTTP/1.0
298: A:
299: Location: foobar
300: baz
301: EOF
302: );
303: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
304: ok($tf->handle_http($t) == 0, '#1232 - duplicate headers with line-wrapping - test 3');
305:
306:
307:
308:
309: ok($tf->stop_proc == 0, "Stopping lighttpd");
310:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>