diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2020-12-23 00:38:43 -0500 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2020-12-23 03:50:13 -0500 |
commit | b598bb53f961cdc5743b034f646c7633806fc832 (patch) | |
tree | ca0e130a6df4ac66f52f208c99ad2f3686e455d9 | |
parent | 89a3987ce7d6c109269d3370d464994d8feee5cf (diff) | |
download | lighttpd-git-b598bb53f961cdc5743b034f646c7633806fc832.tar.gz |
[tests] remove FastCGI test dependency on PHP
31 files changed, 219 insertions, 377 deletions
diff --git a/configure.ac b/configure.ac index 44dd0ffb..6ebfe385 100644 --- a/configure.ac +++ b/configure.ac @@ -1653,7 +1653,6 @@ AC_CONFIG_FILES([\ tests/docroot/123/Makefile \ tests/docroot/Makefile \ tests/docroot/www/expire/Makefile \ - tests/docroot/www/go/Makefile \ tests/docroot/www/indexfile/Makefile \ tests/docroot/www/Makefile \ tests/Makefile \ diff --git a/tests/LightyTest.pm b/tests/LightyTest.pm index 434b6b6c..29ea0bf3 100644 --- a/tests/LightyTest.pm +++ b/tests/LightyTest.pm @@ -36,7 +36,6 @@ sub find_program { } BEGIN { - our $HAVE_PHP = find_program('PHP', 'php-cgi'); our $HAVE_PERL = find_program('PERL', 'perl'); if (!$HAVE_PERL) { die "Couldn't find path to perl, but it obviously seems to be running"; diff --git a/tests/Makefile.am b/tests/Makefile.am index f6955fad..c6c1231b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -21,7 +21,6 @@ CONFS=\ core-request.t \ core-response.t \ core-var-include.t \ - fastcgi-10.conf \ fastcgi-responder.conf \ LightyTest.pm \ lowercase.conf \ diff --git a/tests/README b/tests/README index bbecd0c7..265afea9 100644 --- a/tests/README +++ b/tests/README @@ -46,21 +46,20 @@ To run a specific config repo=$PWD # from root of src repository cd tests/ ./prepare.sh - PERL=/usr/bin/perl PHP=/usr/bin/php-cgi SRCDIR=$repo/tests \ + PERL=/usr/bin/perl SRCDIR=$repo/tests \ $repo/src/lighttpd -D -f lighttpd.conf -m $repo/src/.libs The PERL, PHP, and SRCDIR environment variables are set by LightyTest.pm when 'make check' is run. PERL and PHP can be set to paths to perl and php, -e.g. export PERL=/usr/bin/perl PHP=/usr/bin/php-cgi +e.g. export PERL=/usr/bin/perl To run a specific config under gdb repo=$PWD # from root of src repository cd tests/ ./prepare.sh - PERL=/usr/bin/perl PHP=/usr/bin/php-cgi SRCDIR=$repo/tests repo=$repo \ - gdb $repo/src/lighttpd + PERL=/usr/bin/perl SRCDIR=$repo/tests \ + gdb --args $repo/src/lighttpd -D -f lighttpd.conf -m $repo/src/.libs - (gdb) set args -D -f lighttpd.conf -m $repo/src/.libs (gdb) start (gdb) ... diff --git a/tests/docroot/123/Makefile.am b/tests/docroot/123/Makefile.am index f77f883a..4652a4f9 100644 --- a/tests/docroot/123/Makefile.am +++ b/tests/docroot/123/Makefile.am @@ -1 +1 @@ -EXTRA_DIST=100.txt 12345.html 12345.txt dummyfile.bla phpinfo.php +EXTRA_DIST=100.txt 12345.html 12345.txt dummyfile.bla diff --git a/tests/docroot/123/phpinfo.php b/tests/docroot/123/phpinfo.php deleted file mode 100644 index 147cebcd..00000000 --- a/tests/docroot/123/phpinfo.php +++ /dev/null @@ -1 +0,0 @@ -<?php phpinfo(); ?> diff --git a/tests/docroot/www/Makefile.am b/tests/docroot/www/Makefile.am index 1e2f6aef..72bbeb51 100644 --- a/tests/docroot/www/Makefile.am +++ b/tests/docroot/www/Makefile.am @@ -2,27 +2,20 @@ EXTRA_DIST=\ 404.html \ 404.pl \ cgi-pathinfo.pl \ - cgi.php \ cgi.pl \ crlfcrash.pl \ exec-date.shtml \ - get-env.php \ get-header.pl \ get-post-len.pl \ - get-server-env.php \ index.html \ index.txt \ ip.pl \ nph-status.pl \ - phpinfo.php \ prefix.fcgi \ - redirect.php \ send404.pl \ - sendfile.php \ ssi-include.shtml \ ssi-include.txt \ ssi.shtml SUBDIRS=\ expire \ - go \ indexfile diff --git a/tests/docroot/www/cgi.php b/tests/docroot/www/cgi.php deleted file mode 100755 index f59a8401..00000000 --- a/tests/docroot/www/cgi.php +++ /dev/null @@ -1,9 +0,0 @@ -<?php - -#ob_start(/*"ob_gzhandler"*/); -print "12345<br />\n"; -#phpinfo(); -#header("Content-Length: ".ob_get_length()); -#ob_end_flush(); - -?> diff --git a/tests/docroot/www/cgi.pl b/tests/docroot/www/cgi.pl index f7296f8b..c149cee1 100755 --- a/tests/docroot/www/cgi.pl +++ b/tests/docroot/www/cgi.pl @@ -5,6 +5,33 @@ if ($ENV{"QUERY_STRING"} eq "internal-redir") { exit 0; } +if ($ENV{"QUERY_STRING"} eq "external-redir") { + print "Location: http://www.example.org:2048/\r\n\r\n"; + exit 0; +} + +# X-Sendfile +if ($ENV{"QUERY_STRING"} eq "xsendfile") { + # urlencode path for CGI header + # (including urlencode ',' if in path, for X-Sendfile2 w/ FastCGI (not CGI)) + # (This implementation is not minimal encoding; + # encode everything that is not alphanumeric, '.' '_', '-', '/') + require Cwd; + my $path = Cwd::getcwd() . "/index.txt"; + $path =~ s#([^\w./-])#"%".unpack("H2",$1)#eg; + + print "Status: 200\r\n"; + print "X-Sendfile: $path\r\n\r\n"; + exit 0; +} + +# env +if ($ENV{"QUERY_STRING"} =~ /^env=(\w+)/) { + print "Status: 200\r\n\r\n$ENV{$1}"; + exit 0; +} + +# default print "Content-Type: text/html\r\n\r\n"; print $ENV{"SCRIPT_NAME"}; diff --git a/tests/docroot/www/get-env.php b/tests/docroot/www/get-env.php deleted file mode 100644 index cd7fa040..00000000 --- a/tests/docroot/www/get-env.php +++ /dev/null @@ -1,4 +0,0 @@ -<?php - $env = $_GET["env"]; - print isset($_ENV[$env]) ? $_ENV[$env] : ''; -?> diff --git a/tests/docroot/www/get-server-env.php b/tests/docroot/www/get-server-env.php deleted file mode 100644 index 64d93124..00000000 --- a/tests/docroot/www/get-server-env.php +++ /dev/null @@ -1,3 +0,0 @@ -<?php - print $_SERVER[$_GET["env"]]; -?> diff --git a/tests/docroot/www/go/Makefile.am b/tests/docroot/www/go/Makefile.am deleted file mode 100644 index fe20c503..00000000 --- a/tests/docroot/www/go/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -EXTRA_DIST=cgi.php diff --git a/tests/docroot/www/go/cgi.php b/tests/docroot/www/go/cgi.php deleted file mode 100755 index f59a8401..00000000 --- a/tests/docroot/www/go/cgi.php +++ /dev/null @@ -1,9 +0,0 @@ -<?php - -#ob_start(/*"ob_gzhandler"*/); -print "12345<br />\n"; -#phpinfo(); -#header("Content-Length: ".ob_get_length()); -#ob_end_flush(); - -?> diff --git a/tests/docroot/www/indexfile/Makefile.am b/tests/docroot/www/indexfile/Makefile.am index 333c0c56..140163d3 100644 --- a/tests/docroot/www/indexfile/Makefile.am +++ b/tests/docroot/www/indexfile/Makefile.am @@ -1 +1 @@ -EXTRA_DIST=index.php return-404.php query_string.pl +EXTRA_DIST=index.pl query_string.pl diff --git a/tests/docroot/www/indexfile/index.php b/tests/docroot/www/indexfile/index.php deleted file mode 100644 index e0c7d9ec..00000000 --- a/tests/docroot/www/indexfile/index.php +++ /dev/null @@ -1 +0,0 @@ -<?php print $_SERVER["PHP_SELF"]; ?> diff --git a/tests/docroot/www/indexfile/index.pl b/tests/docroot/www/indexfile/index.pl new file mode 100644 index 00000000..dbf047b9 --- /dev/null +++ b/tests/docroot/www/indexfile/index.pl @@ -0,0 +1,8 @@ +#!/usr/bin/perl + +if ($ENV{REDIRECT_STATUS}) { + print "Status: $ENV{REDIRECT_STATUS}\r\n\r\n$ENV{SCRIPT_NAME}"; + exit 0; +} + +print "Status: 200\r\n\r\n"; diff --git a/tests/docroot/www/indexfile/return-404.php b/tests/docroot/www/indexfile/return-404.php deleted file mode 100644 index 2adaaeaa..00000000 --- a/tests/docroot/www/indexfile/return-404.php +++ /dev/null @@ -1,5 +0,0 @@ -<?php - header("Status: 404"); - - print $_SERVER["PHP_SELF"]; -?> diff --git a/tests/docroot/www/phpinfo.php b/tests/docroot/www/phpinfo.php deleted file mode 100644 index 147cebcd..00000000 --- a/tests/docroot/www/phpinfo.php +++ /dev/null @@ -1 +0,0 @@ -<?php phpinfo(); ?> diff --git a/tests/docroot/www/prefix.fcgi b/tests/docroot/www/prefix.fcgi index e3883520..f091de63 100644 --- a/tests/docroot/www/prefix.fcgi +++ b/tests/docroot/www/prefix.fcgi @@ -1,3 +1 @@ -<?php -echo $_SERVER[$_GET["var"]]; -?> +# (file exists for mod-fastcgi.t test case) diff --git a/tests/docroot/www/redirect.php b/tests/docroot/www/redirect.php deleted file mode 100644 index 0489d22d..00000000 --- a/tests/docroot/www/redirect.php +++ /dev/null @@ -1,4 +0,0 @@ -<?php - - header('Location: http://www.example.org:2048/'); -?> diff --git a/tests/docroot/www/sendfile.php b/tests/docroot/www/sendfile.php deleted file mode 100644 index e4602203..00000000 --- a/tests/docroot/www/sendfile.php +++ /dev/null @@ -1,13 +0,0 @@ -<?php - -function pathencode($path) { - return str_replace(',', '%2c', urlencode($path)); -} - -$val = "X-Sendfile2: " . pathencode(getcwd() . "/index.txt") . " " . $_GET["range"]; - -if (isset($_GET["range2"])) $val .= ", " . pathencode(getcwd() . "/index.txt") . " " . $_GET["range2"]; - -header($val); - -?>
\ No newline at end of file diff --git a/tests/fastcgi-10.conf b/tests/fastcgi-10.conf deleted file mode 100644 index f0285622..00000000 --- a/tests/fastcgi-10.conf +++ /dev/null @@ -1,67 +0,0 @@ -server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/" - -## bind to port (default: 80) -server.port = 2048 - -## bind to localhost (default: all interfaces) -server.bind = "localhost" -server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log" -server.breakagelog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log" -server.name = "www.example.org" -server.tag = "Apache 1.3.29" - -server.modules = ( - "mod_auth", - "mod_authn_file", - "mod_fastcgi", - "mod_accesslog", -) - -index-file.names = ( - "index.php", - "index.html", -) - -accesslog.filename = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.access.log" - -fastcgi.debug = 0 -fastcgi.server = ( - ".php" => ( ( - "host" => "127.0.0.1", - "port" => 1026, - "bin-path" => env.PHP, - "bin-copy-environment" => ( "PATH", "SHELL", "USER", ), - "allow-x-send-file" => "enable", - ) ), - "/prefix.fcgi" => ( ( - "host" => "127.0.0.1", - "port" => 1026, - "bin-path" => env.PHP, - "bin-copy-environment" => ( "PATH", "SHELL", "USER", ), - ) ), -) - -server.error-handler-404 = "/indexfile/return-404.php" - -$HTTP["host"] == "zzz.example.org" { - server.name = "zzz.example.org" -} - -$HTTP["host"] == "auth.example.org" { - server.name = "auth.example.org" - auth.backend.htpasswd.userfile = env.SRCDIR + "/tmp/lighttpd/lighttpd.htpasswd" - auth.backend = "htpasswd" - auth.require = ( - "" => ( - "method" => "basic", - "realm" => "download archiv", - "require" => "valid-user", - ), - ) -} - -$HTTP["host"] == "www.example.org" { - $HTTP["url"] == "/go/" { - index-file.names = ( "cgi.php" ) - } -} diff --git a/tests/fastcgi-responder.conf b/tests/fastcgi-responder.conf index c905f9f4..d5a430a8 100644 --- a/tests/fastcgi-responder.conf +++ b/tests/fastcgi-responder.conf @@ -15,69 +15,95 @@ server.name = "www.example.org" server.tag = "Apache 1.3.29" server.modules = ( + "mod_auth", + "mod_authn_file", "mod_fastcgi", "mod_accesslog", ) -index-file.names = ( - "index.php", - "index.html", -) - accesslog.filename = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.access.log" $HTTP["host"] == "auth.example.org" { -fastcgi.debug = 0 -fastcgi.server = ( + server.name = "auth.example.org" + + $HTTP["url"] =~ "\.php$" { + auth.backend.htpasswd.userfile = env.SRCDIR + "/tmp/lighttpd/lighttpd.htpasswd" + auth.backend = "htpasswd" + auth.require = ( + "" => ( + "method" => "basic", + "realm" => "download archiv", + "require" => "valid-user", + ), + ) + } + + fastcgi.debug = 0 + fastcgi.server = ( "/" => ( "grisu-auth" => ( "host" => "127.0.0.1", - "port" => 20000, + "port" => 10000, "bin-path" => env.SRCDIR + "/fcgi-responder", - "mode" => "authorizer", + "bin-copy-environment" => ( "PATH", "SHELL", "USER", ), "check-local" => "disable", + "max-procs" => 1, + "mode" => "authorizer", ), "grisu-resp" => ( "host" => "127.0.0.1", "port" => 10000, "bin-path" => env.SRCDIR + "/fcgi-responder", + "bin-copy-environment" => ( "PATH", "SHELL", "USER", ), "check-local" => "disable", "max-procs" => 1, ), ), -) + ) } else { -fastcgi.debug = 0 -fastcgi.server = ( + fastcgi.debug = 0 + fastcgi.server = ( + ".php" => ( ( + "host" => "127.0.0.1", + "port" => 10000, + "bin-path" => env.SRCDIR + "/fcgi-responder", + "bin-copy-environment" => ( "PATH", "SHELL", "USER", ), + "check-local" => "disable", + "max-procs" => 1, + ) ), + "/prefix.fcgi" => ( ( + "host" => "127.0.0.1", + "port" => 10000, + "bin-path" => env.SRCDIR + "/fcgi-responder", + "max-procs" => 1, + ) ), ".fcgi" => ( "grisu" => ( "host" => "127.0.0.1", "port" => 10000, "bin-path" => env.SRCDIR + "/fcgi-responder", + "bin-copy-environment" => ( "PATH", "SHELL", "USER", ), "check-local" => "disable", "max-procs" => 1, - "min-procs" => 1, ), ), -) + ) } -$HTTP["host"] == "zzz.example.org" { - server.name = "zzz.example.org" -} - $HTTP["host"] == "wsgi.example.org" { fastcgi.server = ( "/" => ( ( - "host" => "127.0.0.1", "port" => 10000, - "fix-root-scriptname" => "enable", - "check-local" => "disable", + "host" => "127.0.0.1", + "port" => 10000, "bin-path" => env.SRCDIR + "/fcgi-responder", + "bin-copy-environment" => ( "PATH", "SHELL", "USER", ), + "check-local" => "disable", + "fix-root-scriptname" => "enable", "max-procs" => 1, ) ), ) diff --git a/tests/fcgi-responder.c b/tests/fcgi-responder.c index 64bcc2a9..31ec884b 100644 --- a/tests/fcgi-responder.c +++ b/tests/fcgi-responder.c @@ -198,10 +198,6 @@ fcgi_process_params (FILE * const stream, int req_id, int role, unsigned char * if (NULL == p) cdata = NULL; - else if (9 == len && 0 == memcmp(p, "path_info", 9)) - cdata = fcgi_getenv(r, rlen, "PATH_INFO", 9, &len); - else if (11 == len && 0 == memcmp(p, "script_name", 11)) - cdata = fcgi_getenv(r, rlen, "SCRIPT_NAME", 11, &len); else if (len > 4 && 0 == memcmp(p, "env=", 4)) cdata = fcgi_getenv(r, rlen, p+4, len-4, &len); else if (8 == len && 0 == memcmp(p, "auth-var", 8)) diff --git a/tests/lighttpd.conf b/tests/lighttpd.conf index 31515899..7b57d42e 100644 --- a/tests/lighttpd.conf +++ b/tests/lighttpd.conf @@ -172,3 +172,9 @@ $HTTP["host"] == "etag.example.org" { static-file.etags = "disable" deflate.filetype = () } + +$HTTP["host"] == "cgi.example.org" { + index-file.names = ( "nonexistent.txt", "index.pl" ) + server.error-handler-404 = "/indexfile/index.pl" + cgi.x-sendfile = "enable" +} diff --git a/tests/mod-cgi.t b/tests/mod-cgi.t index b3e306ca..33fa76f0 100755 --- a/tests/mod-cgi.t +++ b/tests/mod-cgi.t @@ -8,7 +8,7 @@ BEGIN { use strict; use IO::Socket; -use Test::More tests => 16; +use Test::More tests => 24; use LightyTest; my $tf = LightyTest->new(); @@ -25,6 +25,17 @@ EOF $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; ok($tf->handle_http($t) == 0, 'perl via cgi'); +if ($^O ne "cygwin") { + $t->{REQUEST} = ( <<EOF +GET /cgi.pl%20%20%20 HTTP/1.0 +EOF + ); + $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ]; + ok($tf->handle_http($t) == 0, 'No source retrieval'); +} else { + ok(1, 'No source retrieval; skipped on cygwin; see response.c'); +} + $t->{REQUEST} = ( <<EOF GET /cgi.pl/foo HTTP/1.0 EOF @@ -40,6 +51,30 @@ $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; ok($tf->handle_http($t) == 0, 'perl via cgi and internal redirect from CGI'); $t->{REQUEST} = ( <<EOF +GET /cgi.pl?xsendfile HTTP/1.0 +Host: cgi.example.org +EOF + ); +$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => 4348 } ]; +ok($tf->handle_http($t) == 0, 'X-Sendfile'); + +$t->{REQUEST} = ( <<EOF +GET /cgi.pl?external-redir HTTP/1.0 +Host: www.example.org +EOF + ); +$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => 'http://www.example.org:2048/' } ]; +ok($tf->handle_http($t) == 0, 'Status + Location via FastCGI'); + +$t->{REQUEST} = ( <<EOF +GET /cgi.pl/?external-redir HTTP/1.0 +Host: www.example.org +EOF + ); +$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => 'http://www.example.org:2048/' } ]; +ok($tf->handle_http($t) == 0, 'Trailing slash as path-info (#1989: workaround broken operating systems)'); + +$t->{REQUEST} = ( <<EOF GET /cgi-pathinfo.pl/foo HTTP/1.0 EOF ); @@ -82,11 +117,25 @@ $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP- ok($tf->handle_http($t) == 0, 'cgi-env: QUERY_STRING'); $t->{REQUEST} = ( <<EOF -GET /get-header.pl?GATEWAY_INTERFACE HTTP/1.0 +GET /get-header.pl?SCRIPT_NAME HTTP/1.0 EOF ); -$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'CGI/1.1' } ]; -ok($tf->handle_http($t) == 0, 'cgi-env: GATEWAY_INTERFACE'); +$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/get-header.pl' } ]; +ok($tf->handle_http($t) == 0, 'cgi-env: SCRIPT_NAME'); + +$t->{REQUEST} = ( <<EOF +GET /get-header.pl/path/info?SCRIPT_NAME HTTP/1.0 +EOF + ); +$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/get-header.pl' } ]; +ok($tf->handle_http($t) == 0, 'cgi-env: SCRIPT_NAME w/ PATH_INFO'); + +$t->{REQUEST} = ( <<EOF +GET /get-header.pl/path/info?PATH_INFO HTTP/1.0 +EOF + ); +$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/path/info' } ]; +ok($tf->handle_http($t) == 0, 'cgi-env: PATH_INFO'); $t->{REQUEST} = ( <<EOF GET /get-header.pl?HTTP_XX_YY123 HTTP/1.0 @@ -121,5 +170,23 @@ EOF $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => 'http://www.example.org/' } ]; ok($tf->handle_http($t) == 0, 'broken header via perl cgi'); +$t->{REQUEST} = ( <<EOF +GET /indexfile/ HTTP/1.0 +Host: cgi.example.org +EOF + ); +$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/indexfile/index.pl' } ]; +ok($tf->handle_http($t) == 0, 'index-file handling, Bug #3, Bug #6'); + +$t->{REQUEST} = ( <<EOF +POST /indexfile/abc HTTP/1.0 +Host: cgi.example.org +Content-Length: 0 +EOF + ); +$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => '/indexfile/index.pl' } ]; +ok($tf->handle_http($t) == 0, 'server.error-handler-404, Bug #12'); + + ok($tf->stop_proc == 0, "Stopping lighttpd"); diff --git a/tests/mod-fastcgi.t b/tests/mod-fastcgi.t index 449b1534..0e7ae4a8 100755 --- a/tests/mod-fastcgi.t +++ b/tests/mod-fastcgi.t @@ -7,7 +7,7 @@ BEGIN { } use strict; -use Test::More tests => 44; +use Test::More tests => 24; use LightyTest; my $tf = LightyTest->new(); @@ -15,21 +15,15 @@ my $tf = LightyTest->new(); my $t; SKIP: { - skip "no php binary found", 29 unless $LightyTest::HAVE_PHP; - - $tf->{CONFIGFILE} = 'fastcgi-10.conf'; - ok($tf->start_proc == 0, "Starting lighttpd") or goto cleanup; + skip "no fcgi-responder found", 24 + unless ( -x $tf->{BASEDIR}."/tests/fcgi-responder" + || -x $tf->{BASEDIR}."/tests/fcgi-responder.exe"); - $t->{REQUEST} = ( <<EOF -GET /phpinfo.php HTTP/1.0 -Host: www.example.org -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; - ok($tf->handle_http($t) == 0, 'valid request'); + $tf->{CONFIGFILE} = 'fastcgi-responder.conf'; + ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die(); $t->{REQUEST} = ( <<EOF -GET /phpinfofoobar.php HTTP/1.0 +GET /prefix.fcgi-nonexistent HTTP/1.0 Host: www.example.org EOF ); @@ -37,143 +31,49 @@ EOF ok($tf->handle_http($t) == 0, 'file not found'); $t->{REQUEST} = ( <<EOF -GET /go/ HTTP/1.0 -Host: www.example.org -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; - ok($tf->handle_http($t) == 0, 'index-file handling'); - - $t->{REQUEST} = ( <<EOF -GET /redirect.php HTTP/1.0 -Host: www.example.org -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => 'http://www.example.org:2048/' } ]; - ok($tf->handle_http($t) == 0, 'Status + Location via FastCGI'); - - $t->{REQUEST} = ( <<EOF -GET /redirect.php/ HTTP/1.0 -Host: www.example.org -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => 'http://www.example.org:2048/' } ]; - ok($tf->handle_http($t) == 0, 'Trailing slash as path-info (#1989: workaround broken operating systems)'); - - $t->{REQUEST} = ( <<EOF -GET /get-server-env.php?env=PHP_SELF HTTP/1.0 -Host: www.example.org +GET /prefix.fcgi?env=SCRIPT_NAME HTTP/1.0 EOF ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; - ok($tf->handle_http($t) == 0, '$_SERVER["PHP_SELF"]'); + $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/prefix.fcgi' } ]; + ok($tf->handle_http($t) == 0, 'SCRIPT_NAME'); $t->{REQUEST} = ( <<EOF -GET /get-server-env.php/foo?env=SCRIPT_NAME HTTP/1.0 -Host: www.example.org +GET /prefix.fcgi/foo/bar?env=SCRIPT_NAME HTTP/1.0 EOF ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/get-server-env.php' } ]; - ok($tf->handle_http($t) == 0, '$_SERVER["SCRIPT_NAME"]'); + $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/prefix.fcgi' } ]; + ok($tf->handle_http($t) == 0, 'SCRIPT_NAME w/ PATH_INFO'); $t->{REQUEST} = ( <<EOF -GET /get-server-env.php/foo?env=PATH_INFO HTTP/1.0 -Host: www.example.org +GET /prefix.fcgi/foo/bar?env=PATH_INFO HTTP/1.0 EOF ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo' } ]; - ok($tf->handle_http($t) == 0, '$_SERVER["PATH_INFO"]'); + $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo/bar' } ]; + ok($tf->handle_http($t) == 0, 'PATH_INFO'); - $t->{REQUEST} = ( <<EOF -GET /get-server-env.php?env=SERVER_NAME HTTP/1.0 + $t->{REQUEST} = ( <<EOF +GET /phpinfo.php HTTP/1.0 Host: www.example.org EOF ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ]; - ok($tf->handle_http($t) == 0, 'SERVER_NAME'); - - $t->{REQUEST} = ( <<EOF -GET /get-server-env.php?env=SERVER_NAME HTTP/1.0 -Host: foo.example.org -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ]; - ok($tf->handle_http($t) == 0, 'SERVER_NAME'); - - $t->{REQUEST} = ( <<EOF -GET /get-server-env.php?env=SERVER_NAME HTTP/1.0 -Host: vvv.example.org -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } ]; - ok($tf->handle_http($t) == 0, 'SERVER_NAME'); - - $t->{REQUEST} = ( <<EOF -GET /cgi.php/abc HTTP/1.0 -EOF - ); $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; - ok($tf->handle_http($t) == 0, 'PATHINFO'); - - if ($^O ne "cygwin") { - $t->{REQUEST} = ( <<EOF -GET /cgi.php%20%20%20 HTTP/1.0 -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ]; - ok($tf->handle_http($t) == 0, 'No source retrieval'); - } else { - ok(1, 'No source retrieval; skipped on cygwin; see response.c'); - } - - $t->{REQUEST} = ( <<EOF -GET /www/abc/def HTTP/1.0 -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ]; - ok($tf->handle_http($t) == 0, 'PATHINFO on a directory'); - - $t->{REQUEST} = ( <<EOF -GET /indexfile/ HTTP/1.0 -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/indexfile/index.php' } ]; - ok($tf->handle_http($t) == 0, 'PHP_SELF + Indexfile, Bug #3'); - - $t->{REQUEST} = ( <<EOF -GET /prefix.fcgi?var=SCRIPT_NAME HTTP/1.0 -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/prefix.fcgi' } ]; - ok($tf->handle_http($t) == 0, 'PATH_INFO, check-local off'); - - $t->{REQUEST} = ( <<EOF -GET /prefix.fcgi/foo/bar?var=SCRIPT_NAME HTTP/1.0 -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/prefix.fcgi' } ]; - ok($tf->handle_http($t) == 0, 'PATH_INFO, check-local off'); - - $t->{REQUEST} = ( <<EOF -GET /prefix.fcgi/foo/bar?var=PATH_INFO HTTP/1.0 -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo/bar' } ]; - ok($tf->handle_http($t) == 0, 'PATH_INFO, check-local off'); + ok($tf->handle_http($t) == 0, 'valid request'); $t->{REQUEST} = ( <<EOF -GET /sendfile.php?range=0- HTTP/1.0 +GET /get-server-env.php?env=USER HTTP/1.0 +Host: bin-env.example.org EOF ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => 4348 } ]; - ok($tf->handle_http($t) == 0, 'X-Sendfile2'); + $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 , 'HTTP-Content' => $ENV{USER} } ]; + ok($tf->handle_http($t) == 0, 'FastCGI + bin-copy-environment'); $t->{REQUEST} = ( <<EOF -GET /sendfile.php?range=0-4&range2=5- HTTP/1.0 +GET /get-server-env.php?env=MAIL HTTP/1.0 +Host: bin-env.example.org EOF ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => 4348 } ]; - ok($tf->handle_http($t) == 0, 'X-Sendfile2'); + $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 , 'HTTP-Content' => '' } ]; + ok($tf->handle_http($t) == 0, 'FastCGI + bin-copy-environment'); $t->{REQUEST} = ( <<EOF GET /get-server-env.php?env=REMOTE_USER HTTP/1.0 @@ -194,58 +94,6 @@ EOF ok($tf->handle_http($t) == 0, '$_SERVER["AUTH_TYPE"]'); $t->{REQUEST} = ( <<EOF -GET /indexfile/ HTTP/1.0 -Host: www.example.org -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/indexfile/index.php' } ]; - ok($tf->handle_http($t) == 0, 'Bug #6'); - - $t->{REQUEST} = ( <<EOF -POST /indexfile/abc HTTP/1.0 -Host: www.example.org -Content-Length: 0 -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => '/indexfile/return-404.php' } ]; - ok($tf->handle_http($t) == 0, 'Bug #12'); - - $t->{REQUEST} = ( <<EOF -GET /indexfile/index.php HTTP/1.0 -Host: bin-env.example.org -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; - ok($tf->handle_http($t) == 0, 'FastCGI + local spawning'); - - $t->{REQUEST} = ( <<EOF -HEAD /indexfile/index.php HTTP/1.0 -Host: bin-env.example.org -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '-Content-Length' => '0' } ]; - # Of course a valid content-length != 0 would be ok, but we assume for now that such one is not generated. - ok($tf->handle_http($t) == 0, 'Check for buggy content length with HEAD'); - - $t->{REQUEST} = ( <<EOF -GET /get-env.php?env=MAIL HTTP/1.0 -Host: bin-env.example.org -EOF - ); - $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 , 'HTTP-Content' => '' } ]; - ok($tf->handle_http($t) == 0, 'FastCGI + bin-copy-environment'); - - ok($tf->stop_proc == 0, "Stopping lighttpd"); -} - -SKIP: { - skip "no fcgi-responder found", 15 - unless ( -x $tf->{BASEDIR}."/tests/fcgi-responder" - || -x $tf->{BASEDIR}."/tests/fcgi-responder.exe"); - - $tf->{CONFIGFILE} = 'fastcgi-responder.conf'; - ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die(); - $t->{REQUEST} = ( <<EOF GET /index.html?auth-ok HTTP/1.0 Host: auth.example.org EOF @@ -318,7 +166,7 @@ EOF ok($tf->handle_http($t) == 0, 'line-ending \r\n + \r\n'); $t->{REQUEST} = ( <<EOF -GET /abc/def/ghi?path_info HTTP/1.0 +GET /abc/def/ghi?env=PATH_INFO HTTP/1.0 Host: wsgi.example.org EOF ); @@ -326,7 +174,7 @@ EOF ok($tf->handle_http($t) == 0, 'PATH_INFO (wsgi)'); $t->{REQUEST} = ( <<EOF -GET /abc/def/ghi?script_name HTTP/1.0 +GET /abc/def/ghi?env=SCRIPT_NAME HTTP/1.0 Host: wsgi.example.org EOF ); @@ -358,9 +206,3 @@ EOF ok($tf->stop_proc == 0, "Stopping lighttpd"); } - -exit 0; - -cleanup: ; - -die(); diff --git a/tests/mod-scgi.t b/tests/mod-scgi.t index 12c11a80..3b30249c 100755 --- a/tests/mod-scgi.t +++ b/tests/mod-scgi.t @@ -51,7 +51,7 @@ EOF ok($tf->handle_http($t) == 0, 'line-ending \r\n + \r\n'); $t->{REQUEST} = ( <<EOF -GET /abc/def/ghi?path_info HTTP/1.0 +GET /abc/def/ghi?env=PATH_INFO HTTP/1.0 Host: wsgi.example.org EOF ); @@ -59,7 +59,7 @@ EOF ok($tf->handle_http($t) == 0, 'PATH_INFO (wsgi)'); $t->{REQUEST} = ( <<EOF -GET /abc/def/ghi?script_name HTTP/1.0 +GET /abc/def/ghi?env=SCRIPT_NAME HTTP/1.0 Host: wsgi.example.org EOF ); diff --git a/tests/prepare.sh b/tests/prepare.sh index 14d94eaa..0aa3ace9 100755 --- a/tests/prepare.sh +++ b/tests/prepare.sh @@ -16,34 +16,29 @@ tmpdir="${top_builddir}/tests/tmp/lighttpd" # create test-framework rm -rf "${tmpdir}" -mkdir -p "${tmpdir}/servers/www.example.org/pages/" -mkdir -p "${tmpdir}/servers/www.example.org/pages/dummydir/" -mkdir -p "${tmpdir}/servers/www.example.org/pages/~test ä_/" -mkdir -p "${tmpdir}/servers/www.example.org/pages/go/" -mkdir -p "${tmpdir}/servers/www.example.org/pages/expire/" -mkdir -p "${tmpdir}/servers/www.example.org/pages/indexfile/" -mkdir -p "${tmpdir}/servers/123.example.org/pages/" -mkdir -p "${tmpdir}/servers/a.example.org/pages/a/" -mkdir -p "${tmpdir}/servers/b.example.org/pages/b/" -mkdir -p "${tmpdir}/logs/" -mkdir -p "${tmpdir}/cache/" -mkdir -p "${tmpdir}/cache/compress/" +mkdir -p "${tmpdir}/servers/www.example.org/pages/" \ + "${tmpdir}/servers/www.example.org/pages/dummydir/" \ + "${tmpdir}/servers/www.example.org/pages/~test ä_/" \ + "${tmpdir}/servers/www.example.org/pages/expire/" \ + "${tmpdir}/servers/www.example.org/pages/indexfile/" \ + "${tmpdir}/servers/123.example.org/pages/" \ + "${tmpdir}/servers/a.example.org/pages/a/" \ + "${tmpdir}/servers/b.example.org/pages/b/" \ + "${tmpdir}/logs/" \ + "${tmpdir}/cache/" \ + "${tmpdir}/cache/compress/" # copy everything into the right places cp "${srcdir}/docroot/www/"*.html \ - "${srcdir}/docroot/www/"*.php \ "${srcdir}/docroot/www/"*.pl \ "${srcdir}/docroot/www/"*.fcgi \ "${srcdir}/docroot/www/"*.shtml \ "${srcdir}/docroot/www/"*.txt \ "${tmpdir}/servers/www.example.org/pages/" -cp "${srcdir}/docroot/www/go/"*.php "${tmpdir}/servers/www.example.org/pages/go/" cp "${srcdir}/docroot/www/expire/"*.txt "${tmpdir}/servers/www.example.org/pages/expire/" -cp "${srcdir}/docroot/www/indexfile/"*.php "${tmpdir}/servers/www.example.org/pages/indexfile/" cp "${srcdir}/docroot/www/indexfile/"*.pl "${tmpdir}/servers/www.example.org/pages/indexfile/" cp "${srcdir}/docroot/123/"*.txt \ "${srcdir}/docroot/123/"*.html \ - "${srcdir}/docroot/123/"*.php \ "${srcdir}/docroot/123/"*.bla \ "${tmpdir}/servers/123.example.org/pages/" cp "${srcdir}/lighttpd.user" "${tmpdir}/" @@ -57,5 +52,6 @@ touch "${tmpdir}/servers/www.example.org/pages/image.jpg" \ echo "12345" > "${tmpdir}/servers/123.example.org/pages/range.pdf" printf "%-40s" "preparing infrastructure" +[ -z "$MAKELEVEL" ] && echo exit 0 diff --git a/tests/request.t b/tests/request.t index ba001ad8..2f5ebc8b 100755 --- a/tests/request.t +++ b/tests/request.t @@ -8,7 +8,7 @@ BEGIN { use strict; use IO::Socket; -use Test::More tests => 52; +use Test::More tests => 53; use LightyTest; my $tf = LightyTest->new(); @@ -524,6 +524,13 @@ EOF $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ]; ok($tf->handle_http($t) == 0, 'static file with forbidden pathinfo'); +$t->{REQUEST} = ( <<EOF +GET /www/abc/def HTTP/1.0 +EOF + ); +$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ]; +ok($tf->handle_http($t) == 0, 'pathinfo on a directory'); + $t->{REQUEST} = ( <<EOF GET /12345.txt HTTP/1.1 diff --git a/tests/scgi-responder.c b/tests/scgi-responder.c index 36529831..9ec86dd5 100644 --- a/tests/scgi-responder.c +++ b/tests/scgi-responder.c @@ -193,10 +193,8 @@ scgi_process (const int fd) if (NULL == p) cdata = NULL; - else if (0 == strcmp(p, "path_info")) - cdata = scgi_getenv(r, rlen, "PATH_INFO"); - else if (0 == strcmp(p, "script_name")) - cdata = scgi_getenv(r, rlen, "SCRIPT_NAME"); + else if (0 == strncmp(p, "env=", 4)) + cdata = scgi_getenv(r, rlen, p+4); else cdata = "test123"; |