summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Rückert <darix@opensu.se>2007-08-12 21:04:14 +0000
committerMarcus Rückert <darix@opensu.se>2007-08-12 21:04:14 +0000
commit420abdb295dcd5b6531bce4ba9d9b9f3e6f5eacd (patch)
tree57d12ab8bd44051b35d389c887244d3e45fca28d
parent58ea3c14c548b1df77d3dc07245bf6e5d68da7b5 (diff)
downloadlighttpd-git-420abdb295dcd5b6531bce4ba9d9b9f3e6f5eacd.tar.gz
- added test cases for 404 handler
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@1894 152afb58-edef-0310-8abb-c4023f1b3aa9
-rw-r--r--tests/404-handler.conf40
-rw-r--r--tests/core-404-handler.t57
-rw-r--r--tests/docroot/www/404.html1
-rw-r--r--tests/docroot/www/404.pl24
4 files changed, 122 insertions, 0 deletions
diff --git a/tests/404-handler.conf b/tests/404-handler.conf
new file mode 100644
index 00000000..ef2ee410
--- /dev/null
+++ b/tests/404-handler.conf
@@ -0,0 +1,40 @@
+debug.log-request-handling = "enable"
+
+server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
+server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
+
+## 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.name = "www.example.org"
+server.tag = "Apache 1.3.29"
+
+
+server.modules = (
+ "mod_cgi",
+ "mod_accesslog" )
+
+######################## MODULE CONFIG ############################
+
+
+accesslog.filename = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.access.log"
+
+mimetype.assign = ( ".html" => "text/html" )
+
+cgi.assign = (".pl" => "/usr/bin/perl" )
+
+$HTTP["url"] =~ "^/static/" {
+ server.error-handler-404 = "/404.html"
+}
+else $HTTP["url"] =~ "^/dynamic/200/" {
+ server.error-handler-404 = "/404.pl"
+}
+else $HTTP["url"] =~ "^/dynamic/302/" {
+ server.error-handler-404 = "/404.pl"
+}
+else $HTTP["url"] =~ "^/dynamic/404/" {
+ server.error-handler-404 = "/404.pl"
+}
diff --git a/tests/core-404-handler.t b/tests/core-404-handler.t
new file mode 100644
index 00000000..002e6fb8
--- /dev/null
+++ b/tests/core-404-handler.t
@@ -0,0 +1,57 @@
+#!/usr/bin/env perl
+#
+# combinations we have to test:
+# plain 404 case
+# 404-handler -> static file (verify content)
+# 404-handler -> fastcgi
+# returning 200
+# returning 302 + Location
+# returning 404
+#
+BEGIN {
+ # add current source dir to the include-path
+ # we need this for make distcheck
+ (my $srcdir = $0) =~ s#/[^/]+$#/#;
+ unshift @INC, $srcdir;
+}
+
+use strict;
+use IO::Socket;
+use Test::More tests => 6;
+use LightyTest;
+
+my $tf = LightyTest->new();
+my $t;
+$tf->{CONFIGFILE} = '404-handler.conf';
+ok($tf->start_proc == 0, "Starting lighttpd") or die();
+
+$t->{REQUEST} = ( <<EOF
+GET /static/notfound HTTP/1.0
+EOF
+ );
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => "static not found\n" } ];
+ok($tf->handle_http($t) == 0, '404 handler => static');
+
+$t->{REQUEST} = ( <<EOF
+GET /dynamic/200/notfound HTTP/1.0
+EOF
+ );
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => "found here\n" } ];
+ok($tf->handle_http($t) == 0, '404 handler => dynamic(200)');
+
+$t->{REQUEST} = ( <<EOF
+GET /dynamic/302/notfound HTTP/1.0
+EOF
+ );
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => "http://www.example.org/" } ];
+ok($tf->handle_http($t) == 0, '404 handler => dynamic(302)');
+
+$t->{REQUEST} = ( <<EOF
+GET /dynamic/200/notfound HTTP/1.0
+EOF
+ );
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => "Not found here\n" } ];
+ok($tf->handle_http($t) == 0, '404 handler => dynamic(200)');
+
+ok($tf->stop_proc == 0, "Stopping lighttpd");
+
diff --git a/tests/docroot/www/404.html b/tests/docroot/www/404.html
new file mode 100644
index 00000000..ce72e899
--- /dev/null
+++ b/tests/docroot/www/404.html
@@ -0,0 +1 @@
+static not found
diff --git a/tests/docroot/www/404.pl b/tests/docroot/www/404.pl
new file mode 100644
index 00000000..4260e32e
--- /dev/null
+++ b/tests/docroot/www/404.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+use CGI qw/:standard/;
+my $cgi = new CGI;
+my $request_uri = $ENV{'REQUEST_URI'};
+print (STDERR "REQUEST_URI: $request_uri\n");
+if ($request_uri =~ m/^\/dynamic\/200\// ) {
+ print header ( -status => 200,
+ -type => 'text/plain' );
+ print ("found here\n");
+}
+elsif ($request_uri =~ m|^/dynamic/301/| ) {
+ print header( -status=>302,
+ -location => 'http://www.example.org/');
+}
+elsif ($request_uri =~ m/^\/dynamic\/404\// ) {
+ print header ( -status => 404
+ -type => 'text/plain' );
+ print ("Not found here\n");
+}
+else {
+ print header ( -status => 404,
+ -type => 'text/plain');
+ print ("huh\n");
+};