summaryrefslogtreecommitdiff
path: root/tests/core-request.t
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2018-04-21 17:23:17 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2018-08-05 03:44:15 -0400
commit1b62dc325c0c1ecba1bb993a4111310cd4c798c7 (patch)
tree1690c969d76a842998f28644a70c6fbc6f6c0938 /tests/core-request.t
parente8c1efd5dfc11b5001113198741536648067c024 (diff)
downloadlighttpd1.4-1b62dc325c0c1ecba1bb993a4111310cd4c798c7.tar.gz
lighttpd1.4-1b62dc325c0c1ecba1bb993a4111310cd4c798c7.zip
[tests] test_request unit tests
unit tests for request processing collect existing request processing tests from Perl tests/*.t (test_request.c runs *much* more quickly than Perl tests/*.t)
Diffstat (limited to 'tests/core-request.t')
-rwxr-xr-xtests/core-request.t256
1 files changed, 15 insertions, 241 deletions
diff --git a/tests/core-request.t b/tests/core-request.t
index 6cbfb718..6de62f85 100755
--- a/tests/core-request.t
+++ b/tests/core-request.t
@@ -8,7 +8,7 @@ BEGIN {
use strict;
use IO::Socket;
-use Test::More tests => 38;
+use Test::More tests => 12;
use LightyTest;
my $tf = LightyTest->new();
@@ -16,216 +16,46 @@ my $t;
ok($tf->start_proc == 0, "Starting lighttpd") or die();
-## Low-Level Request-Header Parsing - URI
-
-$t->{REQUEST} = ( <<EOF
-GET /index%2ehtml HTTP/1.0
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
-ok($tf->handle_http($t) == 0, 'URL-encoding');
-
-$t->{REQUEST} = ( <<EOF
-GET /index.html%00 HTTP/1.0
-EOF
- );
-$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
$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
-Host: www.example.org
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
-ok($tf->handle_http($t) == 0, 'hostname');
+ok($tf->handle_http($t) == 0, 'Valid HTTP/1.0 Request') or die();
$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: 127.0.0.1
+OPTIONS * HTTP/1.0
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
-ok($tf->handle_http($t) == 0, 'IPv4 address');
+ok($tf->handle_http($t) == 0, 'OPTIONS');
$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: [::1]
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
-ok($tf->handle_http($t) == 0, 'IPv6 address');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: www.example.org:80
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
-ok($tf->handle_http($t) == 0, 'hostname + port');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: 127.0.0.1:80
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
-ok($tf->handle_http($t) == 0, 'IPv4 address + port');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: [::1]:80
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
-ok($tf->handle_http($t) == 0, 'IPv6 address + port');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: ../123.org
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'directory traversal');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: .jsdh.sfdg.sdfg.
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'leading and trailing dot');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: jsdh.sfdg.sdfg.
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
-ok($tf->handle_http($t) == 0, 'trailing dot is ok');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: .jsdh.sfdg.sdfg
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'leading dot');
-
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: jsdh..sfdg.sdfg
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'two dots');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: jsdh.sfdg.sdfg:asd
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'broken port-number');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: jsdh.sfdg.sdfg:-1
+OPTIONS / HTTP/1.1
+Host: www.example.org
+Connection: close
EOF
);
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'negative port-number');
-
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200 } ];
+ok($tf->handle_http($t) == 0, 'OPTIONS');
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: :80
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'port given but host missing');
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: .jsdh.sfdg.:sdfg.
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'port and host are broken');
+## Low-Level Request-Header Parsing - URI
$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: a.b-c.d123
+GET /index%2ehtml HTTP/1.0
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
-ok($tf->handle_http($t) == 0, 'allowed characters in host-name');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: -a.c
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'leading dash');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: .
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'dot only');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: a192.168.2.10:1234
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'broken IPv4 address - non-digit');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: 192.168.2:1234
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'broken IPv4 address - too short');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: [::1]' UNION SELECT '/
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'IPv6 address + SQL injection');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Host: [::1]/../../../
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'IPv6 address + path traversal');
-
-
-
-## Low-Level Request-Header Parsing - Content-Length
-
+ok($tf->handle_http($t) == 0, 'URL-encoding');
$t->{REQUEST} = ( <<EOF
-GET /index.html HTTP/1.0
-Content-Length: -2
+GET /index.html%00 HTTP/1.0
EOF
);
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'negative Content-Length');
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
+ok($tf->handle_http($t) == 0, 'URL-encoding, %00');
$t->{REQUEST} = ( <<EOF
POST /12345.txt HTTP/1.0
@@ -236,22 +66,6 @@ EOF
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 413 } ];
ok($tf->handle_http($t) == 0, 'Content-Length > max-request-size');
-$t->{REQUEST} = ( <<EOF
-POST /12345.txt HTTP/1.0
-Host: 123.example.org
-Content-Length:
-EOF
- );
-$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";
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.1
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'Host missing');
print "\nContent-Type\n";
$t->{REQUEST} = ( <<EOF
@@ -276,51 +90,11 @@ $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Conte
ok($tf->handle_http($t) == 0, 'Content-Type - unknown');
$t->{REQUEST} = ( <<EOF
-GET HTTP/1.0
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
-ok($tf->handle_http($t) == 0, 'empty request-URI');
-
-$t->{REQUEST} = ( <<EOF
GET /Foo.txt HTTP/1.0
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
ok($tf->handle_http($t) == 0, 'uppercase filenames');
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Location: foo
-Location: foobar
- baz
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
-ok($tf->handle_http($t) == 0, '#1232 - duplicate headers with line-wrapping');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-Location:
-Location: foobar
- baz
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
-ok($tf->handle_http($t) == 0, '#1232 - duplicate headers with line-wrapping - test 2');
-
-$t->{REQUEST} = ( <<EOF
-GET / HTTP/1.0
-A:
-Location: foobar
- baz
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
-ok($tf->handle_http($t) == 0, '#1232 - duplicate headers with line-wrapping - test 3');
-
-
-
ok($tf->stop_proc == 0, "Stopping lighttpd");
-