[core] struct log_error_st for error logging
[lighttpd.git] / tests / mod-fastcgi.t
blob7a00963cdeb59b771f4ebeda8b825f878828fd38
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;
9 use strict;
10 use Test::More tests => 46;
11 use LightyTest;
13 my $tf = LightyTest->new();
15 my $t;
17 SKIP: {
18 skip "no php binary found", 31 unless $LightyTest::HAVE_PHP;
20 $tf->{CONFIGFILE} = 'fastcgi-10.conf';
21 ok($tf->start_proc == 0, "Starting lighttpd") or goto cleanup;
23 $t->{REQUEST} = ( <<EOF
24 GET /phpinfo.php HTTP/1.0
25 Host: www.example.org
26 EOF
28 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
29 ok($tf->handle_http($t) == 0, 'valid request');
31 $t->{REQUEST} = ( <<EOF
32 GET /phpinfofoobar.php HTTP/1.0
33 Host: www.example.org
34 EOF
36 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
37 ok($tf->handle_http($t) == 0, 'file not found');
39 $t->{REQUEST} = ( <<EOF
40 GET /go/ HTTP/1.0
41 Host: www.example.org
42 EOF
44 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
45 ok($tf->handle_http($t) == 0, 'index-file handling');
47 $t->{REQUEST} = ( <<EOF
48 GET /redirect.php HTTP/1.0
49 Host: www.example.org
50 EOF
52 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => 'http://www.example.org:2048/' } ];
53 ok($tf->handle_http($t) == 0, 'Status + Location via FastCGI');
55 $t->{REQUEST} = ( <<EOF
56 GET /redirect.php/ HTTP/1.0
57 Host: www.example.org
58 EOF
60 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => 'http://www.example.org:2048/' } ];
61 ok($tf->handle_http($t) == 0, 'Trailing slash as path-info (#1989: workaround broken operating systems)');
63 $t->{REQUEST} = ( <<EOF
64 GET /get-server-env.php?env=PHP_SELF HTTP/1.0
65 Host: www.example.org
66 EOF
68 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
69 ok($tf->handle_http($t) == 0, '$_SERVER["PHP_SELF"]');
71 $t->{REQUEST} = ( <<EOF
72 GET /get-server-env.php/foo?env=SCRIPT_NAME HTTP/1.0
73 Host: www.example.org
74 EOF
76 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/get-server-env.php' } ];
77 ok($tf->handle_http($t) == 0, '$_SERVER["SCRIPT_NAME"]');
79 $t->{REQUEST} = ( <<EOF
80 GET /get-server-env.php/foo?env=PATH_INFO HTTP/1.0
81 Host: www.example.org
82 EOF
84 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo' } ];
85 ok($tf->handle_http($t) == 0, '$_SERVER["PATH_INFO"]');
87 $t->{REQUEST} = ( <<EOF
88 GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
89 Host: www.example.org
90 EOF
92 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
93 ok($tf->handle_http($t) == 0, 'SERVER_NAME');
95 $t->{REQUEST} = ( <<EOF
96 GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
97 Host: foo.example.org
98 EOF
100 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
101 ok($tf->handle_http($t) == 0, 'SERVER_NAME');
103 $t->{REQUEST} = ( <<EOF
104 GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
105 Host: vvv.example.org
108 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
109 ok($tf->handle_http($t) == 0, 'SERVER_NAME');
111 $t->{REQUEST} = ( <<EOF
112 GET /cgi.php/abc HTTP/1.0
115 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
116 ok($tf->handle_http($t) == 0, 'PATHINFO');
118 if ($^O ne "cygwin") {
119 $t->{REQUEST} = ( <<EOF
120 GET /cgi.php%20%20%20 HTTP/1.0
123 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
124 ok($tf->handle_http($t) == 0, 'No source retrieval');
125 } else {
126 ok(1, 'No source retrieval; skipped on cygwin; see response.c');
129 $t->{REQUEST} = ( <<EOF
130 GET /www/abc/def HTTP/1.0
133 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
134 ok($tf->handle_http($t) == 0, 'PATHINFO on a directory');
136 $t->{REQUEST} = ( <<EOF
137 GET /indexfile/ HTTP/1.0
140 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/indexfile/index.php' } ];
141 ok($tf->handle_http($t) == 0, 'PHP_SELF + Indexfile, Bug #3');
143 $t->{REQUEST} = ( <<EOF
144 GET /prefix.fcgi?var=SCRIPT_NAME HTTP/1.0
147 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/prefix.fcgi' } ];
148 ok($tf->handle_http($t) == 0, 'PATH_INFO, check-local off');
150 $t->{REQUEST} = ( <<EOF
151 GET /prefix.fcgi/foo/bar?var=SCRIPT_NAME HTTP/1.0
154 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/prefix.fcgi' } ];
155 ok($tf->handle_http($t) == 0, 'PATH_INFO, check-local off');
157 $t->{REQUEST} = ( <<EOF
158 GET /prefix.fcgi/foo/bar?var=PATH_INFO HTTP/1.0
161 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo/bar' } ];
162 ok($tf->handle_http($t) == 0, 'PATH_INFO, check-local off');
164 $t->{REQUEST} = ( <<EOF
165 GET /sendfile.php?range=0- HTTP/1.0
168 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => 4348 } ];
169 ok($tf->handle_http($t) == 0, 'X-Sendfile2');
171 $t->{REQUEST} = ( <<EOF
172 GET /sendfile.php?range=0-4&range2=5- HTTP/1.0
175 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => 4348 } ];
176 ok($tf->handle_http($t) == 0, 'X-Sendfile2');
178 $t->{REQUEST} = ( <<EOF
179 GET /get-server-env.php?env=REMOTE_USER HTTP/1.0
180 Host: auth.example.org
181 Authorization: Basic ZGVzOmRlcw==
184 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'des' } ];
185 ok($tf->handle_http($t) == 0, '$_SERVER["REMOTE_USER"]');
187 $t->{REQUEST} = ( <<EOF
188 GET /get-server-env.php?env=AUTH_TYPE HTTP/1.0
189 Host: auth.example.org
190 Authorization: Basic ZGVzOmRlcw==
193 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'Basic' } ];
194 ok($tf->handle_http($t) == 0, '$_SERVER["AUTH_TYPE"]');
196 $t->{REQUEST} = ( <<EOF
197 GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
198 Host: zzz.example.org
201 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'zzz.example.org' } ];
202 ok($tf->handle_http($t) == 0, 'FastCGI + Host');
204 $t->{REQUEST} = ( <<EOF
205 GET http://zzz.example.org/get-server-env.php?env=SERVER_NAME HTTP/1.0
206 Host: aaa.example.org
209 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'zzz.example.org' } ];
210 ok($tf->handle_http($t) == 0, 'SERVER_NAME (absolute url in request line)');
212 $t->{REQUEST} = ( <<EOF
213 GET /indexfile/ HTTP/1.0
214 Host: www.example.org
217 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/indexfile/index.php' } ];
218 ok($tf->handle_http($t) == 0, 'Bug #6');
220 $t->{REQUEST} = ( <<EOF
221 POST /indexfile/abc HTTP/1.0
222 Host: www.example.org
223 Content-Length: 0
226 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => '/indexfile/return-404.php' } ];
227 ok($tf->handle_http($t) == 0, 'Bug #12');
229 $t->{REQUEST} = ( <<EOF
230 GET /indexfile/index.php HTTP/1.0
231 Host: bin-env.example.org
234 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
235 ok($tf->handle_http($t) == 0, 'FastCGI + local spawning');
237 $t->{REQUEST} = ( <<EOF
238 HEAD /indexfile/index.php HTTP/1.0
239 Host: bin-env.example.org
242 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '-Content-Length' => '0' } ];
243 # Of course a valid content-length != 0 would be ok, but we assume for now that such one is not generated.
244 ok($tf->handle_http($t) == 0, 'Check for buggy content length with HEAD');
246 $t->{REQUEST} = ( <<EOF
247 GET /get-env.php?env=MAIL HTTP/1.0
248 Host: bin-env.example.org
251 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 , 'HTTP-Content' => '' } ];
252 ok($tf->handle_http($t) == 0, 'FastCGI + bin-copy-environment');
254 ok($tf->stop_proc == 0, "Stopping lighttpd");
257 SKIP: {
258 skip "no fcgi-auth, fcgi-responder found", 15
259 unless (-x $tf->{BASEDIR}."/tests/fcgi-auth" || -x $tf->{BASEDIR}."/tests/fcgi-auth.exe")
260 && (-x $tf->{BASEDIR}."/tests/fcgi-responder" || -x $tf->{BASEDIR}."/tests/fcgi-responder.exe");
262 $tf->{CONFIGFILE} = 'fastcgi-responder.conf';
263 ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
264 $t->{REQUEST} = ( <<EOF
265 GET /index.html?ok HTTP/1.0
266 Host: auth.example.org
269 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
270 ok($tf->handle_http($t) == 0, 'FastCGI - Auth');
272 $t->{REQUEST} = ( <<EOF
273 GET /index.html?fail HTTP/1.0
274 Host: auth.example.org
277 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
278 ok($tf->handle_http($t) == 0, 'FastCGI - Auth');
280 $t->{REQUEST} = ( <<EOF
281 GET /expire/access.txt?ok HTTP/1.0
282 Host: auth.example.org
285 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
286 ok($tf->handle_http($t) == 0, 'FastCGI - Auth in subdirectory');
288 $t->{REQUEST} = ( <<EOF
289 GET /index.fcgi?varfail HTTP/1.0
290 Host: auth.example.org
293 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
294 ok($tf->handle_http($t) == 0, 'FastCGI - Auth Fail with FastCGI responder afterwards');
296 $t->{REQUEST} = ( <<EOF
297 GET /index.fcgi?var HTTP/1.0
298 Host: auth.example.org
301 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'LighttpdTestContent' } ];
302 ok($tf->handle_http($t) == 0, 'FastCGI - Auth Success with Variable- to Env expansion');
304 $t->{REQUEST} = ( <<EOF
305 GET /index.fcgi?lf HTTP/1.0
306 Host: www.example.org
309 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
310 ok($tf->handle_http($t) == 0, 'line-ending \n\n');
312 $t->{REQUEST} = ( <<EOF
313 GET /index.fcgi?crlf HTTP/1.0
314 Host: www.example.org
317 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
318 ok($tf->handle_http($t) == 0, 'line-ending \r\n\r\n');
320 $t->{REQUEST} = ( <<EOF
321 GET /index.fcgi?slow-lf HTTP/1.0
322 Host: www.example.org
325 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
326 ok($tf->handle_http($t) == 0, 'line-ending \n + \n');
328 $t->{REQUEST} = ( <<EOF
329 GET /index.fcgi?slow-crlf HTTP/1.0
330 Host: www.example.org
333 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
334 ok($tf->handle_http($t) == 0, 'line-ending \r\n + \r\n');
336 $t->{REQUEST} = ( <<EOF
337 GET /abc/def/ghi?path_info HTTP/1.0
338 Host: wsgi.example.org
341 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/abc/def/ghi' } ];
342 ok($tf->handle_http($t) == 0, 'PATH_INFO (wsgi)');
344 $t->{REQUEST} = ( <<EOF
345 GET /abc/def/ghi?script_name HTTP/1.0
346 Host: wsgi.example.org
349 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '' } ];
350 ok($tf->handle_http($t) == 0, 'SCRIPT_NAME (wsgi)');
353 $t->{REQUEST} = ( <<EOF
354 GET /index.fcgi?die-at-end HTTP/1.0
355 Host: www.example.org
358 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
359 ok($tf->handle_http($t) == 0, 'killing fastcgi and wait for restart');
361 # (might take lighttpd 1 sec to detect backend exit)
362 select(undef, undef, undef, .5);
363 for (my $c = 2*20; $c && 0 == $tf->listening_on(10000); --$c) {
364 select(undef, undef, undef, 0.05);
366 $t->{REQUEST} = ( <<EOF
367 GET /index.fcgi?crlf HTTP/1.0
368 Host: www.example.org
371 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
372 ok($tf->handle_http($t) == 0, 'regular response of after restart');
375 ok($tf->stop_proc == 0, "Stopping lighttpd");
378 exit 0;
380 cleanup: ;
382 die();