2005-09-01 11:44:57 +00:00
|
|
|
#!/usr/bin/env perl
|
2005-06-26 10:27:41 +00:00
|
|
|
BEGIN {
|
2008-01-15 22:03:59 +00:00
|
|
|
# add current source dir to the include-path
|
|
|
|
# we need this for make distcheck
|
|
|
|
(my $srcdir = $0) =~ s,/[^/]+$,/,;
|
|
|
|
unshift @INC, $srcdir;
|
2005-06-26 10:27:41 +00:00
|
|
|
}
|
|
|
|
|
2005-03-02 11:27:02 +00:00
|
|
|
use strict;
|
|
|
|
use IO::Socket;
|
2005-06-12 09:09:28 +00:00
|
|
|
use Test::More tests => 12;
|
2005-06-15 09:37:18 +00:00
|
|
|
use LightyTest;
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
my $tf = LightyTest->new();
|
|
|
|
my $t;
|
2006-10-05 00:09:51 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->start_proc == 0, "Starting lighttpd") or die();
|
2005-03-02 11:27:02 +00:00
|
|
|
|
|
|
|
## Low-Level Response-Header Parsing - HTTP/1.1
|
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-02 11:27:02 +00:00
|
|
|
GET / HTTP/1.1
|
|
|
|
Host: www.example.org
|
|
|
|
Connection: close
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, '+Date' => '' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'Date header');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-02 11:27:02 +00:00
|
|
|
GET / HTTP/1.1
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 400, 'Connection' => 'close' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'Host missing');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-06-12 09:09:28 +00:00
|
|
|
GET / HTTP/1.0
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+ETag' => '' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'ETag is set');
|
2005-06-12 09:09:28 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-06-12 09:09:28 +00:00
|
|
|
GET / HTTP/1.0
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'ETag' => '/^".+"$/' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'ETag has quotes');
|
2005-06-12 09:09:28 +00:00
|
|
|
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-03-04 13:10:35 +00:00
|
|
|
|
2005-03-02 11:27:02 +00:00
|
|
|
## Low-Level Response-Header Parsing - Content-Length
|
|
|
|
|
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-02 11:27:02 +00:00
|
|
|
GET /12345.html HTTP/1.0
|
|
|
|
Host: 123.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'Content-Length for text/html');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-02 11:27:02 +00:00
|
|
|
GET /12345.txt HTTP/1.0
|
|
|
|
Host: 123.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'Content-Length for text/plain');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
## Low-Level Response-Header Parsing - Location
|
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-02 11:27:02 +00:00
|
|
|
GET /dummydir HTTP/1.0
|
|
|
|
EOF
|
|
|
|
);
|
2005-09-01 11:12:05 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://'.$tf->{HOSTNAME}.':'.$tf->{PORT}.'/dummydir/' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'internal redirect in directory');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-02 11:27:02 +00:00
|
|
|
GET /dummydir?foo HTTP/1.0
|
|
|
|
EOF
|
|
|
|
);
|
2005-09-01 11:12:05 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://'.$tf->{HOSTNAME}.':'.$tf->{PORT}.'/dummydir/?foo' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'internal redirect in directory + querystring');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-03-04 13:10:35 +00:00
|
|
|
## simple-vhost
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-04 13:10:35 +00:00
|
|
|
GET /12345.txt HTTP/1.0
|
|
|
|
Host: no-simple.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'disabling simple-vhost via conditionals');
|
2005-03-04 13:10:35 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
$t->{REQUEST} = ( <<EOF
|
2005-03-04 13:10:35 +00:00
|
|
|
GET /12345.txt HTTP/1.0
|
|
|
|
Host: simple.example.org
|
|
|
|
EOF
|
|
|
|
);
|
2005-08-31 12:55:44 +00:00
|
|
|
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->handle_http($t) == 0, 'simple-vhost via conditionals');
|
2005-03-02 11:27:02 +00:00
|
|
|
|
2005-06-15 09:37:18 +00:00
|
|
|
ok($tf->stop_proc == 0, "Stopping lighttpd");
|
2005-03-02 11:27:02 +00:00
|
|
|
|