2005-09-01 11:44:57 +00:00
|
|
|
#!/usr/bin/env perl
|
2005-06-26 10:27:41 +00:00
|
|
|
BEGIN {
|
2008-01-15 22:03:59 +00:00
|
|
|
# add current source dir to the include-path
|
|
|
|
# we need this for make distcheck
|
|
|
|
(my $srcdir = $0) =~ s,/[^/]+$,/,;
|
|
|
|
unshift @INC, $srcdir;
|
2005-06-26 10:27:41 +00:00
|
|
|
}
|
2005-03-06 11:22:14 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use IO::Socket;
|
2009-10-12 21:49:09 +00:00
|
|
|
use Test::More tests => 8;
|
2005-06-15 09:37:18 +00:00
|
|
|
use LightyTest;
|
2005-03-06 11:22:14 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
my $tf = LightyTest->new();
|
|
|
|
my $t;
|
2008-07-29 21:22:28 +00:00
|
|
|
my $php_child = -1;
|
2006-10-05 00:09:51 +00:00
|
|
|
|
2008-07-29 21:22:28 +00:00
|
|
|
my $phpbin = (defined $ENV{'PHP'} ? $ENV{'PHP'} : '/usr/bin/php-cgi');
|
|
|
|
|
|
|
|
SKIP: {
|
|
|
|
skip "PHP already running on port 1026", 1 if $tf->listening_on(1026);
|
|
|
|
skip "no php binary found", 1 unless -x $phpbin;
|
|
|
|
ok(-1 != ($php_child = $tf->spawnfcgi($phpbin, 1026)), "Spawning php");
|
|
|
|
}
|
2005-03-06 11:22:14 +00:00
|
|
|
|
|
|
|
SKIP: {
|
2009-10-12 21:49:09 +00:00
|
|
|
skip "no PHP running on port 1026", 6 unless $tf->listening_on(1026);
|
2005-03-06 11:22:14 +00:00
|
|
|
|
2008-07-29 21:22:28 +00:00
|
|
|
ok($tf->start_proc == 0, "Starting lighttpd") or goto cleanup;
|
2005-03-06 11:22:14 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-06 11:22:14 +00:00
|
|
|
GET /rewrite/foo HTTP/1.0
|
|
|
|
Host: www.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'valid request');
|
2008-12-07 15:22:42 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-06 11:22:14 +00:00
|
|
|
GET /rewrite/foo?a=b HTTP/1.0
|
|
|
|
Host: www.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'a=b' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'valid request');
|
2005-03-06 11:22:14 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-06 11:22:14 +00:00
|
|
|
GET /rewrite/bar?a=b HTTP/1.0
|
|
|
|
Host: www.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'bar&a=b' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'valid request');
|
2005-03-06 11:22:14 +00:00
|
|
|
|
2009-10-12 21:49:09 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
|
|
|
GET /rewrite/nofile?a=b HTTP/1.0
|
|
|
|
Host: www.example.org
|
|
|
|
EOF
|
|
|
|
);
|
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'file=/rewrite/nofile&a=b' } ];
|
|
|
|
ok($tf->handle_http($t) == 0, 'not existing file rewrite');
|
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->stop_proc == 0, "Stopping lighttpd");
|
2005-03-06 11:22:14 +00:00
|
|
|
}
|
2008-07-29 21:22:28 +00:00
|
|
|
|
|
|
|
SKIP: {
|
|
|
|
skip "PHP not started, cannot stop it", 1 unless $php_child != -1;
|
|
|
|
ok(0 == $tf->endspawnfcgi($php_child), "Stopping php");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
cleanup: ;
|
|
|
|
|
|
|
|
$tf->endspawnfcgi($php_child) if $php_child != -1;
|
|
|
|
|
|
|
|
die();
|