summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kneschke <jan@kneschke.de>2005-06-15 09:37:18 +0000
committerJan Kneschke <jan@kneschke.de>2005-06-15 09:37:18 +0000
commit7a25f1b5f54620b5e890b63a1d8d6f56da97e3b8 (patch)
treedd06be40c0ab441483ee73835e152f82210037d1
parentaff653fdba46dc4687f1d66fe2bc642c11d4c2ac (diff)
downloadlighttpd-git-7a25f1b5f54620b5e890b63a1d8d6f56da97e3b8.tar.gz
Unified all tests to use the LighyTest framework
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.3.x@388 152afb58-edef-0310-8abb-c4023f1b3aa9
-rwxr-xr-xtests/LightyTest.pm239
-rwxr-xr-xtests/core-request.t346
-rwxr-xr-xtests/core-response.t256
-rwxr-xr-xtests/core.t266
-rwxr-xr-xtests/mod-access.t195
-rwxr-xr-xtests/mod-auth.t212
-rwxr-xr-xtests/mod-cgi.t212
-rwxr-xr-xtests/mod-compress.t212
-rwxr-xr-xtests/mod-fastcgi.t400
-rwxr-xr-xtests/mod-proxy.t232
-rwxr-xr-xtests/mod-redirect.t194
-rwxr-xr-xtests/mod-rewrite.t223
-rwxr-xr-xtests/mod-userdir.t206
-rwxr-xr-xtests/request.t344
14 files changed, 705 insertions, 2832 deletions
diff --git a/tests/LightyTest.pm b/tests/LightyTest.pm
new file mode 100755
index 00000000..2fa43370
--- /dev/null
+++ b/tests/LightyTest.pm
@@ -0,0 +1,239 @@
+#! /usr/bin/perl -w
+
+package LightyTest;
+use strict;
+use IO::Socket;
+use Test::More;
+
+sub new {
+ my $class = shift;
+ my $self = {};
+
+ $self->{CONFIGFILE} = 'lighttpd.conf';
+ $self->{BASEDIR} = (defined $ENV{'top_builddir'} ? $ENV{'top_builddir'} : '..');
+ $self->{SRCDIR} = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
+
+ $self->{LIGHTTPD_PATH} = $self->{BASEDIR}.'/src/lighttpd';
+ $self->{LIGHTTPD_PIDFILE} = '/tmp/lighttpd/lighttpd.pid';
+ $self->{PIDOF_PIDFILE} = '/tmp/lighttpd/pidof.pid';
+ $self->{PORT} = 2048;
+
+ bless($self, $class);
+
+ return $self;
+}
+
+sub pidof {
+ my $self = shift;
+ my $prog = shift;
+
+ open F, "ps ax | grep $prog | grep -v grep | awk '{ print \$1 }'|" or
+ open F, "ps -ef | grep $prog | grep -v grep | awk '{ print \$2 }'|" or
+ return -1;
+
+ my $pid = <F>;
+ close F;
+
+ if (defined $pid) { return $pid; }
+
+ return -1;
+}
+
+sub stop_proc {
+ my $self = shift;
+
+ open F, $self->{LIGHTTPD_PIDFILE} or return -1;
+ my $pid = <F>;
+ close F;
+
+ if (defined $pid) {
+ kill('TERM',$pid) or return -1;
+ select(undef, undef, undef, 0.01);
+ }
+
+ return 0;
+}
+
+
+sub start_proc {
+ my $self = shift;
+ # kill old proc if necessary
+ $self->stop_proc;
+
+ # pre-process configfile if necessary
+ #
+
+ my $pwd = `pwd`;
+ chomp($pwd);
+ unlink("/tmp/cfg.file");
+ system("cat ".$self->{SRCDIR}."/".$self->{CONFIGFILE}.' | perl -pe "s#\@SRCDIR\@#'.$pwd.'/'.$self->{BASEDIR}.'/tests/#" > /tmp/cfg.file');
+
+ unlink($self->{LIGHTTPD_PIDFILE});
+ system($self->{LIGHTTPD_PATH}." -f /tmp/cfg.file");
+ # system("valgrind --tool=memcheck --show-reachable=yes --leak-check=yes --logfile=foo ".$lighttpd_path." -D -f /tmp/cfg.file &");
+
+ sleep(1);
+
+ unlink("/tmp/cfg.file");
+
+ # no pidfile, we failed
+ if (not -e $self->{LIGHTTPD_PIDFILE}) {
+ diag(sprintf('Could not find pidfile: %s', $self->{LIGHTTPD_PIDFILE}));
+ return -1;
+ }
+
+ # the process is gone, we failed
+ if (0 == kill 0, `cat $self->{LIGHTTPD_PIDFILE}`) {
+ diag(sprintf('the process referenced by %s is not up', $self->{LIGHTTPD_PIDFILE}));
+ return -1;
+ }
+
+ 0;
+}
+
+sub handle_http {
+ my $self = shift;
+ my $t = shift;
+ my $EOL = "\015\012";
+ my $BLANK = $EOL x 2;
+ my $host = "127.0.0.1";
+
+ my @request = $t->{REQUEST};
+ my @response = $t->{RESPONSE};
+
+ my $remote =
+ IO::Socket::INET->new(Proto => "tcp",
+ PeerAddr => $host,
+ PeerPort => $self->{PORT})
+ or return -1;
+
+ $remote->autoflush(1);
+
+ foreach(@request) {
+ # pipeline requests
+ s/\r//g;
+ s/\n/$EOL/g;
+
+ print $remote $_.$BLANK;
+ }
+
+ my $lines = "";
+
+ # read everything
+ while(<$remote>) {
+ $lines .= $_;
+ }
+
+ close $remote;
+
+ my $href;
+ foreach $href (@response) {
+ # first line is always response header
+ my %resp_hdr;
+ my $resp_body;
+ my $resp_line;
+ my $conditions = $_;
+
+ for (my $ln = 0; defined $lines; $ln++) {
+ (my $line, $lines) = split($EOL, $lines, 2);
+
+ # header finished
+ last if(length($line) == 0);
+
+ if ($ln == 0) {
+ # response header
+ $resp_line = $line;
+ } else {
+ # response vars
+
+ if ($line =~ /^([^:]+):\s*(.+)$/) {
+ (my $h = $1) =~ tr/[A-Z]/[a-z]/;
+
+ $resp_hdr{$h} = $2;
+ } else {
+ return -1;
+ }
+ }
+ }
+
+ # check length
+ if (defined $resp_hdr{"content-length"}) {
+ ($resp_body, $lines) = split("^.".$resp_hdr{"content-length"}, $lines, 2);
+ } else {
+ $resp_body = $lines;
+ undef $lines;
+ }
+
+ # check conditions
+ if ($resp_line =~ /^(HTTP\/1\.[01]) ([0-9]{3}) .+$/) {
+ if ($href->{'HTTP-Protocol'} ne $1) {
+ diag(sprintf("proto failed: expected '%s', got '%s'\n", $href->{'HTTP-Protocol'}, $1));
+ return -1;
+ }
+ if ($href->{'HTTP-Status'} ne $2) {
+ diag(sprintf("status failed: expected '%s', got '%s'\n", $href->{'HTTP-Status'}, $2));
+ return -1;
+ }
+ } else {
+ return -1;
+ }
+
+ if (defined $href->{'HTTP-Content'}) {
+ if ($href->{'HTTP-Content'} ne $resp_body) {
+ diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body));
+ return -1;
+ }
+ }
+
+ if (defined $href->{'-HTTP-Content'}) {
+ if (defined $resp_body && $resp_body ne '') {
+ diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body));
+ return -1;
+ }
+ }
+
+ foreach (keys %{ $href }) {
+ next if $_ eq 'HTTP-Protocol';
+ next if $_ eq 'HTTP-Status';
+ next if $_ eq 'HTTP-Content';
+ next if $_ eq '-HTTP-Content';
+
+ (my $k = $_) =~ tr/[A-Z]/[a-z]/;
+
+ my $no_val = 0;
+
+ if (substr($k, 0, 1) eq '+') {
+ $k = substr($k, 1);
+ $no_val = 1;
+
+ }
+
+ if (!defined $resp_hdr{$k}) {
+ diag(sprintf("required header '%s' is missing\n", $k));
+ return -1;
+ }
+
+ if ($no_val == 0) {
+ if ($href->{$_} =~ /^\/(.+)\/$/) {
+ if ($resp_hdr{$k} !~ /$1/) {
+ diag(sprintf("response-header failed: expected '%s', got '%s', regex: %s\n",
+ $href->{$_}, $resp_hdr{$k}, $1));
+ return -1;
+ }
+ } elsif ($href->{$_} ne $resp_hdr{$k}) {
+ diag(sprintf("response-header failed: expected '%s', got '%s'\n",
+ $href->{$_}, $resp_hdr{$k}));
+ return -1;
+ }
+ }
+ }
+ }
+
+ # we should have sucked up everything
+ return -1 if (defined $lines);
+
+ return 0;
+}
+
+1;
+
diff --git a/tests/core-request.t b/tests/core-request.t
index e2fe0965..690c64c4 100755
--- a/tests/core-request.t
+++ b/tests/core-request.t
@@ -3,411 +3,233 @@
use strict;
use IO::Socket;
use Test::More tests => 28;
+use LightyTest;
-my $basedir = (defined $ENV{'top_builddir'} ? $ENV{'top_builddir'} : '..');
-my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
-
-my $testname;
-my @request;
-my @response;
-my $configfile = $srcdir.'/lighttpd.conf';
-my $lighttpd_path = $basedir.'/src/lighttpd';
-my $pidfile = '/tmp/lighttpd/lighttpd.pid';
-my $pidoffile = '/tmp/lighttpd/pidof.pid';
-
-sub pidof {
- my $prog = $_[0];
-
- open F, "ps ax | grep $prog | awk '{ print \$1 }'|" or
- open F, "ps -ef | grep $prog | awk '{ print \$2 }'|" or
- return -1;
-
- my $pid = <F>;
- close F;
-
- return $pid;
-}
-
-sub stop_proc {
- open F, $pidfile or return -1;
- my $pid = <F>;
- close F;
-
- kill('TERM',$pid) or return -1;
- select(undef, undef, undef, 0.01);
-
- return 0;
-}
-
-
-sub start_proc {
- # kill old proc if necessary
- stop_proc;
-
- unlink($pidfile);
- system($lighttpd_path." -f ".$configfile);
-
- if (-e $pidfile) {
- return 0;
- } else {
- return -1;
- }
-}
-
-sub handle_http {
- my $EOL = "\015\012";
- my $BLANK = $EOL x 2;
- my $port = 2048;
- my $host = "127.0.0.1";
-
- my $remote =
- IO::Socket::INET->new(Proto => "tcp",
- PeerAddr => $host,
- PeerPort => $port)
- or return -1;
-
- $remote->autoflush(1);
-
- foreach(@request) {
- # pipeline requests
- s/\r//g;
- s/\n/$EOL/g;
-
- print $remote $_.$BLANK;
- }
-
- my $lines = "";
-
- # read everything
- while(<$remote>) {
- $lines .= $_;
- }
-
- close $remote;
-
- my $href;
- foreach $href (@response) {
- # first line is always response header
- my %resp_hdr;
- my $resp_body;
- my $resp_line;
- my $conditions = $_;
-
- for (my $ln = 0; defined $lines; $ln++) {
- (my $line, $lines) = split($EOL, $lines, 2);
-
- # header finished
- last if(length($line) == 0);
-
- if ($ln == 0) {
- # response header
- $resp_line = $line;
- } else {
- # response vars
-
- if ($line =~ /^([^:]+):\s*(.+)$/) {
- (my $h = $1) =~ tr/[A-Z]/[a-z]/;
-
- $resp_hdr{$h} = $2;
- } else {
- return -1;
- }
- }
- }
-
- # check length
- if (defined $resp_hdr{"content-length"}) {
- ($resp_body, $lines) = split("^.".$resp_hdr{"content-length"}, $lines, 2);
- } else {
- $resp_body = $lines;
- undef $lines;
- }
-
- # check conditions
- if ($resp_line =~ /^(HTTP\/1\.[01]) ([0-9]{3}) .+$/) {
- if ($href->{'HTTP-Protocol'} ne $1) {
- diag(sprintf("proto failed: expected '%s', got '%s'\n", $href->{'HTTP-Protocol'}, $1));
- return -1;
- }
- if ($href->{'HTTP-Status'} ne $2) {
- diag(sprintf("status failed: expected '%s', got '%s'\n", $href->{'HTTP-Status'}, $2));
- return -1;
- }
- } else {
- return -1;
- }
-
- if (defined $href->{'HTTP-Content'}) {
- if ($href->{'HTTP-Content'} ne $resp_body) {
- diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body));
- return -1;
- }
- }
-
- if (defined $href->{'-HTTP-Content'}) {
- if (defined $resp_body && $resp_body ne '') {
- diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body));
- return -1;
- }
- }
-
- foreach (keys %{ $href }) {
- next if $_ eq 'HTTP-Protocol';
- next if $_ eq 'HTTP-Status';
- next if $_ eq 'HTTP-Content';
- next if $_ eq '-HTTP-Content';
-
- (my $k = $_) =~ tr/[A-Z]/[a-z]/;
-
- my $no_val = 0;
-
- if (substr($k, 0, 1) eq '+') {
- $k = substr($k, 1);
- $no_val = 1;
-
- }
-
- if (!defined $resp_hdr{$k}) {
- diag(sprintf("required header '%s' is missing\n", $k));
- return -1;
- }
-
- if ($no_val == 0 &&
- $href->{$_} ne $resp_hdr{$k}) {
- diag(sprintf("response-header failed: expected '%s', got '%s'\n", $href->{$_}, $resp_hdr{$k}));
- return -1;
- }
- }
- }
-
- # we should have sucked up everything
- return -1 if (defined $lines);
-
- return 0;
-}
-
-ok(start_proc == 0, "Starting lighttpd") or die();
+my $tf = LightyTest->new();
+my $t;
+
+ok($tf->start_proc == 0, "Starting lighttpd") or die();
## Low-Level Request-Header Parsing - URI
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /index%2ehtml HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'URL-encoding');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'URL-encoding');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /index.html%00 HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
-ok(handle_http == 0, 'URL-encoding, %00');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
+ok($tf->handle_http($t) == 0, 'URL-encoding, %00');
## Low-Level Request-Header Parsing - Host
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: www.example.org
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'hostname');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'hostname');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: 127.0.0.1
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'IPv4 address');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'IPv4 address');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: [::1]
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'IPv6 address');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'IPv6 address');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: www.example.org:80
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'hostname + port');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'hostname + port');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: 127.0.0.1:80
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'IPv4 address + port');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'IPv4 address + port');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: [::1]:80
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'IPv6 address + port');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'IPv6 address + port');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: ../123.org
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'directory traversal');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'directory traversal');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: .jsdh.sfdg.sdfg.
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'leading and trailing dot');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'leading and trailing dot');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: jsdh.sfdg.sdfg.
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'trailing dot is ok');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'trailing dot is ok');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: .jsdh.sfdg.sdfg
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'leading dot');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'leading dot');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: jsdh..sfdg.sdfg
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'two dots');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'two dots');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: jsdh.sfdg.sdfg:asd
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'broken port-number');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'broken port-number');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: jsdh.sfdg.sdfg:-1
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'negative port-number');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'negative port-number');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: :80
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'port given but host missing');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'port given but host missing');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: .jsdh.sfdg.:sdfg.
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'port and host are broken');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'port and host are broken');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: a.b-c.d123
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'allowed characters in host-name');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'allowed characters in host-name');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: -a.c
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'leading dash');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'leading dash');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: .
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'dot only');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'dot only');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: a192.168.2.10:1234
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'broken IPv4 address - non-digit');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'broken IPv4 address - non-digit');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: 192.168.2:1234
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'broken IPv4 address - too short');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'broken IPv4 address - too short');
## Low-Level Request-Header Parsing - Content-Length
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /index.html HTTP/1.0
Content-Length: -2
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'negative Content-Length');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'negative Content-Length');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
POST /12345.txt HTTP/1.0
Host: 123.example.org
Content-Length: 2147483648
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 413 } );
-ok(handle_http == 0, 'Content-Length > max-request-size');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 413 } );
+ok($tf->handle_http($t) == 0, 'Content-Length > max-request-size');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
POST /12345.txt HTTP/1.0
Host: 123.example.org
Content-Length:
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 411 } );
-ok(handle_http == 0, 'Content-Length is empty');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 411 } );
+ok($tf->handle_http($t) == 0, 'Content-Length is empty');
print "\nLow-Level Request-Header Parsing - HTTP/1.1\n";
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.1
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'Host missing');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'Host missing');
-ok(stop_proc == 0, "Stopping lighttpd");
+ok($tf->stop_proc == 0, "Stopping lighttpd");
diff --git a/tests/core-response.t b/tests/core-response.t
index 1d0d76b3..3be4618b 100755
--- a/tests/core-response.t
+++ b/tests/core-response.t
@@ -3,286 +3,100 @@
use strict;
use IO::Socket;
use Test::More tests => 12;
+use LightyTest;
-my $basedir = (defined $ENV{'top_builddir'} ? $ENV{'top_builddir'} : '..');
-my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
-
-my $testname;
-my @request;
-my @response;
-my $configfile = $srcdir.'/lighttpd.conf';
-my $lighttpd_path = $basedir.'/src/lighttpd';
-my $pidfile = '/tmp/lighttpd/lighttpd.pid';
-my $pidoffile = '/tmp/lighttpd/pidof.pid';
-
-sub pidof {
- my $prog = $_[0];
-
- open F, "ps ax | grep $prog | awk '{ print \$1 }'|" or
- open F, "ps -ef | grep $prog | awk '{ print \$2 }'|" or
- return -1;
-
- my $pid = <F>;
- close F;
-
- return $pid;
-}
-
-sub stop_proc {
- open F, $pidfile or return -1;
- my $pid = <F>;
- close F;
-
- kill('TERM',$pid) or return -1;
- select(undef, undef, undef, 0.01);
-
- return 0;
-}
-
-
-sub start_proc {
- # kill old proc if necessary
- stop_proc;
-
- unlink($pidfile);
- system($lighttpd_path." -f ".$configfile);
-
- if (-e $pidfile) {
- return 0;
- } else {
- return -1;
- }
-}
-
-sub handle_http {
- my $EOL = "\015\012";
- my $BLANK = $EOL x 2;
- my $port = 2048;
- my $host = "127.0.0.1";
-
- my $remote =
- IO::Socket::INET->new(Proto => "tcp",
- PeerAddr => $host,
- PeerPort => $port)
- or return -1;
-
- $remote->autoflush(1);
-
- foreach(@request) {
- # pipeline requests
- s/\r//g;
- s/\n/$EOL/g;
-
- print $remote $_.$BLANK;
- }
-
- my $lines = "";
-
- # read everything
- while(<$remote>) {
- $lines .= $_;
- }
-
- close $remote;
-
- my $href;
- foreach $href (@response) {
- # first line is always response header
- my %resp_hdr;
- my $resp_body;
- my $resp_line;
- my $conditions = $_;
-
- for (my $ln = 0; defined $lines; $ln++) {
- (my $line, $lines) = split($EOL, $lines, 2);
-
- # header finished
- last if(length($line) == 0);
-
- if ($ln == 0) {
- # response header
- $resp_line = $line;
- } else {
- # response vars
-
- if ($line =~ /^([^:]+):\s*(.+)$/) {
- (my $h = $1) =~ tr/[A-Z]/[a-z]/;
-
- $resp_hdr{$h} = $2;
- } else {
- return -1;
- }
- }
- }
-
- # check length
- if (defined $resp_hdr{"content-length"}) {
- ($resp_body, $lines) = split("^.".$resp_hdr{"content-length"}, $lines, 2);
- } else {
- $resp_body = $lines;
- undef $lines;
- }
-
- # check conditions
- if ($resp_line =~ /^(HTTP\/1\.[01]) ([0-9]{3}) .+$/) {
- if ($href->{'HTTP-Protocol'} ne $1) {
- diag(sprintf("proto failed: expected '%s', got '%s'\n", $href->{'HTTP-Protocol'}, $1));
- return -1;
- }
- if ($href->{'HTTP-Status'} ne $2) {
- diag(sprintf("status failed: expected '%s', got '%s'\n", $href->{'HTTP-Status'}, $2));
- return -1;
- }
- } else {
- return -1;
- }
-
- if (defined $href->{'HTTP-Content'}) {
- if ($href->{'HTTP-Content'} ne $resp_body) {
- diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body));
- return -1;
- }
- }
-
- if (defined $href->{'-HTTP-Content'}) {
- if (defined $resp_body && $resp_body ne '') {
- diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body));
- return -1;
- }
- }
-
- foreach (keys %{ $href }) {
- next if $_ eq 'HTTP-Protocol';
- next if $_ eq 'HTTP-Status';
- next if $_ eq 'HTTP-Content';
- next if $_ eq '-HTTP-Content';
-
- (my $k = $_) =~ tr/[A-Z]/[a-z]/;
-
- my $no_val = 0;
-
- if (substr($k, 0, 1) eq '+') {
- $k = substr($k, 1);
- $no_val = 1;
-
- }
-
- if (!defined $resp_hdr{$k}) {
- diag(sprintf("required header '%s' is missing\n", $k));
- return -1;
- }
-
- if ($no_val == 0) {
- if ($href->{$_} =~ /^\/(.+)\/$/) {
- if ($resp_hdr{$k} !~ /$1/) {
- diag(sprintf("response-header failed: expected '%s', got '%s', regex: %s\n",
- $href->{$_}, $resp_hdr{$k}, $1));
- return -1;
- }
- } elsif ($href->{$_} ne $resp_hdr{$k}) {
- diag(sprintf("response-header failed: expected '%s', got '%s'\n",
- $href->{$_}, $resp_hdr{$k}));
- return -1;
- }
- }
- }
- }
-
- # we should have sucked up everything
- return -1 if (defined $lines);
-
- return 0;
-}
+my $tf = LightyTest->new();
+my $t;
-ok(start_proc == 0, "Starting lighttpd") or die();
+ok($tf->start_proc == 0, "Starting lighttpd") or die();
## Low-Level Response-Header Parsing - HTTP/1.1
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.1
Host: www.example.org
Connection: close
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, '+Date' => '' } );
-ok(handle_http == 0, 'Date header');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, '+Date' => '' } );
+ok($tf->handle_http($t) == 0, 'Date header');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.1
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 400, 'Connection' => 'close' } );
-ok(handle_http == 0, 'Host missing');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 400, 'Connection' => 'close' } );
+ok($tf->handle_http($t) == 0, 'Host missing');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+ETag' => '' } );
-ok(handle_http == 0, 'ETag is set');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+ETag' => '' } );
+ok($tf->handle_http($t) == 0, 'ETag is set');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'ETag' => '/^".+"$/' } );
-ok(handle_http == 0, 'ETag has quotes');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'ETag' => '/^".+"$/' } );
+ok($tf->handle_http($t) == 0, 'ETag has quotes');
## Low-Level Response-Header Parsing - Content-Length
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /12345.html HTTP/1.0
Host: 123.example.org
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } );
-ok(handle_http == 0, 'Content-Length for text/html');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } );
+ok($tf->handle_http($t) == 0, 'Content-Length for text/html');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /12345.txt HTTP/1.0
Host: 123.example.org
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } );
-ok(handle_http == 0, 'Content-Length for text/plain');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } );
+ok($tf->handle_http($t) == 0, 'Content-Length for text/plain');
## Low-Level Response-Header Parsing - Location
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /dummydir HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:2048/dummydir/' } );
-ok(handle_http == 0, 'internal redirect in directory');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:2048/dummydir/' } );
+ok($tf->handle_http($t) == 0, 'internal redirect in directory');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /dummydir?foo HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:2048/dummydir/?foo' } );
-ok(handle_http == 0, 'internal redirect in directory + querystring');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:2048/dummydir/?foo' } );
+ok($tf->handle_http($t) == 0, 'internal redirect in directory + querystring');
## simple-vhost
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /12345.txt HTTP/1.0
Host: no-simple.example.org
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } );
-ok(handle_http == 0, 'disabling simple-vhost via conditionals');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } );
+ok($tf->handle_http($t) == 0, 'disabling simple-vhost via conditionals');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /12345.txt HTTP/1.0
Host: simple.example.org
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
-ok(handle_http == 0, 'simple-vhost via conditionals');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
+ok($tf->handle_http($t) == 0, 'simple-vhost via conditionals');
-ok(stop_proc == 0, "Stopping lighttpd");
+ok($tf->stop_proc == 0, "Stopping lighttpd");
diff --git a/tests/core.t b/tests/core.t
index 86ac45a7..3fb8e2b8 100755
--- a/tests/core.t
+++ b/tests/core.t
@@ -3,290 +3,112 @@
use strict;
use IO::Socket;
use Test::More tests => 15;
+use LightyTest;
-my $basedir = (defined $ENV{'top_builddir'} ? $ENV{'top_builddir'} : '..');
-my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
+my $tf = LightyTest->new();
+my $t;
-my $testname;
-my @request;
-my @response;
-my $configfile = $srcdir.'/lighttpd.conf';
-my $lighttpd_path = $basedir.'/src/lighttpd';
-my $pidfile = '/tmp/lighttpd/lighttpd.pid';
-my $pidoffile = '/tmp/lighttpd/pidof.pid';
+ok($tf->start_proc == 0, "Starting lighttpd") or die();
-sub pidof {
- my $prog = $_[0];
-
- open F, "ps ax | grep $prog | awk '{ print \$1 }'|" or
- open F, "ps -ef | grep $prog | awk '{ print \$2 }'|" or
- return -1;
-
- my $pid = <F>;
- close F;
-
- return $pid;
-}
-
-sub stop_proc {
- open F, $pidfile or return -1;
- my $pid = <F>;
- close F;
-
- kill('TERM',$pid) or return -1;
- select(undef, undef, undef, 0.01);
-
- return 0;
-}
-
-
-sub start_proc {
- # kill old proc if necessary
- stop_proc;
-
- unlink($pidfile);
- system($lighttpd_path." -f ".$configfile);
-
- if (-e $pidfile) {
- return 0;
- } else {
- return -1;
- }
-}
-
-sub handle_http {
- my $EOL = "\015\012";
- my $BLANK = $EOL x 2;
- my $port = 2048;
- my $host = "127.0.0.1";
-
- my $remote =
- IO::Socket::INET->new(Proto => "tcp",
- PeerAddr => $host,
- PeerPort => $port)
- or return -1;
-
- $remote->autoflush(1);
-
- foreach(@request) {
- # pipeline requests
- s/\r//g;
- s/\n/$EOL/g;
-
- print $remote $_.$BLANK;
- }
-
- my $lines = "";
-
- # read everything
- while(<$remote>) {
- $lines .= $_;
- }
-
- close $remote;
-
- my $href;
- foreach $href (@response) {
- # first line is always response header
- my %resp_hdr;
- my $resp_body;
- my $resp_line;
- my $conditions = $_;
-
- for (my $ln = 0; defined $lines; $ln++) {
- (my $line, $lines) = split($EOL, $lines, 2);
-
- # header finished
- last if(length($line) == 0);
-
- if ($ln == 0) {
- # response header
- $resp_line = $line;
- } else {
- # response vars
-
- if ($line =~ /^([^:]+):\s*(.+)$/) {
- (my $h = $1) =~ tr/[A-Z]/[a-z]/;
-
- $resp_hdr{$h} = $2;
- } else {
- return -1;
- }
- }
- }
-
- # check length
- if (defined $resp_hdr{"content-length"}) {
- ($resp_body, $lines) = split("^.".$resp_hdr{"content-length"}, $lines, 2);
- } else {
- $resp_body = $lines;
- undef $lines;
- }
-
- # check conditions
- if ($resp_line =~ /^(HTTP\/1\.[01]) ([0-9]{3}) .+$/) {
- if ($href->{'HTTP-Protocol'} ne $1) {
- diag(sprintf("proto failed: expected '%s', got '%s'\n", $href->{'HTTP-Protocol'}, $1));
- return -1;
- }
- if ($href->{'HTTP-Status'} ne $2) {
- diag(sprintf("status failed: expected '%s', got '%s'\n", $href->{'HTTP-Status'}, $2));
- return -1;
- }
- } else {
- return -1;
- }
-
- if (defined $href->{'HTTP-Content'}) {
- if ($href->{'HTTP-Content'} ne $resp_body) {
- diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body));
- return -1;
- }
- }
-
- if (defined $href->{'-HTTP-Content'}) {
- if (defined $resp_body && $resp_body ne '') {
- diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body));
- return -1;
- }
- }
-
- foreach (keys %{ $href }) {
- next if $_ eq 'HTTP-Protocol';
- next if $_ eq 'HTTP-Status';
- next if $_ eq 'HTTP-Content';
- next if $_ eq '-HTTP-Content';
-
- (my $k = $_) =~ tr/[A-Z]/[a-z]/;
-
- my $no_val = 0;
-
- if (substr($k, 0, 1) eq '+') {
- $k = substr($k, 1);
- $no_val = 1;
-
- }
-
- if (!defined $resp_hdr{$k}) {
- diag(sprintf("required header '%s' is missing\n", $k));
- return -1;
- }
-
- if ($no_val == 0 &&
- $href->{$_} ne $resp_hdr{$k}) {
- diag(sprintf("response-header failed: expected '%s', got '%s'\n", $href->{$_}, $resp_hdr{$k}));
- return -1;
- }
- }
- }
-
- # we should have sucked up everything
- return -1 if (defined $lines);
-
- return 0;
-}
-
-ok(start_proc == 0, "Starting lighttpd") or die();
-
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'Valid HTTP/1.0 Request') or die();
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'Valid HTTP/1.0 Request') or die();
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'missing Protocol');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'missing Protocol');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
BC /
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'missing protocol + unknown method');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'missing protocol + unknown method');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
ABC
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'missing protocol + unknown method + missing URI');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'missing protocol + unknown method + missing URI');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
ABC / HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 501 } );
-ok(handle_http == 0, 'unknown method');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 501 } );
+ok($tf->handle_http($t) == 0, 'unknown method');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.3
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 505 } );
-ok(handle_http == 0, 'unknown protocol');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 505 } );
+ok($tf->handle_http($t) == 0, 'unknown protocol');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET http://www.example.org/ HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'absolute URI');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'absolute URI');
print "\nLow-Level Request-Header Parsing\n";
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
ABC : foo
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'whitespace after key');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'whitespace after key');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
ABC a: foo
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'whitespace with-in key');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'whitespace with-in key');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
ABC:foo
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'no whitespace');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'no whitespace');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
ABC:foo
bc
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'line-folding');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'line-folding');
print "\nLow-Level Request-Header Parsing - URI\n";
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /index%2ehtml HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'URL-encoding');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'URL-encoding');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /index.html%00 HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
-ok(handle_http == 0, 'URL-encoding, %00');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
+ok($tf->handle_http($t) == 0, 'URL-encoding, %00');
-ok(stop_proc == 0, "Stopping lighttpd");
+ok($tf->stop_proc == 0, "Stopping lighttpd");
diff --git a/tests/mod-access.t b/tests/mod-access.t
index 8c978a89..4c0987db 100755
--- a/tests/mod-access.t
+++ b/tests/mod-access.t
@@ -3,198 +3,19 @@
use strict;
use IO::Socket;
use Test::More tests => 3;
+use LightyTest;
-my $basedir = (defined $ENV{'top_builddir'} ? $ENV{'top_builddir'} : '..');
-my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
-
-my $testname;
-my @request;
-my @response;
-my $configfile = $srcdir.'/lighttpd.conf';
-my $lighttpd_path = $basedir.'/src/lighttpd';
-my $pidfile = '/tmp/lighttpd/lighttpd.pid';
-my $pidoffile = '/tmp/lighttpd/pidof.pid';
-
-sub pidof {
- my $prog = $_[0];
-
- open F, "ps ax | grep $prog | awk '{ print \$1 }'|" or
- open F, "ps -ef | grep $prog | awk '{ print \$2 }'|" or
- return -1;
-
- my $pid = <F>;
- close F;
-
- return $pid;
-}
-
-sub stop_proc {
- open F, $pidfile or return -1;
- my $pid = <F>;
- close F;
-
- kill('TERM',$pid) or return -1;
- select(undef, undef, undef, 0.01);
-
- return 0;
-}
-
-
-sub start_proc {
- # kill old proc if necessary
- stop_proc;
-
- unlink($pidfile);
- system($lighttpd_path." -f ".$configfile);
-
- if (-e $pidfile) {
- return 0;
- } else {
- return -1;
- }
-}
-
-sub handle_http {
- my $EOL = "\015\012";
- my $BLANK = $EOL x 2;
- my $port = 2048;
- my $host = "127.0.0.1";
-
- my $remote =
- IO::Socket::INET->new(Proto => "tcp",
- PeerAddr => $host,
- PeerPort => $port)
- or return -1;
-
- $remote->autoflush(1);
-
- foreach(@request) {
- # pipeline requests
- s/\r//g;
- s/\n/$EOL/g;
-
- print $remote $_.$BLANK;
- }
-
- my $lines = "";
-
- # read everything
- while(<$remote>) {
- $lines .= $_;
- }
-
- close $remote;
-
- my $href;
- foreach $href (@response) {
- # first line is always response header
- my %resp_hdr;
- my $resp_body;
- my $resp_line;
- my $conditions = $_;
-
- for (my $ln = 0; defined $lines; $ln++) {
- (my $line, $lines) = split($EOL, $lines, 2);
-
- # header finished
- last if(length($line) == 0);
-
- if ($ln == 0) {
- # response header
- $resp_line = $line;
- } else {
- # response vars
-
- if ($line =~ /^([^:]+):\s*(.+)$/) {
- (my $h = $1) =~ tr/[A-Z]/[a-z]/;
-
- $resp_hdr{$h} = $2;
- } else {
- return -1;
- }
- }
- }
-
- # check length
- if (defined $resp_hdr{"content-length"}) {
- ($resp_body, $lines) = split("^.".$resp_hdr{"content-length"}, $lines, 2);
- } else {
- $resp_body = $lines;
- undef $lines;
- }
-
- # check conditions
- if ($resp_line =~ /^(HTTP\/1\.[01]) ([0-9]{3}) .+$/) {
- if ($href->{'HTTP-Protocol'} ne $1) {
- diag(sprintf("proto failed: expected '%s', got '%s'\n", $href->{'HTTP-Protocol'}, $1));
- return -1;
- }
- if ($href->{'HTTP-Status'} ne $2) {
- diag(sprintf("status failed: expected '%s', got '%s'\n", $href->{'HTTP-Status'}, $2));
- return -1;
- }
- } else {
- return -1;
- }
-
- if (defined $href->{'HTTP-Content'}) {
- if ($href->{'HTTP-Content'} ne $resp_body) {
- diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body));
- return -1;
- }
- }
-
- if (defined $href->{'-HTTP-Content'}) {
- if (defined $resp_body && $resp_body ne '') {
- diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body));
- return -1;
- }
- }
-
- foreach (keys %{ $href }) {
- next if $_ eq 'HTTP-Protocol';
- next if $_ eq 'HTTP-Status';
- next if $_ eq 'HTTP-Content';
- next if $_ eq '-HTTP-Content';
-
- (my $k = $_) =~ tr/[A-Z]/[a-z]/;
-
- my $no_val = 0;
-
- if (substr($k, 0, 1) eq '+') {
- $k = substr($k, 1);
- $no_val = 1;
-
- }
-
- if (!defined $resp_hdr{$k}) {
- diag(sprintf("required header '%s' is missing\n", $k));
- return -1;
- }
-
- if ($no_val == 0 &&
- $href->{$_} ne $resp_hdr{$k}) {
- diag(sprintf("response-header failed: expected '%s', got '%s'\n", $href->{$_}, $resp_hdr{$k}));
- return -1;
- }
- }
- }
-
- # we should have sucked up everything
- return -1 if (defined $lines);
-
- return 0;
-}
+my $tf = LightyTest->new();
+my $t;
-ok(start_proc == 0, "Starting lighttpd") or die();
-
+ok($tf->start_proc == 0, "Starting lighttpd") or die();
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /index.html~ HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } );
-ok(handle_http == 0, 'forbid access to ...~');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } );
+ok($tf->handle_http($t) == 0, 'forbid access to ...~');
-ok(stop_proc == 0, "Stopping lighttpd");
+ok($tf->stop_proc == 0, "Stopping lighttpd");
diff --git a/tests/mod-auth.t b/tests/mod-auth.t
index 731f07da..6e7b5483 100755
--- a/tests/mod-auth.t
+++ b/tests/mod-auth.t
@@ -3,225 +3,47 @@
use strict;
use IO::Socket;
use Test::More tests => 6;
+use LightyTest;
-my $basedir = (defined $ENV{'top_builddir'} ? $ENV{'top_builddir'} : '..');
-my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
-
-my $testname;
-my @request;
-my @response;
-my $configfile = $srcdir.'/lighttpd.conf';
-my $lighttpd_path = $basedir.'/src/lighttpd';
-my $pidfile = '/tmp/lighttpd/lighttpd.pid';
-my $pidoffile = '/tmp/lighttpd/pidof.pid';
-
-sub pidof {
- my $prog = $_[0];
-
- open F, "ps ax | grep $prog | awk '{ print \$1 }'|" or
- open F, "ps -ef | grep $prog | awk '{ print \$2 }'|" or
- return -1;
-
- my $pid = <F>;
- close F;
-
- return $pid;
-}
-
-sub stop_proc {
- open F, $pidfile or return -1;
- my $pid = <F>;
- close F;
-
- kill('TERM',$pid) or return -1;
- select(undef, undef, undef, 0.01);
-
- return 0;
-}
-
-
-sub start_proc {
- # kill old proc if necessary
- stop_proc;
-
- unlink($pidfile);
- system($lighttpd_path." -f ".$configfile);
-
- if (-e $pidfile) {
- return 0;
- } else {
- return -1;
- }
-}
-
-sub handle_http {
- my $EOL = "\015\012";
- my $BLANK = $EOL x 2;
- my $port = 2048;
- my $host = "127.0.0.1";
-
- my $remote =
- IO::Socket::INET->new(Proto => "tcp",
- PeerAddr => $host,
- PeerPort => $port)
- or return -1;
-
- $remote->autoflush(1);
-
- foreach(@request) {
- # pipeline requests
- s/\r//g;
- s/\n/$EOL/g;
-
- print $remote $_.$BLANK;
- }
-
- my $lines = "";
-
- # read everything
- while(<$remote>) {
- $lines .= $_;
- }
-
- close $remote;
-
- my $href;
- foreach $href (@response) {
- # first line is always response header
- my %resp_hdr;
- my $resp_body;
- my $resp_line;
- my $conditions = $_;
-
- for (my $ln = 0; defined $lines; $ln++) {
- (my $line, $lines) = split($EOL, $lines, 2);
-
- # header finished
- last if(length($line) == 0);
-
- if ($ln == 0) {
- # response header
- $resp_line = $line;
- } else {
- # response vars
-
- if ($line =~ /^([^:]+):\s*(.+)$/) {
- (my $h = $1) =~ tr/[A-Z]/[a-z]/;
-
- $resp_hdr{$h} = $2;
- } else {
- return -1;
- }
- }
- }
-
- # check length
- if (defined $resp_hdr{"content-length"}) {
- ($resp_body, $lines) = split("^.".$resp_hdr{"content-length"}, $lines, 2);
- } else {
- $resp_body = $lines;
- undef $lines;
- }
-
- # check conditions
- if ($resp_line =~ /^(HTTP\/1\.[01]) ([0-9]{3}) .+$/) {
- if ($href->{'HTTP-Protocol'} ne $1) {
- diag(sprintf("proto failed: expected '%s', got '%s'\n", $href->{'HTTP-Protocol'}, $1));
- return -1;
- }
- if ($href->{'HTTP-Status'} ne $2) {
- diag(sprintf("status failed: expected '%s', got '%s'\n", $href->{'HTTP-Status'}, $2));
- return -1;
- }
- } else {
- return -1;
- }
-
- if (defined $href->{'HTTP-Content'}) {
- if ($href->{'HTTP-Content'} ne $resp_body) {
- diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body));
- return -1;
- }
- }
-
- if (defined $href->{'-HTTP-Content'}) {
- if (defined $resp_body && $resp_body ne '') {
- diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body));
- return -1;
- }
- }
-
- foreach (keys %{ $href }) {
- next if $_ eq 'HTTP-Protocol';
- next if $_ eq 'HTTP-Status';
- next if $_ eq 'HTTP-Content';
- next if $_ eq '-HTTP-Content';
-
- (my $k = $_) =~ tr/[A-Z]/[a-z]/;
-
- my $no_val = 0;
-
- if (substr($k, 0, 1) eq '+') {
- $k = substr($k, 1);
- $no_val = 1;
-
- }
-
- if (!defined $resp_hdr{$k}) {
- diag(sprintf("required header '%s' is missing\n", $k));
- return -1;
- }
-
- if ($no_val == 0 &&
- $href->{$_} ne $resp_hdr{$k}) {
- diag(sprintf("response-header failed: expected '%s', got '%s'\n", $href->{$_}, $resp_hdr{$k}));
- return -1;
- }
- }
- }
-
- # we should have sucked up everything
- return -1 if (defined $lines);
-
- return 0;
-}
+my $tf = LightyTest->new();
+my $t;
-ok(start_proc == 0, "Starting lighttpd") or die();
+ok($tf->start_proc == 0, "Starting lighttpd") or die();
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /server-status HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } );
-ok(handle_http == 0, 'Missing Auth-token');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } );
+ok($tf->handle_http($t) == 0, 'Missing Auth-token');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /server-status HTTP/1.0
Authorization: Basic amFuOmphb
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } );
-ok(handle_http == 0, 'Basic-Auth: Wrong Auth-token');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } );
+ok($tf->handle_http($t) == 0, 'Basic-Auth: Wrong Auth-token');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /server-config HTTP/1.0
Authorization: Basic amFuOmphbg==
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'Basic-Auth: Valid Auth-token');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'Basic-Auth: Valid Auth-token');
## this should not crash
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /server-status HTTP/1.0
User-Agent: Wget/1.9.1
Authorization: Digest username="jan", realm="jan", nonce="9a5428ccc05b086a08d918e73b01fc6f",
uri="/server-status", response="ea5f7d9a30b8b762f9610ccb87dea74f"
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } );
-ok(handle_http == 0, 'Digest-Auth: missing qop, no crash');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 401 } );
+ok($tf->handle_http($t) == 0, 'Digest-Auth: missing qop, no crash');
-ok(stop_proc == 0, "Stopping lighttpd");
+ok($tf->stop_proc == 0, "Stopping lighttpd");
diff --git a/tests/mod-cgi.t b/tests/mod-cgi.t
index bf51fdb3..7fe3350c 100755
--- a/tests/mod-cgi.t
+++ b/tests/mod-cgi.t
@@ -3,220 +3,42 @@
use strict;
use IO::Socket;
use Test::More tests => 6;
+use LightyTest;
-my $basedir = (defined $ENV{'top_builddir'} ? $ENV{'top_builddir'} : '..');
-my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
-
-my $testname;
-my @request;
-my @response;
-my $configfile = $srcdir.'/lighttpd.conf';
-my $lighttpd_path = $basedir.'/src/lighttpd';
-my $pidfile = '/tmp/lighttpd/lighttpd.pid';
-my $pidoffile = '/tmp/lighttpd/pidof.pid';
-
-sub pidof {
- my $prog = $_[0];
-
- open F, "ps ax | grep $prog | awk '{ print \$1 }'|" or
- open F, "ps -ef | grep $prog | awk '{ print \$2 }'|" or
- return -1;
-
- my $pid = <F>;
- close F;
-
- return $pid;
-}
-
-sub stop_proc {
- open F, $pidfile or return -1;
- my $pid = <F>;
- close F;
-
- kill('TERM',$pid) or return -1;
- select(undef, undef, undef, 0.01);
-
- return 0;
-}
-
-
-sub start_proc {
- # kill old proc if necessary
- stop_proc;
-
- unlink($pidfile);
- system($lighttpd_path." -f ".$configfile);
-
- if (-e $pidfile) {
- return 0;
- } else {
- return -1;
- }
-}
-
-sub handle_http {
- my $EOL = "\015\012";
- my $BLANK = $EOL x 2;
- my $port = 2048;
- my $host = "127.0.0.1";
-
- my $remote =
- IO::Socket::INET->new(Proto => "tcp",
- PeerAddr => $host,
- PeerPort => $port)
- or return -1;
-
- $remote->autoflush(1);
-
- foreach(@request) {
- # pipeline requests
- s/\r//g;
- s/\n/$EOL/g;
-
- print $remote $_.$BLANK;
- }
-
- my $lines = "";
-
- # read everything
- while(<$remote>) {
- $lines .= $_;
- }
-
- close $remote;
-
- my $href;
- foreach $href (@response) {
- # first line is always response header
- my %resp_hdr;
- my $resp_body;
- my $resp_line;
- my $conditions = $_;
-
- for (my $ln = 0; defined $lines; $ln++) {
- (my $line, $lines) = split($EOL, $lines, 2);
-
- # header finished
- last if(length($line) == 0);
-
- if ($ln == 0) {
- # response header
- $resp_line = $line;
- } else {
- # response vars
-
- if ($line =~ /^([^:]+):\s*(.+)$/) {
- (my $h = $1) =~ tr/[A-Z]/[a-z]/;
-
- $resp_hdr{$h} = $2;
- } else {
- return -1;
- }
- }
- }
-
- # check length
- if (defined $resp_hdr{"content-length"}) {
- ($resp_body, $lines) = split("^.".$resp_hdr{"content-length"}, $lines, 2);
- } else {
- $resp_body = $lines;
- undef $lines;
- }
-
- # check conditions
- if ($resp_line =~ /^(HTTP\/1\.[01]) ([0-9]{3}) .+$/) {
- if ($href->{'HTTP-Protocol'} ne $1) {
- diag(sprintf("proto failed: expected '%s', got '%s'\n", $href->{'HTTP-Protocol'}, $1));
- return -1;
- }
- if ($href->{'HTTP-Status'} ne $2) {
- diag(sprintf("status failed: expected '%s', got '%s'\n", $href->{'HTTP-Status'}, $2));
- return -1;
- }
- } else {
- return -1;
- }
-
- if (defined $href->{'HTTP-Content'}) {
- if ($href->{'HTTP-Content'} ne $resp_body) {
- diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body));
- return -1;
- }
- }
-
- if (defined $href->{'-HTTP-Content'}) {
- if (defined $resp_body && $resp_body ne '') {
- diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body));
- return -1;
- }
- }
-
- foreach (keys %{ $href }) {
- next if $_ eq 'HTTP-Protocol';
- next if $_ eq 'HTTP-Status';
- next if $_ eq 'HTTP-Content';
- next if $_ eq '-HTTP-Content';
-
- (my $k = $_) =~ tr/[A-Z]/[a-z]/;
-
- my $no_val = 0;
-
- if (substr($k, 0, 1) eq '+') {
- $k = substr($k, 1);
- $no_val = 1;
-
- }
-
- if (!defined $resp_hdr{$k}) {
- diag(sprintf("required header '%s' is missing\n", $k));
- return -1;
- }
-
- if ($no_val == 0 &&
- $href->{$_} ne $resp_hdr{$k}) {
- diag(sprintf("response-header failed: expected '%s', got '%s'\n", $href->{$_}, $resp_hdr{$k}));
- return -1;
- }
- }
- }
-
- # we should have sucked up everything
- return -1 if (defined $lines);
-
- return 0;
-}
+my $tf = LightyTest->new();
+my $t;
-ok(start_proc == 0, "Starting lighttpd") or die();
+ok($tf->start_proc == 0, "Starting lighttpd") or die();
# mod-cgi
#
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /cgi.pl HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'perl via cgi');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'perl via cgi');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /cgi.pl/foo HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/cgi.pl' } );
-ok(handle_http == 0, 'perl via cgi + pathinfo');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/cgi.pl' } );
+ok($tf->handle_http($t) == 0, 'perl via cgi + pathinfo');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /cgi-pathinfo.pl/foo HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo' } );
-ok(handle_http == 0, 'perl via cgi + pathinfo');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/foo' } );
+ok($tf->handle_http($t) == 0, 'perl via cgi + pathinfo');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /nph-status.pl HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'NPH + perl, Bug #14');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'NPH + perl, Bug #14');
-ok(stop_proc == 0, "Stopping lighttpd");
+ok($tf->stop_proc == 0, "Stopping lighttpd");
diff --git a/tests/mod-compress.t b/tests/mod-compress.t
index 18969a2a..72bf1f61 100755
--- a/tests/mod-compress.t
+++ b/tests/mod-compress.t
@@ -3,221 +3,43 @@
use strict;
use IO::Socket;
use Test::More tests => 6;
+use LightyTest;
-my $basedir = (defined $ENV{'top_builddir'} ? $ENV{'top_builddir'} : '..');
-my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
-
-my $testname;
-my @request;
-my @response;
-my $configfile = $srcdir.'/lighttpd.conf';
-my $lighttpd_path = $basedir.'/src/lighttpd';
-my $pidfile = '/tmp/lighttpd/lighttpd.pid';
-my $pidoffile = '/tmp/lighttpd/pidof.pid';
-
-sub pidof {
- my $prog = $_[0];
-
- open F, "ps ax | grep $prog | awk '{ print \$1 }'|" or
- open F, "ps -ef | grep $prog | awk '{ print \$2 }'|" or
- return -1;
-
- my $pid = <F>;
- close F;
-
- return $pid;
-}
-
-sub stop_proc {
- open F, $pidfile or return -1;
- my $pid = <F>;
- close F;
-
- kill('TERM',$pid) or return -1;
- select(undef, undef, undef, 0.01);
-
- return 0;
-}
-
-
-sub start_proc {
- # kill old proc if necessary
- stop_proc;
-
- unlink($pidfile);
- system($lighttpd_path." -f ".$configfile);
-
- if (-e $pidfile) {
- return 0;
- } else {
- return -1;
- }
-}
-
-sub handle_http {
- my $EOL = "\015\012";
- my $BLANK = $EOL x 2;
- my $port = 2048;
- my $host = "127.0.0.1";
-
- my $remote =
- IO::Socket::INET->new(Proto => "tcp",
- PeerAddr => $host,
- PeerPort => $port)
- or return -1;
-
- $remote->autoflush(1);
-
- foreach(@request) {
- # pipeline requests
- s/\r//g;
- s/\n/$EOL/g;
-
- print $remote $_.$BLANK;
- }
-
- my $lines = "";
-
- # read everything
- while(<$remote>) {
- $lines .= $_;
- }
-
- close $remote;
-
- my $href;
- foreach $href (@response) {
- # first line is always response header
- my %resp_hdr;
- my $resp_body;
- my $resp_line;
- my $conditions = $_;
-
- for (my $ln = 0; defined $lines; $ln++) {
- (my $line, $lines) = split($EOL, $lines, 2);
-
- # header finished
- last if(length($line) == 0);
-
- if ($ln == 0) {
- # response header
- $resp_line = $line;
- } else {
- # response vars
-
- if ($line =~ /^([^:]+):\s*(.+)$/) {
- (my $h = $1) =~ tr/[A-Z]/[a-z]/;
-
- $resp_hdr{$h} = $2;
- } else {
- return -1;
- }
- }
- }
-
- # check length
- if (defined $resp_hdr{"content-length"}) {
- ($resp_body, $lines) = split("^.".$resp_hdr{"content-length"}, $lines, 2);
- } else {
- $resp_body = $lines;
- undef $lines;
- }
-
- # check conditions
- if ($resp_line =~ /^(HTTP\/1\.[01]) ([0-9]{3}) .+$/) {
- if ($href->{'HTTP-Protocol'} ne $1) {
- diag(sprintf("proto failed: expected '%s', got '%s'\n", $href->{'HTTP-Protocol'}, $1));
- return -1;
- }
- if ($href->{'HTTP-Status'} ne $2) {
- diag(sprintf("status failed: expected '%s', got '%s'\n", $href->{'HTTP-Status'}, $2));
- return -1;
- }
- } else {
- return -1;
- }
-
- if (defined $href->{'HTTP-Content'}) {
- if ($href->{'HTTP-Content'} ne $resp_body) {
- diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body));
- return -1;
- }
- }
-
- if (defined $href->{'-HTTP-Content'}) {
- if (defined $resp_body && $resp_body ne '') {
- diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body));
- return -1;
- }
- }
-
- foreach (keys %{ $href }) {
- next if $_ eq 'HTTP-Protocol';
- next if $_ eq 'HTTP-Status';
- next if $_ eq 'HTTP-Content';
- next if $_ eq '-HTTP-Content';
-
- (my $k = $_) =~ tr/[A-Z]/[a-z]/;
-
- my $no_val = 0;
-
- if (substr($k, 0, 1) eq '+') {
- $k = substr($k, 1);
- $no_val = 1;
-
- }
-
- if (!defined $resp_hdr{$k}) {
- diag(sprintf("required header '%s' is missing\n", $k));
- return -1;
- }
-
- if ($no_val == 0 &&
- $href->{$_} ne $resp_hdr{$k}) {
- diag(sprintf("response-header failed: expected '%s', got '%s'\n", $href->{$_}, $resp_hdr{$k}));
- return -1;
- }
- }
- }
-
- # we should have sucked up everything
- return -1 if (defined $lines);
-
- return 0;
-}
+my $tf = LightyTest->new();
+my $t;
-ok(start_proc == 0, "Starting lighttpd") or die();
+ok($tf->start_proc == 0, "Starting lighttpd") or die();
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /index.html HTTP/1.0
Accept-Encoding: deflate
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '' } );
-ok(handle_http == 0, 'Vary is set');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '' } );
+ok($tf->handle_http($t) == 0, 'Vary is set');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /index.html HTTP/1.0
Accept-Encoding: deflate
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', 'Content-Length' => '1288', '+Content-Encoding' => '' } );
-ok(handle_http == 0, 'deflate - Content-Length and Content-Encoding is set');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', 'Content-Length' => '1288', '+Content-Encoding' => '' } );
+ok($tf->handle_http($t) == 0, 'deflate - Content-Length and Content-Encoding is set');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /index.html HTTP/1.0
Accept-Encoding: gzip
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', '+Content-Encoding' => '' } );
-ok(handle_http == 0, 'gzip - Content-Length and Content-Encoding is set');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', '+Content-Encoding' => '' } );
+ok($tf->handle_http($t) == 0, 'gzip - Content-Length and Content-Encoding is set');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /index.txt HTTP/1.0
Accept-Encoding: gzip, deflate
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', '+Content-Encoding' => '' } );
-ok(handle_http == 0, 'gzip, deflate - Content-Length and Content-Encoding is set');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', '+Content-Encoding' => '' } );
+ok($tf->handle_http($t) == 0, 'gzip, deflate - Content-Length and Content-Encoding is set');
-ok(stop_proc == 0, "Stopping lighttpd");
+ok($tf->stop_proc == 0, "Stopping lighttpd");
diff --git a/tests/mod-fastcgi.t b/tests/mod-fastcgi.t
index 482b1b43..6d7d8915 100755
--- a/tests/mod-fastcgi.t
+++ b/tests/mod-fastcgi.t
@@ -1,456 +1,264 @@
#! /usr/bin/perl -w
use strict;
-use IO::Socket;
use Test::More tests => 40;
+use LightyTest;
-my $basedir = (defined $ENV{'top_builddir'} ? $ENV{'top_builddir'} : '..');
-my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
+my $tf = LightyTest->new();
-my $testname;
-my @request;
-my @response;
-my $configfile = 'lighttpd.conf';
-my $lighttpd_path = $basedir.'/src/lighttpd';
-my $pidfile = '/tmp/lighttpd/lighttpd.pid';
-my $pidoffile = '/tmp/lighttpd/pidof.pid';
-
-sub pidof {
- my $prog = $_[0];
-
- open F, "ps ax | grep $prog | grep -v grep | awk '{ print \$1 }'|" or
- open F, "ps -ef | grep $prog | grep -v grep | awk '{ print \$2 }'|" or
- return -1;
-
- my $pid = <F>;
- close F;
-
- if (defined $pid) { return $pid; }
-
- return -1;
-}
-
-sub stop_proc {
- open F, $pidfile or return -1;
- my $pid = <F>;
- close F;
-
- if (defined $pid) {
- kill('TERM',$pid) or return -1;
- select(undef, undef, undef, 0.01);
- }
-
- return 0;
-}
-
-
-sub start_proc {
- # kill old proc if necessary
- stop_proc;
-
- # pre-process configfile if necessary
- #
-
- my $pwd = `pwd`;
- chomp($pwd);
- unlink("/tmp/cfg.file");
- system("cat ".$srcdir."/".$configfile.' | perl -pe "s#\@SRCDIR\@#'.$pwd.'/'.$basedir.'/tests/#" > /tmp/cfg.file');
-
- unlink($pidfile);
- system($lighttpd_path." -f /tmp/cfg.file");
-
- unlink("/tmp/cfg.file");
- if (-e $pidfile) {
- return 0;
- } else {
- return -1;
- }
-}
-
-sub handle_http {
- my $EOL = "\015\012";
- my $BLANK = $EOL x 2;
- my $port = 2048;
- my $host = "127.0.0.1";
-
- my $remote =
- IO::Socket::INET->new(Proto => "tcp",
- PeerAddr => $host,
- PeerPort => $port)
- or return -1;
-
- $remote->autoflush(1);
-
- foreach(@request) {
- # pipeline requests
- s/\r//g;
- s/\n/$EOL/g;
-
- print $remote $_.$BLANK;
- }
-
- my $lines = "";
-
- # read everything
- while(<$remote>) {
- $lines .= $_;
- }
-
- close $remote;
-
- my $href;
- foreach $href (@response) {
- # first line is always response header
- my %resp_hdr;
- my $resp_body;
- my $resp_line;
- my $conditions = $_;
-
- for (my $ln = 0; defined $lines; $ln++) {
- (my $line, $lines) = split($EOL, $lines, 2);
-
- # header finished
- last if(length($line) == 0);
-
- if ($ln == 0) {
- # response header
- $resp_line = $line;
- } else {
- # response vars
-
- if ($line =~ /^([^:]+):\s*(.+)$/) {
- (my $h = $1) =~ tr/[A-Z]/[a-z]/;
-
- $resp_hdr{$h} = $2;
- } else {
- return -1;
- }
- }
- }
-
- # check length
- if (defined $resp_hdr{"content-length"}) {
- ($resp_body, $lines) = split("^.".$resp_hdr{"content-length"}, $lines, 2);
- } else {
- $resp_body = $lines;
- undef $lines;
- }
-
- # check conditions
- if ($resp_line =~ /^(HTTP\/1\.[01]) ([0-9]{3}) .+$/) {
- if ($href->{'HTTP-Protocol'} ne $1) {
- diag(sprintf("proto failed: expected '%s', got '%s'\n", $href->{'HTTP-Protocol'}, $1));
- return -1;
- }
- if ($href->{'HTTP-Status'} ne $2) {
- diag(sprintf("status failed: expected '%s', got '%s'\n", $href->{'HTTP-Status'}, $2));
- return -1;
- }
- } else {
- return -1;
- }
-
- if (defined $href->{'HTTP-Content'}) {
- if ($href->{'HTTP-Content'} ne $resp_body) {
- diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body));
- return -1;
- }
- }
-
- if (defined $href->{'-HTTP-Content'}) {
- if (defined $resp_body && $resp_body ne '') {
- diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body));
- return -1;
- }
- }
-
- foreach (keys %{ $href }) {
- next if $_ eq 'HTTP-Protocol';
- next if $_ eq 'HTTP-Status';
- next if $_ eq 'HTTP-Content';
- next if $_ eq '-HTTP-Content';
-
- (my $k = $_) =~ tr/[A-Z]/[a-z]/;
-
- my $no_val = 0;
-
- if (substr($k, 0, 1) eq '+') {
- $k = substr($k, 1);
- $no_val = 1;
-
- }
-
- if (!defined $resp_hdr{$k}) {
- diag(sprintf("required header '%s' is missing\n", $k));
- return -1;
- }
-
- if ($no_val == 0 &&
- $href->{$_} ne $resp_hdr{$k}) {
- diag(sprintf("response-header failed: expected '%s', got '%s'\n", $href->{$_}, $resp_hdr{$k}));
- return -1;
- }
- }
- }
-
- # we should have sucked up everything
- return -1 if (defined $lines);
-
- return 0;
-}
-
+my $t;
SKIP: {
- skip "no PHP running on port 1026", 24 if pidof("php") == -1;
+ skip "no PHP running on port 1026", 24 if $tf->pidof("php") == -1;
- ok(start_proc == 0, "Starting lighttpd") or die();
+ ok($tf->start_proc == 0, "Starting lighttpd") or die();
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /phpinfo.php HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
- ok(handle_http == 0, 'valid request');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ ok($tf->handle_http($t) == 0, 'valid request');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /phpinfofoobar.php HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
- ok(handle_http == 0, 'file not found');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
+ ok($tf->handle_http($t) == 0, 'file not found');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /go/ HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
- ok(handle_http == 0, 'index-file handling');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ ok($tf->handle_http($t) == 0, 'index-file handling');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /redirect.php HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => 'http://www.example.org:2048/' } );
- ok(handle_http == 0, 'Status + Location via FastCGI');
+ $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');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /phpself.php HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
- ok(handle_http == 0, '$_SERVER["PHP_SELF"]');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ ok($tf->handle_http($t) == 0, '$_SERVER["PHP_SELF"]');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /phpself.php/foo HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/phpself.php' } );
- ok(handle_http == 0, '$_SERVER["PHP_SELF"]');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/phpself.php' } );
+ ok($tf->handle_http($t) == 0, '$_SERVER["PHP_SELF"]');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /phphost.php HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } );
- ok(handle_http == 0, 'SERVER_NAME');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } );
+ ok($tf->handle_http($t) == 0, 'SERVER_NAME');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /phphost.php HTTP/1.0
Host: foo.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } );
- ok(handle_http == 0, 'SERVER_NAME');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } );
+ ok($tf->handle_http($t) == 0, 'SERVER_NAME');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /phphost.php HTTP/1.0
Host: vvv.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } );
- ok(handle_http == 0, 'SERVER_NAME');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } );
+ ok($tf->handle_http($t) == 0, 'SERVER_NAME');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /phphost.php HTTP/1.0
Host: zzz.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } );
- ok(handle_http == 0, 'SERVER_NAME');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'www.example.org' } );
+ ok($tf->handle_http($t) == 0, 'SERVER_NAME');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /cgi.php/abc HTTP/1.0
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
- ok(handle_http == 0, 'PATHINFO');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ ok($tf->handle_http($t) == 0, 'PATHINFO');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /www/abc/def HTTP/1.0
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
- ok(handle_http == 0, 'PATHINFO on a directory');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
+ ok($tf->handle_http($t) == 0, 'PATHINFO on a directory');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /indexfile/ HTTP/1.0
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/indexfile/index.php' } );
- ok(handle_http == 0, 'PHP_SELF + Indexfile, Bug #3');
+ $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');
- ok(stop_proc == 0, "Stopping lighttpd");
+ ok($tf->stop_proc == 0, "Stopping lighttpd");
- $configfile = 'fastcgi-10.conf';
- ok(start_proc == 0, "Starting lighttpd with $configfile") or die();
- @request = ( <<EOF
+ $tf->{CONFIGFILE} = 'fastcgi-10.conf';
+ ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
+ $t->{REQUEST} = ( <<EOF
GET /phphost.php HTTP/1.0
Host: zzz.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'zzz.example.org' } );
- ok(handle_http == 0, 'FastCGI + Host');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'zzz.example.org' } );
+ ok($tf->handle_http($t) == 0, 'FastCGI + Host');
- ok(stop_proc == 0, "Stopping lighttpd");
+ ok($tf->stop_proc == 0, "Stopping lighttpd");
- $configfile = 'bug-06.conf';
- ok(start_proc == 0, "Starting lighttpd with $configfile") or die();
- @request = ( <<EOF
+ $tf->{CONFIGFILE} = 'bug-06.conf';
+ ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
+ $t->{REQUEST} = ( <<EOF
GET /indexfile/ HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/indexfile/index.php' } );
- ok(handle_http == 0, 'Bug #6');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/indexfile/index.php' } );
+ ok($tf->handle_http($t) == 0, 'Bug #6');
- ok(stop_proc == 0, "Stopping lighttpd");
+ ok($tf->stop_proc == 0, "Stopping lighttpd");
- $configfile = 'bug-12.conf';
- ok(start_proc == 0, "Starting lighttpd with bug-12.conf") or die();
- @request = ( <<EOF
+ $tf->{CONFIGFILE} = 'bug-12.conf';
+ ok($tf->start_proc == 0, "Starting lighttpd with bug-12.conf") or die();
+ $t->{REQUEST} = ( <<EOF
POST /indexfile/abc HTTP/1.0
Host: www.example.org
Content-Length: 0
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => '/indexfile/return-404.php' } );
- ok(handle_http == 0, 'Bug #12');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => '/indexfile/return-404.php' } );
+ ok($tf->handle_http($t) == 0, 'Bug #12');
- ok(stop_proc == 0, "Stopping lighttpd");
+ ok($tf->stop_proc == 0, "Stopping lighttpd");
}
SKIP: {
- skip "no fcgi-auth found", 4 unless -x $basedir."/tests/fcgi-auth.exe";
+ skip "no fcgi-auth found", 4 unless -x $tf->{BASEDIR}."/tests/fcgi-auth" || -x $tf->{BASEDIR}."/tests/fcgi-auth.exe";
- $configfile = 'fastcgi-auth.conf';
- ok(start_proc == 0, "Starting lighttpd with $configfile") or die();
- @request = ( <<EOF
+ $tf->{CONFIGFILE} = 'fastcgi-auth.conf';
+ ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
+ $t->{REQUEST} = ( <<EOF
GET /index.html?ok HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
- ok(handle_http == 0, 'FastCGI - Auth');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ ok($tf->handle_http($t) == 0, 'FastCGI - Auth');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /index.html?fail HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } );
- ok(handle_http == 0, 'FastCGI - Auth');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } );
+ ok($tf->handle_http($t) == 0, 'FastCGI - Auth');
- ok(stop_proc == 0, "Stopping lighttpd");
+ ok($tf->stop_proc == 0, "Stopping lighttpd");
}
SKIP: {
skip "no php found", 3 unless -x "/home/weigon/Documents/php-4.3.10/sapi/cgi/php";
- $configfile = 'fastcgi-13.conf';
- ok(start_proc == 0, "Starting lighttpd with $configfile") or die();
- @request = ( <<EOF
+ $tf->{CONFIGFILE} = 'fastcgi-13.conf';
+ ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
+ $t->{REQUEST} = ( <<EOF
GET /indexfile/index.php HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
- ok(handle_http == 0, 'FastCGI + local spawning');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ ok($tf->handle_http($t) == 0, 'FastCGI + local spawning');
- ok(stop_proc == 0, "Stopping lighttpd");
+ ok($tf->stop_proc == 0, "Stopping lighttpd");
}
SKIP: {
- skip "no fcgi-responder found", 9 unless -x $basedir."/tests/fcgi-responder.exe";
+ skip "no fcgi-responder found", 9 unless -x $tf->{BASEDIR}."/tests/fcgi-responder" || -x $tf->{BASEDIR}."/tests/fcgi-responder.exe";
- $configfile = 'fastcgi-responder.conf';
- ok(start_proc == 0, "Starting lighttpd with $configfile") or die();
- @request = ( <<EOF
+ $tf->{CONFIGFILE} = 'fastcgi-responder.conf';
+ ok($tf->start_proc == 0, "Starting lighttpd with $tf->{CONFIGFILE}") or die();
+ $t->{REQUEST} = ( <<EOF
GET /index.fcgi?lf HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } );
- ok(handle_http == 0, 'line-ending \n\n');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } );
+ ok($tf->handle_http($t) == 0, 'line-ending \n\n');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /index.fcgi?crlf HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } );
- ok(handle_http == 0, 'line-ending \r\n\r\n');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } );
+ ok($tf->handle_http($t) == 0, 'line-ending \r\n\r\n');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /index.fcgi?slow-lf HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } );
- ok(handle_http == 0, 'line-ending \n + \n');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } );
+ ok($tf->handle_http($t) == 0, 'line-ending \n + \n');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /index.fcgi?slow-crlf HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } );
- ok(handle_http == 0, 'line-ending \r\n + \r\n');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } );
+ ok($tf->handle_http($t) == 0, 'line-ending \r\n + \r\n');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /index.fcgi?die-at-end HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } );
- ok(handle_http == 0, 'killing fastcgi and wait for restart');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } );
+ ok($tf->handle_http($t) == 0, 'killing fastcgi and wait for restart');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /index.fcgi?die-at-end HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } );
- ok(handle_http == 0, 'killing fastcgi and wait for restart');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } );
+ ok($tf->handle_http($t) == 0, 'killing fastcgi and wait for restart');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /index.fcgi?crlf HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } );
- ok(handle_http == 0, 'regular response of after restart');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'test123' } );
+ ok($tf->handle_http($t) == 0, 'regular response of after restart');
- ok(stop_proc == 0, "Stopping lighttpd");
+ ok($tf->stop_proc == 0, "Stopping lighttpd");
}
diff --git a/tests/mod-proxy.t b/tests/mod-proxy.t
index 555093d6..a1abce16 100755
--- a/tests/mod-proxy.t
+++ b/tests/mod-proxy.t
@@ -3,231 +3,37 @@
use strict;
use IO::Socket;
use Test::More tests => 5;
+use LightyTest;
-my $basedir = (defined $ENV{'top_builddir'} ? $ENV{'top_builddir'} : '..');
-my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
+my $tf_real = LightyTest->new();
+my $tf_proxy = LightyTest->new();
-my $testname;
-my @request;
-my @response;
-my $configfile = 'lighttpd.conf';
-my $lighttpd_path = $basedir.'/src/lighttpd';
-my $pidfile = '/tmp/lighttpd/lighttpd.pid';
-my $pidoffile = '/tmp/lighttpd/pidof.pid';
+my $t;
-# proxy is on 2050, real server on 2048
-my $port = 2050;
-
-sub pidof {
- my $prog = $_[0];
-
- open F, "ps ax | grep $prog | grep -v grep | awk '{ print \$1 }'|" or
- open F, "ps -ef | grep $prog | grep -v grep | awk '{ print \$2 }'|" or
- return -1;
-
- my $pid = <F>;
- close F;
-
- if (defined $pid) { return $pid; }
-
- return -1;
-}
-
-sub stop_proc {
- open F, $pidfile or return -1;
- my $pid = <F>;
- close F;
-
- if (defined $pid) {
- kill('TERM',$pid) or return -1;
- select(undef, undef, undef, 0.01);
- }
-
- return 0;
-}
-
-
-sub start_proc {
- # kill old proc if necessary
- stop_proc;
-
- # pre-process configfile if necessary
- #
-
- my $pwd = `pwd`;
- chomp($pwd);
- unlink("/tmp/cfg.file");
- system("cat ".$srcdir."/".$configfile.' | perl -pe "s#\@SRCDIR\@#'.$pwd.'/'.$basedir.'/tests/#" > /tmp/cfg.file');
-
- unlink($pidfile);
- system($lighttpd_path." -f /tmp/cfg.file");
- # system("valgrind --tool=memcheck --show-reachable=yes --leak-check=yes --logfile=foo ".$lighttpd_path." -D -f /tmp/cfg.file &");
-
- sleep(1);
- unlink("/tmp/cfg.file");
- if (-e $pidfile) {
- return 0;
- } else {
- return -1;
- }
-}
-
-sub handle_http {
- my $EOL = "\015\012";
- my $BLANK = $EOL x 2;
- my $host = "127.0.0.1";
-
- my $remote =
- IO::Socket::INET->new(Proto => "tcp",
- PeerAddr => $host,
- PeerPort => $port)
- or return -1;
-
- $remote->autoflush(1);
-
- foreach(@request) {
- # pipeline requests
- s/\r//g;
- s/\n/$EOL/g;
-
- print $remote $_.$BLANK;
- }
-
- my $lines = "";
-
- # read everything
- while(<$remote>) {
- $lines .= $_;
- }
-
- close $remote;
-
- my $href;
- foreach $href (@response) {
- # first line is always response header
- my %resp_hdr;
- my $resp_body;
- my $resp_line;
- my $conditions = $_;
-
- for (my $ln = 0; defined $lines; $ln++) {
- (my $line, $lines) = split($EOL, $lines, 2);
-
- # header finished
- last if(length($line) == 0);
-
- if ($ln == 0) {
- # response header
- $resp_line = $line;
- } else {
- # response vars
-
- if ($line =~ /^([^:]+):\s*(.+)$/) {
- (my $h = $1) =~ tr/[A-Z]/[a-z]/;
-
- $resp_hdr{$h} = $2;
- } else {
- return -1;
- }
- }
- }
-
- # check length
- if (defined $resp_hdr{"content-length"}) {
- ($resp_body, $lines) = split("^.".$resp_hdr{"content-length"}, $lines, 2);
- } else {
- $resp_body = $lines;
- undef $lines;
- }
-
- # check conditions
- if ($resp_line =~ /^(HTTP\/1\.[01]) ([0-9]{3}) .+$/) {
- if ($href->{'HTTP-Protocol'} ne $1) {
- diag(sprintf("proto failed: expected '%s', got '%s'\n", $href->{'HTTP-Protocol'}, $1));
- return -1;
- }
- if ($href->{'HTTP-Status'} ne $2) {
- diag(sprintf("status failed: expected '%s', got '%s'\n", $href->{'HTTP-Status'}, $2));
- return -1;
- }
- } else {
- return -1;
- }
-
- if (defined $href->{'HTTP-Content'}) {
- if ($href->{'HTTP-Content'} ne $resp_body) {
- diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body));
- return -1;
- }
- }
-
- if (defined $href->{'-HTTP-Content'}) {
- if (defined $resp_body && $resp_body ne '') {
- diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body));
- return -1;
- }
- }
-
- foreach (keys %{ $href }) {
- next if $_ eq 'HTTP-Protocol';
- next if $_ eq 'HTTP-Status';
- next if $_ eq 'HTTP-Content';
- next if $_ eq '-HTTP-Content';
-
- (my $k = $_) =~ tr/[A-Z]/[a-z]/;
-
- my $no_val = 0;
-
- if (substr($k, 0, 1) eq '+') {
- $k = substr($k, 1);
- $no_val = 1;
-
- }
-
- if (!defined $resp_hdr{$k}) {
- diag(sprintf("required header '%s' is missing\n", $k));
- return -1;
- }
-
- if ($no_val == 0 &&
- $href->{$_} ne $resp_hdr{$k}) {
- diag(sprintf("response-header failed: expected '%s', got '%s'\n", $href->{$_}, $resp_hdr{$k}));
- return -1;
- }
- }
- }
-
- # we should have sucked up everything
- if (defined $lines) {
- diag(sprintf("still have data\n"));
- return -1;
- }
-
- return 0;
-}
-
## we need two procs
## 1. the real webserver
## 2. the proxy server
-$configfile = 'lighttpd.conf';
-$pidfile = '/tmp/lighttpd/lighttpd.pid';
-ok(start_proc == 0, "Starting lighttpd") or die();
+$tf_real->{PORT} = 2048;
+$tf_real->{CONFIGFILE} = 'lighttpd.conf';
+$tf_real->{LIGHTTPD_PIDFILE} = '/tmp/lighttpd/lighttpd.pid';
+
+$tf_proxy->{PORT} = 2050;
+$tf_proxy->{CONFIGFILE} = 'proxy.conf';
+$tf_proxy->{LIGHTTPD_PIDFILE} = '/tmp/lighttpd/lighttpd-proxy.pid';
+
+ok($tf_real->start_proc == 0, "Starting lighttpd") or die();
-$configfile = 'proxy.conf';
-$pidfile = '/tmp/lighttpd/lighttpd-proxy.pid';
-ok(start_proc == 0, "Starting lighttpd as proxy") or die();
+ok($tf_proxy->start_proc == 0, "Starting lighttpd as proxy") or die();
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /phpinfo.php HTTP/1.0
Host: www.example.org
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'valid request');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf_proxy->handle_http($t) == 0, 'valid request');
-$pidfile = '/tmp/lighttpd/lighttpd-proxy.pid';
-ok(stop_proc == 0, "Stopping lighttpd proxy");
+ok($tf_proxy->stop_proc == 0, "Stopping lighttpd proxy");
-$pidfile = '/tmp/lighttpd/lighttpd.pid';
-ok(stop_proc == 0, "Stopping lighttpd");
+ok($tf_real->stop_proc == 0, "Stopping lighttpd");
diff --git a/tests/mod-redirect.t b/tests/mod-redirect.t
index df6f4798..3fa18d2a 100755
--- a/tests/mod-redirect.t
+++ b/tests/mod-redirect.t
@@ -3,198 +3,20 @@
use strict;
use IO::Socket;
use Test::More tests => 3;
+use LightyTest;
-my $basedir = (defined $ENV{'top_builddir'} ? $ENV{'top_builddir'} : '..');
-my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
-
-my $testname;
-my @request;
-my @response;
-my $configfile = $srcdir.'/lighttpd.conf';
-my $lighttpd_path = $basedir.'/src/lighttpd';
-my $pidfile = '/tmp/lighttpd/lighttpd.pid';
-my $pidoffile = '/tmp/lighttpd/pidof.pid';
-
-sub pidof {
- my $prog = $_[0];
-
- open F, "ps ax | grep $prog | awk '{ print \$1 }'|" or
- open F, "ps -ef | grep $prog | awk '{ print \$2 }'|" or
- return -1;
-
- my $pid = <F>;
- close F;
-
- return $pid;
-}
-
-sub stop_proc {
- open F, $pidfile or return -1;
- my $pid = <F>;
- close F;
-
- kill('TERM',$pid) or return -1;
- select(undef, undef, undef, 0.01);
-
- return 0;
-}
-
-
-sub start_proc {
- # kill old proc if necessary
- stop_proc;
-
- unlink($pidfile);
- system($lighttpd_path." -f ".$configfile);
-
- if (-e $pidfile) {
- return 0;
- } else {
- return -1;
- }
-}
-
-sub handle_http {
- my $EOL = "\015\012";
- my $BLANK = $EOL x 2;
- my $port = 2048;
- my $host = "127.0.0.1";
-
- my $remote =
- IO::Socket::INET->new(Proto => "tcp",
- PeerAddr => $host,
- PeerPort => $port)
- or return -1;
-
- $remote->autoflush(1);
-
- foreach(@request) {
- # pipeline requests
- s/\r//g;
- s/\n/$EOL/g;
-
- print $remote $_.$BLANK;
- }
-
- my $lines = "";
-
- # read everything
- while(<$remote>) {
- $lines .= $_;
- }
-
- close $remote;
-
- my $href;
- foreach $href (@response) {
- # first line is always response header
- my %resp_hdr;
- my $resp_body;
- my $resp_line;
- my $conditions = $_;
-
- for (my $ln = 0; defined $lines; $ln++) {
- (my $line, $lines) = split($EOL, $lines, 2);
-
- # header finished
- last if(length($line) == 0);
-
- if ($ln == 0) {
- # response header
- $resp_line = $line;
- } else {
- # response vars
-
- if ($line =~ /^([^:]+):\s*(.+)$/) {
- (my $h = $1) =~ tr/[A-Z]/[a-z]/;
-
- $resp_hdr{$h} = $2;
- } else {
- return -1;
- }
- }
- }
-
- # check length
- if (defined $resp_hdr{"content-length"}) {
- ($resp_body, $lines) = split("^.".$resp_hdr{"content-length"}, $lines, 2);
- } else {
- $resp_body = $lines;
- undef $lines;
- }
-
- # check conditions
- if ($resp_line =~ /^(HTTP\/1\.[01]) ([0-9]{3}) .+$/) {
- if ($href->{'HTTP-Protocol'} ne $1) {
- diag(sprintf("proto failed: expected '%s', got '%s'\n", $href->{'HTTP-Protocol'}, $1));
- return -1;
- }
- if ($href->{'HTTP-Status'} ne $2) {
- diag(sprintf("status failed: expected '%s', got '%s'\n", $href->{'HTTP-Status'}, $2));
- return -1;
- }
- } else {
- return -1;
- }
-
- if (defined $href->{'HTTP-Content'}) {
- if ($href->{'HTTP-Content'} ne $resp_body) {
- diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body));
- return -1;
- }
- }
-
- if (defined $href->{'-HTTP-Content'}) {
- if (defined $resp_body && $resp_body ne '') {
- diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body));
- return -1;
- }
- }
-
- foreach (keys %{ $href }) {
- next if $_ eq 'HTTP-Protocol';
- next if $_ eq 'HTTP-Status';
- next if $_ eq 'HTTP-Content';
- next if $_ eq '-HTTP-Content';
-
- (my $k = $_) =~ tr/[A-Z]/[a-z]/;
-
- my $no_val = 0;
-
- if (substr($k, 0, 1) eq '+') {
- $k = substr($k, 1);
- $no_val = 1;
-
- }
-
- if (!defined $resp_hdr{$k}) {
- diag(sprintf("required header '%s' is missing\n", $k));
- return -1;
- }
-
- if ($no_val == 0 &&
- $href->{$_} ne $resp_hdr{$k}) {
- diag(sprintf("response-header failed: expected '%s', got '%s'\n", $href->{$_}, $resp_hdr{$k}));
- return -1;
- }
- }
- }
-
- # we should have sucked up everything
- return -1 if (defined $lines);
-
- return 0;
-}
+my $tf = LightyTest->new();
+my $t;
-ok(start_proc == 0, "Starting lighttpd") or die();
+ok($tf->start_proc == 0, "Starting lighttpd") or die();
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /redirect/ HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:2048/' } );
-ok(handle_http == 0, 'external redirect');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:2048/' } );
+ok($tf->handle_http($t) == 0, 'external redirect');
-ok(stop_proc == 0, "Stopping lighttpd");
+ok($tf->stop_proc == 0, "Stopping lighttpd");
diff --git a/tests/mod-rewrite.t b/tests/mod-rewrite.t
index 8a6de425..a4b5d53a 100755
--- a/tests/mod-rewrite.t
+++ b/tests/mod-rewrite.t
@@ -3,231 +3,40 @@
use strict;
use IO::Socket;
use Test::More tests => 5;
+use LightyTest;
-my $basedir = (defined $ENV{'top_builddir'} ? $ENV{'top_builddir'} : '..');
-my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
-
-my $testname;
-my @request;
-my @response;
-my $configfile = 'lighttpd.conf';
-my $lighttpd_path = $basedir.'/src/lighttpd';
-my $pidfile = '/tmp/lighttpd/lighttpd.pid';
-my $pidoffile = '/tmp/lighttpd/pidof.pid';
-
-sub pidof {
- my $prog = $_[0];
-
- open F, "ps ax | grep $prog | grep -v grep | awk '{ print \$1 }'|" or
- open F, "ps -ef | grep $prog | grep -v grep | awk '{ print \$2 }'|" or
- return -1;
-
- my $pid = <F>;
- close F;
-
- if (defined $pid) { return $pid; }
-
- return -1;
-}
-
-sub stop_proc {
- open F, $pidfile or return -1;
- my $pid = <F>;
- close F;
-
- if (defined $pid) {
- kill('TERM',$pid) or return -1;
- select(undef, undef, undef, 0.01);
- }
-
- return 0;
-}
-
-
-sub start_proc {
- # kill old proc if necessary
- stop_proc;
-
- # pre-process configfile if necessary
- #
-
- my $pwd = `pwd`;
- chomp($pwd);
- unlink("/tmp/cfg.file");
- system("cat ".$srcdir."/".$configfile.' | perl -pe "s#\@SRCDIR\@#'.$pwd.'/'.$basedir.'/tests/#" > /tmp/cfg.file');
-
- unlink($pidfile);
- system($lighttpd_path." -f /tmp/cfg.file");
-
- unlink("/tmp/cfg.file");
- if (-e $pidfile) {
- return 0;
- } else {
- return -1;
- }
-}
-
-sub handle_http {
- my $EOL = "\015\012";
- my $BLANK = $EOL x 2;
- my $port = 2048;
- my $host = "127.0.0.1";
-
- my $remote =
- IO::Socket::INET->new(Proto => "tcp",
- PeerAddr => $host,
- PeerPort => $port)
- or return -1;
-
- $remote->autoflush(1);
-
- foreach(@request) {
- # pipeline requests
- s/\r//g;
- s/\n/$EOL/g;
-
- print $remote $_.$BLANK;
- }
-
- my $lines = "";
-
- # read everything
- while(<$remote>) {
- $lines .= $_;
- }
-
- close $remote;
-
- my $href;
- foreach $href (@response) {
- # first line is always response header
- my %resp_hdr;
- my $resp_body;
- my $resp_line;
- my $conditions = $_;
-
- for (my $ln = 0; defined $lines; $ln++) {
- (my $line, $lines) = split($EOL, $lines, 2);
-
- # header finished
- last if(length($line) == 0);
-
- if ($ln == 0) {
- # response header
- $resp_line = $line;
- } else {
- # response vars
-
- if ($line =~ /^([^:]+):\s*(.+)$/) {
- (my $h = $1) =~ tr/[A-Z]/[a-z]/;
-
- $resp_hdr{$h} = $2;
- } else {
- return -1;
- }
- }
- }
-
- # check length
- if (defined $resp_hdr{"content-length"}) {
- ($resp_body, $lines) = split("^.".$resp_hdr{"content-length"}, $lines, 2);
- } else {
- $resp_body = $lines;
- undef $lines;
- }
-
- # check conditions
- if ($resp_line =~ /^(HTTP\/1\.[01]) ([0-9]{3}) .+$/) {
- if ($href->{'HTTP-Protocol'} ne $1) {
- diag(sprintf("proto failed: expected '%s', got '%s'\n", $href->{'HTTP-Protocol'}, $1));
- return -1;
- }
- if ($href->{'HTTP-Status'} ne $2) {
- diag(sprintf("status failed: expected '%s', got '%s'\n", $href->{'HTTP-Status'}, $2));
- return -1;
- }
- } else {
- return -1;
- }
-
- if (defined $href->{'HTTP-Content'}) {
- if ($href->{'HTTP-Content'} ne $resp_body) {
- diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body));
- return -1;
- }
- }
-
- if (defined $href->{'-HTTP-Content'}) {
- if (defined $resp_body && $resp_body ne '') {
- diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body));
- return -1;
- }
- }
-
- foreach (keys %{ $href }) {
- next if $_ eq 'HTTP-Protocol';
- next if $_ eq 'HTTP-Status';
- next if $_ eq 'HTTP-Content';
- next if $_ eq '-HTTP-Content';
-
- (my $k = $_) =~ tr/[A-Z]/[a-z]/;
-
- my $no_val = 0;
-
- if (substr($k, 0, 1) eq '+') {
- $k = substr($k, 1);
- $no_val = 1;
-
- }
-
- if (!defined $resp_hdr{$k}) {
- diag(sprintf("required header '%s' is missing\n", $k));
- return -1;
- }
-
- if ($no_val == 0 &&
- $href->{$_} ne $resp_hdr{$k}) {
- diag(sprintf("response-header failed: expected '%s', got '%s'\n", $href->{$_}, $resp_hdr{$k}));
- return -1;
- }
- }
- }
-
- # we should have sucked up everything
- return -1 if (defined $lines);
-
- return 0;
-}
-
+my $tf = LightyTest->new();
+my $t;
+
SKIP: {
- skip "no PHP running on port 1026", 5 if pidof("php") == -1;
+ skip "no PHP running on port 1026", 5 if $tf->pidof("php") == -1;
- ok(start_proc == 0, "Starting lighttpd") or die();
+ ok($tf->start_proc == 0, "Starting lighttpd") or die();
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /rewrite/foo HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '' } );
- ok(handle_http == 0, 'valid request');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '' } );
+ ok($tf->handle_http($t) == 0, 'valid request');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /rewrite/foo?a=b HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'a=b' } );
- ok(handle_http == 0, 'valid request');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'a=b' } );
+ ok($tf->handle_http($t) == 0, 'valid request');
- @request = ( <<EOF
+ $t->{REQUEST} = ( <<EOF
GET /rewrite/bar?a=b HTTP/1.0
Host: www.example.org
EOF
);
- @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'bar&a=b' } );
- ok(handle_http == 0, 'valid request');
+ $t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'bar&a=b' } );
+ ok($tf->handle_http($t) == 0, 'valid request');
- ok(stop_proc == 0, "Stopping lighttpd");
+ ok($tf->stop_proc == 0, "Stopping lighttpd");
}
diff --git a/tests/mod-userdir.t b/tests/mod-userdir.t
index d74040ef..59990743 100755
--- a/tests/mod-userdir.t
+++ b/tests/mod-userdir.t
@@ -3,214 +3,36 @@
use strict;
use IO::Socket;
use Test::More tests => 5;
+use LightyTest;
-my $basedir = (defined $ENV{'top_builddir'} ? $ENV{'top_builddir'} : '..');
-my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
-
-my $testname;
-my @request;
-my @response;
-my $configfile = $srcdir.'/lighttpd.conf';
-my $lighttpd_path = $basedir.'/src/lighttpd';
-my $pidfile = '/tmp/lighttpd/lighttpd.pid';
-my $pidoffile = '/tmp/lighttpd/pidof.pid';
-
-sub pidof {
- my $prog = $_[0];
-
- open F, "ps ax | grep $prog | awk '{ print \$1 }'|" or
- open F, "ps -ef | grep $prog | awk '{ print \$2 }'|" or
- return -1;
-
- my $pid = <F>;
- close F;
-
- return $pid;
-}
-
-sub stop_proc {
- open F, $pidfile or return -1;
- my $pid = <F>;
- close F;
-
- kill('TERM',$pid) or return -1;
- select(undef, undef, undef, 0.01);
-
- return 0;
-}
-
-
-sub start_proc {
- # kill old proc if necessary
- stop_proc;
-
- unlink($pidfile);
- system($lighttpd_path." -f ".$configfile);
-
- if (-e $pidfile) {
- return 0;
- } else {
- return -1;
- }
-}
-
-sub handle_http {
- my $EOL = "\015\012";
- my $BLANK = $EOL x 2;
- my $port = 2048;
- my $host = "127.0.0.1";
-
- my $remote =
- IO::Socket::INET->new(Proto => "tcp",
- PeerAddr => $host,
- PeerPort => $port)
- or return -1;
-
- $remote->autoflush(1);
-
- foreach(@request) {
- # pipeline requests
- s/\r//g;
- s/\n/$EOL/g;
-
- print $remote $_.$BLANK;
- }
-
- my $lines = "";
-
- # read everything
- while(<$remote>) {
- $lines .= $_;
- }
-
- close $remote;
-
- my $href;
- foreach $href (@response) {
- # first line is always response header
- my %resp_hdr;
- my $resp_body;
- my $resp_line;
- my $conditions = $_;
-
- for (my $ln = 0; defined $lines; $ln++) {
- (my $line, $lines) = split($EOL, $lines, 2);
-
- # header finished
- last if(length($line) == 0);
-
- if ($ln == 0) {
- # response header
- $resp_line = $line;
- } else {
- # response vars
-
- if ($line =~ /^([^:]+):\s*(.+)$/) {
- (my $h = $1) =~ tr/[A-Z]/[a-z]/;
-
- $resp_hdr{$h} = $2;
- } else {
- return -1;
- }
- }
- }
-
- # check length
- if (defined $resp_hdr{"content-length"}) {
- ($resp_body, $lines) = split("^.".$resp_hdr{"content-length"}, $lines, 2);
- } else {
- $resp_body = $lines;
- undef $lines;
- }
-
- # check conditions
- if ($resp_line =~ /^(HTTP\/1\.[01]) ([0-9]{3}) .+$/) {
- if ($href->{'HTTP-Protocol'} ne $1) {
- diag(sprintf("proto failed: expected '%s', got '%s'\n", $href->{'HTTP-Protocol'}, $1));
- return -1;
- }
- if ($href->{'HTTP-Status'} ne $2) {
- diag(sprintf("status failed: expected '%s', got '%s'\n", $href->{'HTTP-Status'}, $2));
- return -1;
- }
- } else {
- return -1;
- }
-
- if (defined $href->{'HTTP-Content'}) {
- if ($href->{'HTTP-Content'} ne $resp_body) {
- diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body));
- return -1;
- }
- }
-
- if (defined $href->{'-HTTP-Content'}) {
- if (defined $resp_body && $resp_body ne '') {
- diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body));
- return -1;
- }
- }
-
- foreach (keys %{ $href }) {
- next if $_ eq 'HTTP-Protocol';
- next if $_ eq 'HTTP-Status';
- next if $_ eq 'HTTP-Content';
- next if $_ eq '-HTTP-Content';
-
- (my $k = $_) =~ tr/[A-Z]/[a-z]/;
-
- my $no_val = 0;
-
- if (substr($k, 0, 1) eq '+') {
- $k = substr($k, 1);
- $no_val = 1;
-
- }
-
- if (!defined $resp_hdr{$k}) {
- diag(sprintf("required header '%s' is missing\n", $k));
- return -1;
- }
-
- if ($no_val == 0 &&
- $href->{$_} ne $resp_hdr{$k}) {
- diag(sprintf("response-header failed: expected '%s', got '%s'\n", $href->{$_}, $resp_hdr{$k}));
- return -1;
- }
- }
- }
-
- # we should have sucked up everything
- return -1 if (defined $lines);
-
- return 0;
-}
+my $tf = LightyTest->new();
+my $t;
-ok(start_proc == 0, "Starting lighttpd") or die();
+ok($tf->start_proc == 0, "Starting lighttpd") or die();
# get current user
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /~foobar/ HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
-ok(handle_http == 0, 'valid user');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
+ok($tf->handle_http($t) == 0, 'valid user');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /~jan HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:2048/~jan/' } );
-ok(handle_http == 0, 'valid user + redirect');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:2048/~jan/' } );
+ok($tf->handle_http($t) == 0, 'valid user + redirect');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /~jan HTTP/1.0
Host: www.example.org
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://www.example.org/~jan/' } );
-ok(handle_http == 0, 'valid user + redirect');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://www.example.org/~jan/' } );
+ok($tf->handle_http($t) == 0, 'valid user + redirect');
-ok(stop_proc == 0, "Stopping lighttpd");
+ok($tf->stop_proc == 0, "Stopping lighttpd");
diff --git a/tests/request.t b/tests/request.t
index 9151f5f5..97b76437 100755
--- a/tests/request.t
+++ b/tests/request.t
@@ -3,315 +3,137 @@
use strict;
use IO::Socket;
use Test::More tests => 28;
+use LightyTest;
-my $basedir = (defined $ENV{'top_builddir'} ? $ENV{'top_builddir'} : '..');
-my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
-
-my $testname;
-my @request;
-my @response;
-my $configfile = $srcdir.'/lighttpd.conf';
-my $lighttpd_path = $basedir.'/src/lighttpd';
-my $pidfile = '/tmp/lighttpd/lighttpd.pid';
-my $pidoffile = '/tmp/lighttpd/pidof.pid';
-
-sub pidof {
- my $prog = $_[0];
-
- open F, "ps ax | grep $prog | awk '{ print \$1 }'|" or
- open F, "ps -ef | grep $prog | awk '{ print \$2 }'|" or
- return -1;
-
- my $pid = <F>;
- close F;
-
- return $pid;
-}
-
-sub stop_proc {
- open F, $pidfile or return -1;
- my $pid = <F>;
- close F;
-
- kill('TERM',$pid) or return -1;
- select(undef, undef, undef, 0.01);
-
- return 0;
-}
-
-
-sub start_proc {
- # kill old proc if necessary
- stop_proc;
-
- unlink($pidfile);
- system($lighttpd_path." -f ".$configfile);
-
- if (-e $pidfile) {
- return 0;
- } else {
- return -1;
- }
-}
-
-sub handle_http {
- my $EOL = "\015\012";
- my $BLANK = $EOL x 2;
- my $port = 2048;
- my $host = "127.0.0.1";
-
- my $remote =
- IO::Socket::INET->new(Proto => "tcp",
- PeerAddr => $host,
- PeerPort => $port)
- or return -1;
-
- $remote->autoflush(1);
-
- foreach(@request) {
- # pipeline requests
- s/\r//g;
- s/\n/$EOL/g;
-
- print $remote $_.$BLANK;
- }
-
- my $lines = "";
-
- # read everything
- while(<$remote>) {
- $lines .= $_;
- }
-
- close $remote;
-
- my $href;
- foreach $href (@response) {
- # first line is always response header
- my %resp_hdr;
- my $resp_body;
- my $resp_line;
- my $conditions = $_;
-
- for (my $ln = 0; defined $lines; $ln++) {
- (my $line, $lines) = split($EOL, $lines, 2);
-
- # header finished
- last if(length($line) == 0);
-
- if ($ln == 0) {
- # response header
- $resp_line = $line;
- } else {
- # response vars
-
- if ($line =~ /^([^:]+):\s*(.+)$/) {
- (my $h = $1) =~ tr/[A-Z]/[a-z]/;
-
- $resp_hdr{$h} = $2;
- } else {
- return -1;
- }
- }
- }
-
- # check length
- if (defined $resp_hdr{"content-length"}) {
- ($resp_body, $lines) = split("^.".$resp_hdr{"content-length"}, $lines, 2);
- } else {
- $resp_body = $lines;
- undef $lines;
- }
-
- # check conditions
- if ($resp_line =~ /^(HTTP\/1\.[01]) ([0-9]{3}) .+$/) {
- if ($href->{'HTTP-Protocol'} ne $1) {
- diag(sprintf("proto failed: expected '%s', got '%s'\n", $href->{'HTTP-Protocol'}, $1));
- return -1;
- }
- if ($href->{'HTTP-Status'} ne $2) {
- diag(sprintf("status failed: expected '%s', got '%s'\n", $href->{'HTTP-Status'}, $2));
- return -1;
- }
- } else {
- return -1;
- }
-
- if (defined $href->{'HTTP-Content'}) {
- if ($href->{'HTTP-Content'} ne $resp_body) {
- diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body));
- return -1;
- }
- }
-
- if (defined $href->{'-HTTP-Content'}) {
- if (defined $resp_body && $resp_body ne '') {
- diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body));
- return -1;
- }
- }
-
- foreach (keys %{ $href }) {
- next if $_ eq 'HTTP-Protocol';
- next if $_ eq 'HTTP-Status';
- next if $_ eq 'HTTP-Content';
- next if $_ eq '-HTTP-Content';
-
- (my $k = $_) =~ tr/[A-Z]/[a-z]/;
-
- my $no_val = 0;
-
- if (substr($k, 0, 1) eq '+') {
- $k = substr($k, 1);
- $no_val = 1;
-
- }
-
- if (!defined $resp_hdr{$k}) {
- diag(sprintf("required header '%s' is missing\n", $k));
- return -1;
- }
-
- if ($no_val == 0 &&
- $href->{$_} ne $resp_hdr{$k}) {
- diag(sprintf("response-header failed: expected '%s', got '%s'\n", $href->{$_}, $resp_hdr{$k}));
- return -1;
- }
- }
- }
-
- # we should have sucked up everything
- return -1 if (defined $lines);
-
- return 0;
-}
+my $tf = LightyTest->new();
+my $t;
-ok(start_proc == 0, "Starting lighttpd") or die();
+ok($tf->start_proc == 0, "Starting lighttpd") or die();
## Basic Request-Handling
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /foobar HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
-ok(handle_http == 0, 'file not found');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
+ok($tf->handle_http($t) == 0, 'file not found');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /foobar?foobar HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
-ok(handle_http == 0, 'file not found + querystring');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
+ok($tf->handle_http($t) == 0, 'file not found + querystring');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /12345.txt HTTP/1.0
Host: 123.example.org
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'text/plain' } );
-ok(handle_http == 0, 'GET, content == 12345, mimetype text/plain');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'text/plain' } );
+ok($tf->handle_http($t) == 0, 'GET, content == 12345, mimetype text/plain');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /12345.html HTTP/1.0
Host: 123.example.org
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'text/html' } );
-ok(handle_http == 0, 'GET, content == 12345, mimetype text/html');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'text/html' } );
+ok($tf->handle_http($t) == 0, 'GET, content == 12345, mimetype text/html');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /dummyfile.bla HTTP/1.0
Host: 123.example.org
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'application/octet-stream' } );
-ok(handle_http == 0, 'GET, content == 12345, mimetype application/octet-stream');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'application/octet-stream' } );
+ok($tf->handle_http($t) == 0, 'GET, content == 12345, mimetype application/octet-stream');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
POST / HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 411 } );
-ok(handle_http == 0, 'POST request, no Content-Length');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 411 } );
+ok($tf->handle_http($t) == 0, 'POST request, no Content-Length');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
POST / HTTP/1.0
Content-type: application/x-www-form-urlencoded
Content-length: 0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'POST request, empty request-body');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'POST request, empty request-body');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
HEAD / HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '-HTTP-Content' => ''} );
-ok(handle_http == 0, 'HEAD request, no content');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '-HTTP-Content' => ''} );
+ok($tf->handle_http($t) == 0, 'HEAD request, no content');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
HEAD /12345.html HTTP/1.0
Host: 123.example.org
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '-HTTP-Content' => '', 'Content-Type' => 'text/html', 'Content-Length' => '6'} );
-ok(handle_http == 0, 'HEAD request, mimetype text/html, content-length');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '-HTTP-Content' => '', 'Content-Type' => 'text/html', 'Content-Length' => '6'} );
+ok($tf->handle_http($t) == 0, 'HEAD request, mimetype text/html, content-length');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
HEAD /foobar?foobar HTTP/1.0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, '-HTTP-Content' => '' } );
-ok(handle_http == 0, 'HEAD request, file-not-found, query-string');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, '-HTTP-Content' => '' } );
+ok($tf->handle_http($t) == 0, 'HEAD request, file-not-found, query-string');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.1
Connection: close
Expect: 100-continue
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 417, '-HTTP-Content' => ''} );
-ok(handle_http == 0, 'Continue, Expect');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 417, '-HTTP-Content' => ''} );
+ok($tf->handle_http($t) == 0, 'Continue, Expect');
## ranges
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /12345.txt HTTP/1.0
Host: 123.example.org
Range: bytes=0-3
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '1234' } );
-ok(handle_http == 0, 'GET, Range 0-3');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '1234' } );
+ok($tf->handle_http($t) == 0, 'GET, Range 0-3');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /12345.txt HTTP/1.0
Host: 123.example.org
Range: bytes=-3
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '45'."\n" } );
-ok(handle_http == 0, 'GET, Range -3');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '45'."\n" } );
+ok($tf->handle_http($t) == 0, 'GET, Range -3');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /12345.txt HTTP/1.0
Host: 123.example.org
Range: bytes=3-
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '45'."\n" } );
-ok(handle_http == 0, 'GET, Range 3-');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '45'."\n" } );
+ok($tf->handle_http($t) == 0, 'GET, Range 3-');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /12345.txt HTTP/1.0
Host: 123.example.org
Range: bytes=0-1,3-4
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => <<EOF
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => <<EOF
\r
--fkj49sn38dcn3\r
Content-Range: bytes 0-1/6\r
@@ -326,33 +148,33 @@ Content-Type: text/plain\r
--fkj49sn38dcn3--\r
EOF
} );
-ok(handle_http == 0, 'GET, Range 0-1,3-4');
+ok($tf->handle_http($t) == 0, 'GET, Range 0-1,3-4');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /12345.txt HTTP/1.0
Host: 123.example.org
Range: bytes=0--
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'GET, Range 0--');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'GET, Range 0--');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /12345.txt HTTP/1.0
Host: 123.example.org
Range: bytes=-2-3
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'GET, Range -2-3');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'GET, Range -2-3');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /12345.txt HTTP/1.0
Host: 123.example.org
Range: bytes=-0
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 416, 'HTTP-Content' => <<EOF
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 416, 'HTTP-Content' => <<EOF
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@@ -366,15 +188,15 @@ EOF
</html>
EOF
} );
-ok(handle_http == 0, 'GET, Range -0');
+ok($tf->handle_http($t) == 0, 'GET, Range -0');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET /12345.txt HTTP/1.0
Host: 123.example.org
Range: bytes=25-
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 416, 'HTTP-Content' => <<EOF
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 416, 'HTTP-Content' => <<EOF
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@@ -389,10 +211,10 @@ EOF
EOF
} );
-ok(handle_http == 0, 'GET, Range start out of range');
+ok($tf->handle_http($t) == 0, 'GET, Range start out of range');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Hsgfsdjf: asdfhdf
hdhd: shdfhfdasd
@@ -405,66 +227,66 @@ nfj: jgfdjdfg
jfue: jfdfdg
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
-ok(handle_http == 0, 'larger headers');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
+ok($tf->handle_http($t) == 0, 'larger headers');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Host: www.example.org
Host: 123.example.org
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'Duplicate Host headers, Bug #25');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'Duplicate Host headers, Bug #25');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Content-Length: 5
Content-Length: 4
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'Duplicate Content-Length headers');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'Duplicate Content-Length headers');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Content-Type: 5
Content-Type: 4
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'Duplicate Content-Type headers');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'Duplicate Content-Type headers');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
Range: bytes=5-6
Range: bytes=5-9
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'Duplicate Range headers');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'Duplicate Range headers');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
If-None-Match: 5
If-None-Match: 4
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'Duplicate If-None-Match headers');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'Duplicate If-None-Match headers');
-@request = ( <<EOF
+$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
If-Modified-Since: 5
If-Modified-Since: 4
EOF
);
-@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
-ok(handle_http == 0, 'Duplicate If-Modified-Since headers');
+$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } );
+ok($tf->handle_http($t) == 0, 'Duplicate If-Modified-Since headers');
-ok(stop_proc == 0, "Stopping lighttpd");
+ok($tf->stop_proc == 0, "Stopping lighttpd");