summaryrefslogtreecommitdiff
path: root/regress/usr.sbin
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2017-02-01 10:26:07 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2017-02-01 10:26:07 +0000
commit30f4eb4ce3be181c314bf689c3b30143e1d1a09c (patch)
tree42ffe3325a0c68f6976e936f1dda53c45da4b004 /regress/usr.sbin
parent21c579cbc81eaf555708a4893ed3feafb328eac4 (diff)
Add Range and multipart tests.
Diffstat (limited to 'regress/usr.sbin')
-rw-r--r--regress/usr.sbin/httpd/tests/args-get-range-512.pl19
-rw-r--r--regress/usr.sbin/httpd/tests/args-get-range-multipart.pl19
-rw-r--r--regress/usr.sbin/httpd/tests/args-tls-get-range-512.pl23
-rw-r--r--regress/usr.sbin/httpd/tests/args-tls-get-range-multipart.pl23
-rw-r--r--regress/usr.sbin/httpd/tests/funcs.pl77
5 files changed, 156 insertions, 5 deletions
diff --git a/regress/usr.sbin/httpd/tests/args-get-range-512.pl b/regress/usr.sbin/httpd/tests/args-get-range-512.pl
new file mode 100644
index 00000000000..6247f2768b7
--- /dev/null
+++ b/regress/usr.sbin/httpd/tests/args-get-range-512.pl
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+
+my $len = 512;
+my $path = 1048576;
+our %args = (
+ client => {
+ path => $path,
+ http_vers => [ "1.1" ],
+ code => "206 Partial Content",
+ header => {
+ "Range" => "bytes=0-511",
+ }
+ },
+ len => $len,
+ md5 => path_md5("$len")
+);
+
+1;
diff --git a/regress/usr.sbin/httpd/tests/args-get-range-multipart.pl b/regress/usr.sbin/httpd/tests/args-get-range-multipart.pl
new file mode 100644
index 00000000000..cd2abae0b6e
--- /dev/null
+++ b/regress/usr.sbin/httpd/tests/args-get-range-multipart.pl
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+
+my $len = 512;
+our %args = (
+ client => {
+ path => $len,
+ http_vers => [ "1.1" ],
+ code => "206 Partial Content",
+ header => {
+ "Range" => "bytes=0-255,256-300,301-",
+ },
+ multipart => 1
+ },
+ len => $len,
+ md5 => path_md5("$len")
+);
+
+1;
diff --git a/regress/usr.sbin/httpd/tests/args-tls-get-range-512.pl b/regress/usr.sbin/httpd/tests/args-tls-get-range-512.pl
new file mode 100644
index 00000000000..fad092cc1ab
--- /dev/null
+++ b/regress/usr.sbin/httpd/tests/args-tls-get-range-512.pl
@@ -0,0 +1,23 @@
+use strict;
+use warnings;
+
+my $len = 512;
+my $path = 1048576;
+our %args = (
+ client => {
+ path => $path,
+ http_vers => [ "1.1" ],
+ code => "206 Partial Content",
+ header => {
+ "Range" => "bytes=0-511",
+ },
+ tls => 1
+ },
+ httpd => {
+ listentls => 1
+ },
+ len => $len,
+ md5 => path_md5("$len")
+);
+
+1;
diff --git a/regress/usr.sbin/httpd/tests/args-tls-get-range-multipart.pl b/regress/usr.sbin/httpd/tests/args-tls-get-range-multipart.pl
new file mode 100644
index 00000000000..aa61904f378
--- /dev/null
+++ b/regress/usr.sbin/httpd/tests/args-tls-get-range-multipart.pl
@@ -0,0 +1,23 @@
+use strict;
+use warnings;
+
+my $len = 1048576;
+our %args = (
+ client => {
+ path => $len,
+ http_vers => [ "1.1" ],
+ code => "206 Partial Content",
+ header => {
+ "Range" => "bytes=0-255,256-10240,10241-",
+ },
+ multipart => 1,
+ tls => 1
+ },
+ httpd => {
+ listentls => 1
+ },
+ len => $len,
+ md5 => path_md5("$len")
+);
+
+1;
diff --git a/regress/usr.sbin/httpd/tests/funcs.pl b/regress/usr.sbin/httpd/tests/funcs.pl
index beda09ac5f6..2707c144c19 100644
--- a/regress/usr.sbin/httpd/tests/funcs.pl
+++ b/regress/usr.sbin/httpd/tests/funcs.pl
@@ -1,4 +1,4 @@
-# $OpenBSD: funcs.pl,v 1.6 2016/05/03 19:13:04 bluhm Exp $
+# $OpenBSD: funcs.pl,v 1.7 2017/02/01 10:26:06 reyk Exp $
# Copyright (c) 2010-2015 Alexander Bluhm <bluhm@openbsd.org>
#
@@ -188,9 +188,12 @@ sub http_request {
sub http_response {
my ($self, $len) = @_;
my $method = $self->{method} || "GET";
+ my $code = $self->{code} || "200 OK";
my $vers;
my $chunked = 0;
+ my $multipart = 0;
+ my $boundary;
{
local $/ = "\r\n";
local $_ = <STDIN>;
@@ -198,8 +201,8 @@ sub http_response {
or die ref($self), " missing http $len response";
chomp;
print STDERR "<<< $_\n";
- m{^HTTP/(\d\.\d) 200 OK$}
- or die ref($self), " http response not ok"
+ m{^HTTP/(\d\.\d) $code$}
+ or die ref($self), " http response not $code"
unless $self->{httpnok};
$vers = $1;
while (<STDIN>) {
@@ -207,7 +210,7 @@ sub http_response {
print STDERR "<<< $_\n";
last if /^$/;
if (/^Content-Length: (.*)/) {
- if ($self->{httpnok}) {
+ if ($self->{httpnok} or $self->{multipart}) {
$len = $1;
} else {
$1 == $len or die ref($self),
@@ -217,9 +220,18 @@ sub http_response {
if (/^Transfer-Encoding: chunked$/) {
$chunked = 1;
}
+ if (/^Content-Type: multipart\/byteranges; boundary=(.*)$/) {
+ $multipart = 1;
+ $boundary = $1;
+ }
}
}
- if ($chunked) {
+ die ref($self), " no multipart response"
+ if ($self->{multipart} && $multipart == 0);
+
+ if ($multipart) {
+ read_multipart($self, $boundary);
+ } elsif ($chunked) {
read_chunked($self);
} else {
#$len = $vers eq "1.1" ? $len : undef;
@@ -265,6 +277,61 @@ sub read_chunked {
}
}
+sub read_multipart {
+ my $self = shift;
+ my $boundary = shift;
+ my $ctx = Digest::MD5->new();
+ my $len = 0;
+
+ for (;;) {
+ my $part = 0;
+ {
+ local $/ = "\r\n";
+ local $_ = <STDIN>;
+ local $_ = <STDIN>;
+ defined or die ref($self), " missing boundary";
+ chomp;
+ print STDERR "<<< $_\n";
+ /^--$boundary(--)?$/
+ or die ref($self), " boundary not found: $_";
+ if (not $1) {
+ while (<STDIN>) {
+ chomp;
+ if (/^Content-Length: (.*)/) {
+ $part = $1;
+ }
+ if (/^Content-Range: bytes (\d+)-(\d+)\/(\d+)$/) {
+ $part = $2 - $1 + 1;
+ }
+ print STDERR "<<< $_\n";
+ last if /^$/;
+ }
+ }
+ }
+ last unless $part > 0;
+
+ my $max = $part;
+ my $rlen = POSIX::BUFSIZ;
+ my $r;
+ do {
+ if ($rlen > $max) {
+ $rlen = $max;
+ }
+ $r = read(STDIN, my $buf, $rlen);
+ last if not $r;
+ $_ = $buf;
+ $ctx->add($_);
+ $max = $max - $r;
+ } while ($max && $r == $rlen);
+
+ $len = $len + $part;
+ }
+
+ print STDERR "LEN: ", $len, "\n";
+ print STDERR "MD5: ", $ctx->hexdigest, "\n";
+
+}
+
sub errignore {
$SIG{PIPE} = 'IGNORE';
$SIG{__DIE__} = sub {