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