Annotation of embedaddon/lighttpd/tests/mod-fastcgi.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 Test::More tests => 58;
11: use LightyTest;
12:
13: my $tf = LightyTest->new();
14:
15: my $t;
16: my $php_child = -1;
17:
18: my $phpbin = (defined $ENV{'PHP'} ? $ENV{'PHP'} : '/usr/bin/php-cgi');
19: $ENV{'PHP'} = $phpbin;
20:
21: SKIP: {
22: skip "PHP already running on port 1026", 1 if $tf->listening_on(1026);
23: skip "no php binary found", 1 unless -x $phpbin;
24: ok(-1 != ($php_child = $tf->spawnfcgi($phpbin, 1026)), "Spawning php");
25: }
26:
27: SKIP: {
28: skip "no PHP running on port 1026", 35 unless $tf->listening_on(1026);
29:
30: ok($tf->start_proc == 0, "Starting lighttpd") or goto cleanup;
31:
32: $t->{REQUEST} = ( <<EOF
33: GET /phpinfo.php HTTP/1.0
34: Host: www.example.org
35: EOF
36: );
37: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
38: ok($tf->handle_http($t) == 0, 'valid request');
39:
40: $t->{REQUEST} = ( <<EOF
41: GET /phpinfofoobar.php HTTP/1.0
42: Host: www.example.org
43: EOF
44: );
45: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
46: ok($tf->handle_http($t) == 0, 'file not found');
47:
48: $t->{REQUEST} = ( <<EOF
49: GET /go/ HTTP/1.0
50: Host: www.example.org
51: EOF
52: );
53: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
54: ok($tf->handle_http($t) == 0, 'index-file handling');
55:
56: $t->{REQUEST} = ( <<EOF
57: GET /redirect.php HTTP/1.0
58: Host: www.example.org
59: EOF
60: );
61: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => 'http://www.example.org:2048/' } ];
62: ok($tf->handle_http($t) == 0, 'Status + Location via FastCGI');
63:
64: $t->{REQUEST} = ( <<EOF
65: GET /redirect.php/ HTTP/1.0
66: Host: www.example.org
67: EOF
68: );
69: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => 'http://www.example.org:2048/' } ];
70: ok($tf->handle_http($t) == 0, 'Trailing slash as path-info (#1989: workaround broken operating systems)');
71:
72: $t->{REQUEST} = ( <<EOF
73: GET /get-server-env.php?env=PHP_SELF HTTP/1.0
74: Host: www.example.org
75: EOF
76: );
77: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
78: ok($tf->handle_http($t) == 0, '$_SERVER["PHP_SELF"]');
79:
80: $t->{REQUEST} = ( <<EOF
81: GET /get-server-env.php/foo?env=SCRIPT_NAME HTTP/1.0
82: Host: www.example.org
83: EOF
84: );
85: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/get-server-env.php' } ];
86: ok($tf->handle_http($t) == 0, '$_SERVER["SCRIPT_NAME"]');
87:
88: $t->{REQUEST} = ( <<EOF
89: GET /get-server-env.php/foo?env=PATH_INFO HTTP/1.0
90: Host: www.example.org
91: EOF
92: );
93: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo' } ];
94: ok($tf->handle_http($t) == 0, '$_SERVER["PATH_INFO"]');
95:
96: $t->{REQUEST} = ( <<EOF
97: GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
98: Host: www.example.org
99: EOF
100: );
101: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
102: ok($tf->handle_http($t) == 0, 'SERVER_NAME');
103:
104: $t->{REQUEST} = ( <<EOF
105: GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
106: Host: foo.example.org
107: EOF
108: );
109: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
110: ok($tf->handle_http($t) == 0, 'SERVER_NAME');
111:
112: $t->{REQUEST} = ( <<EOF
113: GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
114: Host: vvv.example.org
115: EOF
116: );
117: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
118: ok($tf->handle_http($t) == 0, 'SERVER_NAME');
119:
120: $t->{REQUEST} = ( <<EOF
121: GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
122: Host: zzz.example.org
123: EOF
124: );
125: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
126: ok($tf->handle_http($t) == 0, 'SERVER_NAME');
127:
128: $t->{REQUEST} = ( <<EOF
129: GET /cgi.php/abc HTTP/1.0
130: EOF
131: );
132: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
133: ok($tf->handle_http($t) == 0, 'PATHINFO');
134:
135: $t->{REQUEST} = ( <<EOF
136: GET /cgi.php%20%20%20 HTTP/1.0
137: EOF
138: );
139: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
140: ok($tf->handle_http($t) == 0, 'No source retrieval');
141:
142: $t->{REQUEST} = ( <<EOF
143: GET /www/abc/def HTTP/1.0
144: EOF
145: );
146: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
147: ok($tf->handle_http($t) == 0, 'PATHINFO on a directory');
148:
149: $t->{REQUEST} = ( <<EOF
150: GET /indexfile/ HTTP/1.0
151: EOF
152: );
153: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/indexfile/index.php' } ];
154: ok($tf->handle_http($t) == 0, 'PHP_SELF + Indexfile, Bug #3');
155:
156: $t->{REQUEST} = ( <<EOF
157: GET /prefix.fcgi?var=SCRIPT_NAME HTTP/1.0
158: EOF
159: );
160: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/prefix.fcgi' } ];
161: ok($tf->handle_http($t) == 0, 'PATH_INFO, check-local off');
162:
163: $t->{REQUEST} = ( <<EOF
164: GET /prefix.fcgi/foo/bar?var=SCRIPT_NAME HTTP/1.0
165: EOF
166: );
167: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/prefix.fcgi' } ];
168: ok($tf->handle_http($t) == 0, 'PATH_INFO, check-local off');
169:
170: $t->{REQUEST} = ( <<EOF
171: GET /prefix.fcgi/foo/bar?var=PATH_INFO HTTP/1.0
172: EOF
173: );
174: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo/bar' } ];
175: ok($tf->handle_http($t) == 0, 'PATH_INFO, check-local off');
176:
177: $t->{REQUEST} = ( <<EOF
178: GET /sendfile.php?range=0- HTTP/1.0
179: EOF
180: );
181: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => 4348 } ];
182: ok($tf->handle_http($t) == 0, 'X-Sendfile2');
183:
184: $t->{REQUEST} = ( <<EOF
185: GET /sendfile.php?range=0-4&range2=5- HTTP/1.0
186: EOF
187: );
188: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => 4348 } ];
189: ok($tf->handle_http($t) == 0, 'X-Sendfile2');
190:
191: $t->{REQUEST} = ( <<EOF
192: GET /get-server-env.php?env=REMOTE_USER HTTP/1.0
193: Host: auth.example.org
194: Authorization: Basic ZGVzOmRlcw==
195: EOF
196: );
197: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'des' } ];
198: ok($tf->handle_http($t) == 0, '$_SERVER["REMOTE_USER"]');
199:
200: $t->{REQUEST} = ( <<EOF
201: GET /get-server-env.php?env=AUTH_TYPE HTTP/1.0
202: Host: auth.example.org
203: Authorization: Basic ZGVzOmRlcw==
204: EOF
205: );
206: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'Basic' } ];
207: ok($tf->handle_http($t) == 0, '$_SERVER["AUTH_TYPE"]');
208:
209:
210: ok($tf->stop_proc == 0, "Stopping lighttpd");
211:
212:
213: $tf->{CONFIGFILE} = 'fastcgi-10.conf';
214: ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or goto cleanup;
215: $t->{REQUEST} = ( <<EOF
216: GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
217: Host: zzz.example.org
218: EOF
219: );
220: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'zzz.example.org' } ];
221: ok($tf->handle_http($t) == 0, 'FastCGI + Host');
222:
223: $t->{REQUEST} = ( <<EOF
224: GET http://zzz.example.org/get-server-env.php?env=SERVER_NAME HTTP/1.0
225: Host: aaa.example.org
226: EOF
227: );
228: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'zzz.example.org' } ];
229: ok($tf->handle_http($t) == 0, 'SERVER_NAME (absolute url in request line)');
230:
231: ok($tf->stop_proc == 0, "Stopping lighttpd");
232:
233: $tf->{CONFIGFILE} = 'bug-06.conf';
234: ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or goto cleanup;
235: $t->{REQUEST} = ( <<EOF
236: GET /indexfile/ HTTP/1.0
237: Host: www.example.org
238: EOF
239: );
240: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/indexfile/index.php' } ];
241: ok($tf->handle_http($t) == 0, 'Bug #6');
242:
243: ok($tf->stop_proc == 0, "Stopping lighttpd");
244:
245: $tf->{CONFIGFILE} = 'bug-12.conf';
246: ok($tf->start_proc == 0, "Starting lighttpd with bug-12.conf") or goto cleanup;
247: $t->{REQUEST} = ( <<EOF
248: POST /indexfile/abc HTTP/1.0
249: Host: www.example.org
250: Content-Length: 0
251: EOF
252: );
253: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => '/indexfile/return-404.php' } ];
254: ok($tf->handle_http($t) == 0, 'Bug #12');
255:
256: ok($tf->stop_proc == 0, "Stopping lighttpd");
257: }
258:
259: SKIP: {
260: skip "PHP not started, cannot stop it", 1 unless $php_child != -1;
261: ok(0 == $tf->endspawnfcgi($php_child), "Stopping php");
262: $php_child = -1;
263: }
264:
265: SKIP: {
266: skip "no fcgi-auth found", 5 unless -x $tf->{BASEDIR}."/tests/fcgi-auth" || -x $tf->{BASEDIR}."/tests/fcgi-auth.exe";
267:
268: $tf->{CONFIGFILE} = 'fastcgi-auth.conf';
269: ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
270: $t->{REQUEST} = ( <<EOF
271: GET /index.html?ok HTTP/1.0
272: Host: www.example.org
273: EOF
274: );
275: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
276: ok($tf->handle_http($t) == 0, 'FastCGI - Auth');
277:
278: $t->{REQUEST} = ( <<EOF
279: GET /index.html?fail HTTP/1.0
280: Host: www.example.org
281: EOF
282: );
283: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
284: ok($tf->handle_http($t) == 0, 'FastCGI - Auth');
285:
286: $t->{REQUEST} = ( <<EOF
287: GET /expire/access.txt?ok HTTP/1.0
288: Host: www.example.org
289: EOF
290: );
291: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
292: ok($tf->handle_http($t) == 0, 'FastCGI - Auth in subdirectory');
293:
294: ok($tf->stop_proc == 0, "Stopping lighttpd");
295: }
296:
297: SKIP: {
298: skip "no php found", 5 unless -x $phpbin;
299: $tf->{CONFIGFILE} = 'fastcgi-13.conf';
300: ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
301: $t->{REQUEST} = ( <<EOF
302: GET /indexfile/index.php HTTP/1.0
303: Host: www.example.org
304: EOF
305: );
306: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
307: ok($tf->handle_http($t) == 0, 'FastCGI + local spawning');
308:
309: $t->{REQUEST} = ( <<EOF
310: HEAD /indexfile/index.php HTTP/1.0
311: Host: www.example.org
312: EOF
313: );
314: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '-Content-Length' => '0' } ];
315: # Of course a valid content-length != 0 would be ok, but we assume for now that such one is not generated.
316: ok($tf->handle_http($t) == 0, 'Check for buggy content length with HEAD');
317:
318: $t->{REQUEST} = ( <<EOF
319: GET /get-env.php?env=MAIL HTTP/1.0
320: Host: www.example.org
321: EOF
322: );
323: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 , 'HTTP-Content' => '' } ];
324: ok($tf->handle_http($t) == 0, 'FastCGI + bin-copy-environment');
325:
326:
327:
328: ok($tf->stop_proc == 0, "Stopping lighttpd");
329: }
330:
331:
332: SKIP: {
333: skip "no fcgi-responder found", 11 unless -x $tf->{BASEDIR}."/tests/fcgi-responder" || -x $tf->{BASEDIR}."/tests/fcgi-responder.exe";
334:
335: $tf->{CONFIGFILE} = 'fastcgi-responder.conf';
336: ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
337: $t->{REQUEST} = ( <<EOF
338: GET /index.fcgi?lf HTTP/1.0
339: Host: www.example.org
340: EOF
341: );
342: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
343: ok($tf->handle_http($t) == 0, 'line-ending \n\n');
344:
345: $t->{REQUEST} = ( <<EOF
346: GET /index.fcgi?crlf HTTP/1.0
347: Host: www.example.org
348: EOF
349: );
350: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
351: ok($tf->handle_http($t) == 0, 'line-ending \r\n\r\n');
352:
353: $t->{REQUEST} = ( <<EOF
354: GET /index.fcgi?slow-lf HTTP/1.0
355: Host: www.example.org
356: EOF
357: );
358: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
359: ok($tf->handle_http($t) == 0, 'line-ending \n + \n');
360:
361: $t->{REQUEST} = ( <<EOF
362: GET /index.fcgi?slow-crlf HTTP/1.0
363: Host: www.example.org
364: EOF
365: );
366: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
367: ok($tf->handle_http($t) == 0, 'line-ending \r\n + \r\n');
368:
369: $t->{REQUEST} = ( <<EOF
370: GET /abc/def/ghi?path_info HTTP/1.0
371: Host: wsgi.example.org
372: EOF
373: );
374: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/abc/def/ghi' } ];
375: ok($tf->handle_http($t) == 0, 'PATH_INFO (wsgi)');
376:
377: $t->{REQUEST} = ( <<EOF
378: GET /abc/def/ghi?script_name HTTP/1.0
379: Host: wsgi.example.org
380: EOF
381: );
382: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '' } ];
383: ok($tf->handle_http($t) == 0, 'SCRIPT_NAME (wsgi)');
384:
385:
386: $t->{REQUEST} = ( <<EOF
387: GET /index.fcgi?die-at-end HTTP/1.0
388: Host: www.example.org
389: EOF
390: );
391: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
392: ok($tf->handle_http($t) == 0, 'killing fastcgi and wait for restart');
393:
394: select(undef, undef, undef, .2);
395: $t->{REQUEST} = ( <<EOF
396: GET /index.fcgi?die-at-end HTTP/1.0
397: Host: www.example.org
398: EOF
399: );
400: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
401: ok($tf->handle_http($t) == 0, 'killing fastcgi and wait for restart');
402:
403:
404: select(undef, undef, undef, .2);
405: $t->{REQUEST} = ( <<EOF
406: GET /index.fcgi?crlf HTTP/1.0
407: Host: www.example.org
408: EOF
409: );
410: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
411: ok($tf->handle_http($t) == 0, 'regular response of after restart');
412:
413:
414: ok($tf->stop_proc == 0, "Stopping lighttpd");
415: }
416:
417: exit 0;
418:
419: cleanup: ;
420:
421: $tf->endspawnfcgi($php_child) if $php_child != -1;
422:
423: die();
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>