git-svn-id: svn://svn.lighttpd.net/lighttpd/trunk@99 152afb58-edef-0310-8abb-c4023f1b3aa9svn/tags/release-1.3.13
parent
e1fb43d9dd
commit
8810ff2602
@ -1,164 +0,0 @@
|
||||
#! /usr/bin/perl -w
|
||||
|
||||
use strict;
|
||||
use IO::Socket;
|
||||
|
||||
my $EOL = "\015\012";
|
||||
my $BLANK = $EOL x 2;
|
||||
|
||||
|
||||
my @f = <STDIN>;
|
||||
|
||||
# drop first line
|
||||
my $headline = shift @f;
|
||||
chomp $headline;
|
||||
printf STDERR "%-40s", $headline." ";
|
||||
|
||||
|
||||
my $remote =
|
||||
IO::Socket::INET->new(Proto => "tcp",
|
||||
PeerAddr => "127.0.0.1",
|
||||
PeerPort => $#ARGV == 0 ? "1025" : "2048")
|
||||
or die "cannot connect to remote host";
|
||||
|
||||
$remote->autoflush(1);
|
||||
|
||||
my %y;
|
||||
my $m = 0;
|
||||
my $line = 0;
|
||||
my $method;
|
||||
foreach(@f) {
|
||||
if (/^$/) {
|
||||
$m = 1;
|
||||
next;
|
||||
}
|
||||
|
||||
chomp;
|
||||
if ($m == 0) {
|
||||
# header line
|
||||
#
|
||||
if ($line++ == 0) {
|
||||
($method = $_ ) =~ s/ .*//;
|
||||
}
|
||||
print $remote $_.$EOL;
|
||||
} else {
|
||||
my ($key, $value) = split /: /, $_;
|
||||
|
||||
$y{$key} = $value;
|
||||
}
|
||||
}
|
||||
print $remote $EOL;
|
||||
|
||||
my $ln = 0;
|
||||
my $error = 0;
|
||||
my $con_len = -1;
|
||||
my $body = "";
|
||||
$m = 0;
|
||||
|
||||
my %header;
|
||||
while(<$remote>) {
|
||||
$ln++;
|
||||
|
||||
# print STDERR $_;
|
||||
|
||||
if ($ln == 1) {
|
||||
if (/^HTTP/) {
|
||||
my ($proto, $status, $text) = split / /, $_, 3;
|
||||
if (defined $y{"Status"}) {
|
||||
if ($status ne $y{"Status"}) {
|
||||
$error = 1;
|
||||
print STDERR "E: wrong Status code - ";
|
||||
}
|
||||
}
|
||||
} elsif ($y{"Protocol"} eq "HTTP/0.9") {
|
||||
# we expected HTTP/0.9 or Bad Protocol
|
||||
$m = 1;
|
||||
} else {
|
||||
$error = 1;
|
||||
print STDERR "E: broken something - ";
|
||||
}
|
||||
} elsif ($m == 0) {
|
||||
# response header
|
||||
my ($key, $value) = split /: /, $_;
|
||||
|
||||
if (not /^\r$/) {
|
||||
($header{$key} = $value) =~ s/\r\n$//;
|
||||
}
|
||||
}
|
||||
|
||||
# grep for content-length
|
||||
if (/^Content-Length: ([0-9]+)\r$/) {
|
||||
$con_len = $1;
|
||||
}
|
||||
|
||||
if ($m == 1) {
|
||||
$body .= $_;
|
||||
}
|
||||
|
||||
if (/^\r$/) {
|
||||
$m = 1;
|
||||
}
|
||||
|
||||
print $_;
|
||||
|
||||
if ($m == 1 && (length($body) == $con_len)) {
|
||||
# print STDERR length($body)." - ".$con_len."\n";
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
close $remote;
|
||||
|
||||
if ($con_len != -1 && $method ne "HEAD" && $m == 1 && (length($body) != $con_len)) {
|
||||
$error = 1;
|
||||
print STDERR "E: wrong content-length - ";
|
||||
}
|
||||
|
||||
# check the MUST header
|
||||
|
||||
if (defined $y{"MUST"}) {
|
||||
foreach (split / /, $y{"MUST"}) {
|
||||
if (not defined $header{$_}) {
|
||||
$error = 1;
|
||||
print STDERR "E: MUST missing - ";
|
||||
}
|
||||
}
|
||||
}
|
||||
my $might = 0;
|
||||
if (defined $y{"MIGHT"}) {
|
||||
foreach (split / /, $y{"MIGHT"}) {
|
||||
if (not defined $header{$_}) {
|
||||
$might = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defined $y{"Content"}) {
|
||||
if ($body ne $y{"Content"}) {
|
||||
$error = 1;
|
||||
print STDERR "E: Content doesn't match - ";
|
||||
}
|
||||
}
|
||||
|
||||
foreach (keys %y) {
|
||||
next if /^MIGHT$/;
|
||||
next if /^MUST$/;
|
||||
next if /^Status$/;
|
||||
next if /^Protocol$/;
|
||||
next if /^Content$/;
|
||||
|
||||
if ((not defined $header{$_}) ||
|
||||
($header{$_} ne $y{$_})) {
|
||||
$error = 1;
|
||||
print STDERR "E: headerline missing - ";
|
||||
}
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
exit 1;
|
||||
} elsif ($might) {
|
||||
exit 77;
|
||||
} else {
|
||||
exit 0;
|
||||
}
|
||||
|
@ -0,0 +1,233 @@
|
||||
#! /usr/bin/perl -w
|
||||
|
||||
use strict;
|
||||
use IO::Socket;
|
||||
use Test::More tests => 5;
|
||||
|
||||
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 | awk '{ print \$1 }'|" or
|
||||
open F, "ps -ef | grep $prog | 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;
|
||||
}
|
||||
|
||||
|
||||
SKIP: {
|
||||
skip "no PHP running on port 1026", 5 if pidof("php") == -1;
|
||||
|
||||
ok(start_proc == 0, "Starting lighttpd") or die();
|
||||
|
||||
@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');
|
||||
|
||||
@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');
|
||||
|
||||
@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');
|
||||
|
||||
ok(stop_proc == 0, "Stopping lighttpd");
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
exitcode=0
|
||||
lighttpdpid=0
|
||||
prepare_test () {
|
||||
test -x $srcdir/conformance.pl || exit 77
|
||||
|
||||
NAME=`basename $0 | sed s/\.sh$//`
|
||||
if which mktemp > /dev/null; then
|
||||
TMPFILE=`mktemp /tmp/$NAME.XXXXXX` || exit 1;
|
||||
else
|
||||
TMPFILE=/tmp/$NAME.XXXXXX
|
||||
fi
|
||||
|
||||
if test x$top_builddir != x; then
|
||||
# not in stand-alone mode
|
||||
if test -f /tmp/lighttpd/lighttpd.pid; then
|
||||
kill `cat /tmp/lighttpd/lighttpd.pid`
|
||||
rm -f /tmp/lighttpd/lighttpd.pid
|
||||
fi
|
||||
|
||||
# start webserver
|
||||
CONF=`echo $0 | sed s/\.sh$/.conf/`
|
||||
#VALGRIND='valgrind --tool=memcheck --logfile=lighttpd'
|
||||
VALGRIND=
|
||||
if test -e $CONF; then
|
||||
$VALGRIND $top_builddir/src/lighttpd -f $CONF
|
||||
else
|
||||
$VALGRIND $top_builddir/src/lighttpd -f $srcdir/lighttpd.conf
|
||||
fi
|
||||
test x$? = x0 || exit 1
|
||||
|
||||
# ps ax > $NAME.psax
|
||||
fi
|
||||
}
|
||||
|
||||
run_test_script () {
|
||||
if test x$top_builddir = x; then
|
||||
cat $TMPFILE | $srcdir/conformance.pl standalone > $NAME.out
|
||||
else
|
||||
cat $TMPFILE | $srcdir/conformance.pl > $NAME.out
|
||||
fi
|
||||
|
||||
exitcode=$?
|
||||
}
|
||||
|
||||
run_test_exit () {
|
||||
if test x$top_builddir != x; then
|
||||
# stop webserver
|
||||
kill `cat /tmp/lighttpd/lighttpd.pid` || exit 1
|
||||
rm -f /tmp/lighttpd/lighttpd.pid
|
||||
fi
|
||||
|
||||
if test x$exitcode = x0; then
|
||||
rm $NAME.out;
|
||||
fi;
|
||||
rm -f $TMPFILE
|
||||
|
||||
exit $exitcode;
|
||||
}
|
||||
|
||||
run_test () {
|
||||
run_test_script
|
||||
run_test_exit
|
||||
}
|
Loading…
Reference in new issue