3
# add current source dir to the include-path
4
# we need this for make distcheck
5
(my $srcdir = $0) =~ s#/[^/]+$#/#;
10
use Test::More tests => 45;
13
my $tf = LightyTest->new();
18
skip "no PHP running on port 1026", 28 unless $tf->listening_on(1026);
20
ok($tf->start_proc == 0, "Starting lighttpd") or die();
22
$t->{REQUEST} = ( <<EOF
23
GET /phpinfo.php HTTP/1.0
27
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
28
ok($tf->handle_http($t) == 0, 'valid request');
30
$t->{REQUEST} = ( <<EOF
31
GET /phpinfofoobar.php HTTP/1.0
35
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
36
ok($tf->handle_http($t) == 0, 'file not found');
38
$t->{REQUEST} = ( <<EOF
43
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
44
ok($tf->handle_http($t) == 0, 'index-file handling');
46
$t->{REQUEST} = ( <<EOF
47
GET /redirect.php HTTP/1.0
51
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => 'http://www.example.org:2048/' } ];
52
ok($tf->handle_http($t) == 0, 'Status + Location via FastCGI');
54
$t->{REQUEST} = ( <<EOF
55
GET /get-server-env.php?env=PHP_SELF HTTP/1.0
59
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
60
ok($tf->handle_http($t) == 0, '$_SERVER["PHP_SELF"]');
62
$t->{REQUEST} = ( <<EOF
63
GET /get-server-env.php/foo?env=PHP_SELF HTTP/1.0
67
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/get-server-env.php' } ];
68
ok($tf->handle_http($t) == 0, '$_SERVER["PHP_SELF"]');
70
$t->{REQUEST} = ( <<EOF
71
GET /get-server-env.php/foo?env=PATH_INFO HTTP/1.0
75
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo' } ];
76
ok($tf->handle_http($t) == 0, '$_SERVER["PATH_INFO"]');
78
$t->{REQUEST} = ( <<EOF
79
GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
83
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
84
ok($tf->handle_http($t) == 0, 'SERVER_NAME');
86
$t->{REQUEST} = ( <<EOF
87
GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
91
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
92
ok($tf->handle_http($t) == 0, 'SERVER_NAME');
94
$t->{REQUEST} = ( <<EOF
95
GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
99
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
100
ok($tf->handle_http($t) == 0, 'SERVER_NAME');
102
$t->{REQUEST} = ( <<EOF
103
GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
104
Host: zzz.example.org
107
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ];
108
ok($tf->handle_http($t) == 0, 'SERVER_NAME');
110
$t->{REQUEST} = ( <<EOF
111
GET /cgi.php/abc HTTP/1.0
114
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
115
ok($tf->handle_http($t) == 0, 'PATHINFO');
117
$t->{REQUEST} = ( <<EOF
118
GET /www/abc/def HTTP/1.0
121
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
122
ok($tf->handle_http($t) == 0, 'PATHINFO on a directory');
124
$t->{REQUEST} = ( <<EOF
125
GET /indexfile/ HTTP/1.0
128
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/indexfile/index.php' } ];
129
ok($tf->handle_http($t) == 0, 'PHP_SELF + Indexfile, Bug #3');
131
$t->{REQUEST} = ( <<EOF
132
GET /prefix.fcgi?var=SCRIPT_NAME HTTP/1.0
135
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/prefix.fcgi' } ];
136
ok($tf->handle_http($t) == 0, 'PATH_INFO, check-local off');
138
$t->{REQUEST} = ( <<EOF
139
GET /prefix.fcgi/foo/bar?var=SCRIPT_NAME HTTP/1.0
142
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/prefix.fcgi' } ];
143
ok($tf->handle_http($t) == 0, 'PATH_INFO, check-local off');
145
$t->{REQUEST} = ( <<EOF
146
GET /prefix.fcgi/foo/bar?var=PATH_INFO HTTP/1.0
149
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo/bar' } ];
150
ok($tf->handle_http($t) == 0, 'PATH_INFO, check-local off');
153
ok($tf->stop_proc == 0, "Stopping lighttpd");
156
$tf->{CONFIGFILE} = 'fastcgi-10.conf';
157
ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
158
$t->{REQUEST} = ( <<EOF
159
GET /get-server-env.php?env=SERVER_NAME HTTP/1.0
160
Host: zzz.example.org
163
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'zzz.example.org' } ];
164
ok($tf->handle_http($t) == 0, 'FastCGI + Host');
166
ok($tf->stop_proc == 0, "Stopping lighttpd");
168
$tf->{CONFIGFILE} = 'bug-06.conf';
169
ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
170
$t->{REQUEST} = ( <<EOF
171
GET /indexfile/ HTTP/1.0
172
Host: www.example.org
175
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/indexfile/index.php' } ];
176
ok($tf->handle_http($t) == 0, 'Bug #6');
178
ok($tf->stop_proc == 0, "Stopping lighttpd");
180
$tf->{CONFIGFILE} = 'bug-12.conf';
181
ok($tf->start_proc == 0, "Starting lighttpd with bug-12.conf") or die();
182
$t->{REQUEST} = ( <<EOF
183
POST /indexfile/abc HTTP/1.0
184
Host: www.example.org
188
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => '/indexfile/return-404.php' } ];
189
ok($tf->handle_http($t) == 0, 'Bug #12');
191
ok($tf->stop_proc == 0, "Stopping lighttpd");
195
skip "no fcgi-auth found", 4 unless -x $tf->{BASEDIR}."/tests/fcgi-auth" || -x $tf->{BASEDIR}."/tests/fcgi-auth.exe";
197
$tf->{CONFIGFILE} = 'fastcgi-auth.conf';
198
ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
199
$t->{REQUEST} = ( <<EOF
200
GET /index.html?ok HTTP/1.0
201
Host: www.example.org
204
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
205
ok($tf->handle_http($t) == 0, 'FastCGI - Auth');
207
$t->{REQUEST} = ( <<EOF
208
GET /index.html?fail HTTP/1.0
209
Host: www.example.org
212
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
213
ok($tf->handle_http($t) == 0, 'FastCGI - Auth');
215
ok($tf->stop_proc == 0, "Stopping lighttpd");
219
skip "no php found", 4 unless -x "/home/jan/Documents/php-5.1.0b3/sapi/cgi/php";
220
$tf->{CONFIGFILE} = 'fastcgi-13.conf';
221
ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
222
$t->{REQUEST} = ( <<EOF
223
GET /indexfile/index.php HTTP/1.0
224
Host: www.example.org
227
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
228
ok($tf->handle_http($t) == 0, 'FastCGI + local spawning');
230
$t->{REQUEST} = ( <<EOF
231
GET /get-env.php?env=MAIL HTTP/1.0
232
Host: www.example.org
235
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 , 'HTTP-Content' => '' } ];
236
ok($tf->handle_http($t) == 0, 'FastCGI + bin-copy-environment');
240
ok($tf->stop_proc == 0, "Stopping lighttpd");
245
skip "no fcgi-responder found", 9 unless -x $tf->{BASEDIR}."/tests/fcgi-responder" || -x $tf->{BASEDIR}."/tests/fcgi-responder.exe";
247
$tf->{CONFIGFILE} = 'fastcgi-responder.conf';
248
ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
249
$t->{REQUEST} = ( <<EOF
250
GET /index.fcgi?lf HTTP/1.0
251
Host: www.example.org
254
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
255
ok($tf->handle_http($t) == 0, 'line-ending \n\n');
257
$t->{REQUEST} = ( <<EOF
258
GET /index.fcgi?crlf HTTP/1.0
259
Host: www.example.org
262
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
263
ok($tf->handle_http($t) == 0, 'line-ending \r\n\r\n');
265
$t->{REQUEST} = ( <<EOF
266
GET /index.fcgi?slow-lf HTTP/1.0
267
Host: www.example.org
270
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
271
ok($tf->handle_http($t) == 0, 'line-ending \n + \n');
273
$t->{REQUEST} = ( <<EOF
274
GET /index.fcgi?slow-crlf HTTP/1.0
275
Host: www.example.org
278
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
279
ok($tf->handle_http($t) == 0, 'line-ending \r\n + \r\n');
281
$t->{REQUEST} = ( <<EOF
282
GET /index.fcgi?die-at-end HTTP/1.0
283
Host: www.example.org
286
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
287
ok($tf->handle_http($t) == 0, 'killing fastcgi and wait for restart');
289
select(undef, undef, undef, 2);
290
$t->{REQUEST} = ( <<EOF
291
GET /index.fcgi?die-at-end HTTP/1.0
292
Host: www.example.org
295
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
296
ok($tf->handle_http($t) == 0, 'killing fastcgi and wait for restart');
299
select(undef, undef, undef, 2);
300
$t->{REQUEST} = ( <<EOF
301
GET /index.fcgi?crlf HTTP/1.0
302
Host: www.example.org
305
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } ];
306
ok($tf->handle_http($t) == 0, 'regular response of after restart');
309
ok($tf->stop_proc == 0, "Stopping lighttpd");