summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2013-02-07 22:56:28 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2013-02-07 22:56:28 +0000
commitc0c3d14f297c1e7d149229f1bcf8730dcb551ad2 (patch)
tree263fcd71c46e15670d874e3b90cba357e61b5199 /regress
parent3e47d2b6fb93a16503e0b7af5c1c361251b570df (diff)
Add relayd regression tests with http filter and late connect.
Diffstat (limited to 'regress')
-rw-r--r--regress/usr.sbin/relayd/args-http-filter-block.pl29
-rw-r--r--regress/usr.sbin/relayd/args-http-filter-contentlength.pl27
-rw-r--r--regress/usr.sbin/relayd/args-http-filter-put-contentlength.pl28
-rw-r--r--regress/usr.sbin/relayd/args-http-filter-put.pl25
-rw-r--r--regress/usr.sbin/relayd/args-http-filter.pl24
-rw-r--r--regress/usr.sbin/relayd/funcs.pl52
-rw-r--r--regress/usr.sbin/relayd/relayd.pl10
-rw-r--r--regress/usr.sbin/relayd/remote.pl12
8 files changed, 178 insertions, 29 deletions
diff --git a/regress/usr.sbin/relayd/args-http-filter-block.pl b/regress/usr.sbin/relayd/args-http-filter-block.pl
new file mode 100644
index 00000000000..56b8556dba4
--- /dev/null
+++ b/regress/usr.sbin/relayd/args-http-filter-block.pl
@@ -0,0 +1,29 @@
+# test http connection with request block filter, tests lateconnect
+
+use strict;
+use warnings;
+
+our %args = (
+ client => {
+ func => sub {
+ eval { http_client(@_) };
+ warn $@;
+ $@ =~ /missing http 1 response/
+ or die "http not filtered";
+ },
+ len => 1,
+ nocheck => 1,
+ },
+ relayd => {
+ protocol => [ "http",
+ 'request path filter "/1"',
+ ],
+ loggrep => qr/rejecting request/,
+ },
+ server => {
+ noserver => 1,
+ nocheck => 1,
+ },
+);
+
+1;
diff --git a/regress/usr.sbin/relayd/args-http-filter-contentlength.pl b/regress/usr.sbin/relayd/args-http-filter-contentlength.pl
new file mode 100644
index 00000000000..70450528041
--- /dev/null
+++ b/regress/usr.sbin/relayd/args-http-filter-contentlength.pl
@@ -0,0 +1,27 @@
+# test http connection with request filter and explicit content length 0
+
+use strict;
+use warnings;
+
+our %args = (
+ client => {
+ func => \&http_client,
+ header => {
+ 'Content-Length' => 0,
+ },
+ len => 1,
+ },
+ relayd => {
+ protocol => [ "http",
+ 'request path filter "/2"',
+ ],
+ loggrep => qr/done/,
+ },
+ server => {
+ func => \&http_server,
+ },
+ len => 1,
+ md5 => "68b329da9893e34099c7d8ad5cb9c940",
+);
+
+1;
diff --git a/regress/usr.sbin/relayd/args-http-filter-put-contentlength.pl b/regress/usr.sbin/relayd/args-http-filter-put-contentlength.pl
new file mode 100644
index 00000000000..62a234943bb
--- /dev/null
+++ b/regress/usr.sbin/relayd/args-http-filter-put-contentlength.pl
@@ -0,0 +1,28 @@
+# test http put with request filter and request contentlength
+
+use strict;
+use warnings;
+
+our %args = (
+ client => {
+ func => \&http_client,
+ header => {
+ 'Content-Length' => 1,
+ },
+ len => 1,
+ method => 'PUT',
+ },
+ relayd => {
+ protocol => [ "http",
+ 'request path filter "/2"',
+ ],
+ loggrep => qr/done/,
+ },
+ server => {
+ func => \&http_server,
+ },
+ len => 1,
+ md5 => "68b329da9893e34099c7d8ad5cb9c940",
+);
+
+1;
diff --git a/regress/usr.sbin/relayd/args-http-filter-put.pl b/regress/usr.sbin/relayd/args-http-filter-put.pl
new file mode 100644
index 00000000000..b988b793ea9
--- /dev/null
+++ b/regress/usr.sbin/relayd/args-http-filter-put.pl
@@ -0,0 +1,25 @@
+# test http put with request filter
+
+use strict;
+use warnings;
+
+our %args = (
+ client => {
+ func => \&http_client,
+ len => 1,
+ method => 'PUT',
+ },
+ relayd => {
+ protocol => [ "http",
+ 'request path filter "/2"',
+ ],
+ loggrep => qr/done/,
+ },
+ server => {
+ func => \&http_server,
+ },
+ len => 1,
+ md5 => "68b329da9893e34099c7d8ad5cb9c940",
+);
+
+1;
diff --git a/regress/usr.sbin/relayd/args-http-filter.pl b/regress/usr.sbin/relayd/args-http-filter.pl
new file mode 100644
index 00000000000..db71a52a8fa
--- /dev/null
+++ b/regress/usr.sbin/relayd/args-http-filter.pl
@@ -0,0 +1,24 @@
+# test http connection with request filter, triggers lateconnect
+
+use strict;
+use warnings;
+
+our %args = (
+ client => {
+ func => \&http_client,
+ len => 1,
+ },
+ relayd => {
+ protocol => [ "http",
+ 'request path filter "/2"',
+ ],
+ loggrep => qr/done/,
+ },
+ server => {
+ func => \&http_server,
+ },
+ len => 1,
+ md5 => "68b329da9893e34099c7d8ad5cb9c940",
+);
+
+1;
diff --git a/regress/usr.sbin/relayd/funcs.pl b/regress/usr.sbin/relayd/funcs.pl
index cdda4d5042a..14ba5ec3ea2 100644
--- a/regress/usr.sbin/relayd/funcs.pl
+++ b/regress/usr.sbin/relayd/funcs.pl
@@ -1,4 +1,4 @@
-# $OpenBSD: funcs.pl,v 1.7 2013/01/04 14:01:49 bluhm Exp $
+# $OpenBSD: funcs.pl,v 1.8 2013/02/07 22:56:27 bluhm Exp $
# Copyright (c) 2010-2013 Alexander Bluhm <bluhm@openbsd.org>
#
@@ -88,24 +88,33 @@ sub http_client {
my @lengths = @{$self->{lengths} || [ shift // $self->{len} // 251 ]};
my $vers = $self->{lengths} ? "1.1" : "1.0";
my $method = $self->{method} || "GET";
+ my %header = %{$self->{header} || {}};
foreach my $len (@lengths) {
# encode the requested length or chunks into the url
my $path = ref($len) eq 'ARRAY' ? join("/", @$len) : $len;
- my @request = ("$method /$path HTTP/$vers", "Host: foo.bar");
+ my @request = ("$method /$path HTTP/$vers");
+ push @request, "Host: foo.bar" unless defined $header{Host};
push @request, "Content-Length: $len"
- if $vers eq "1.1" && $method eq "PUT";
+ if $vers eq "1.1" && $method eq "PUT" &&
+ !defined $header{'Content-Length'};
+ push @request, "$_: $header{$_}" foreach sort keys %header;
push @request, "";
print STDERR map { ">>> $_\n" } @request;
print map { "$_\r\n" } @request;
write_char($self, $len) if $method eq "PUT";
IO::Handle::flush(\*STDOUT);
+ # XXX client shutdown seems to be broken in relayd
+ #shutdown(\*STDOUT, SHUT_WR)
+ # or die ref($self), " shutdown write failed: $!"
+ # if $vers ne "1.1";
my $chunked = 0;
{
local $/ = "\r\n";
local $_ = <STDIN>;
- defined or die ref($self), " missing http response";
+ defined
+ or die ref($self), " missing http $len response";
chomp;
print STDERR "<<< $_\n";
m{^HTTP/$vers 200 OK$}
@@ -231,26 +240,29 @@ sub http_server {
chomp;
print STDERR "<<< $_\n";
last if /^$/;
- if (/^Content-Length: (.*)/) {
+ if ($method eq "PUT" &&
+ /^Content-Length: (.*)/) {
$1 == $len or die ref($self),
" bad content length $1";
}
}
}
- read_char($self, $vers eq "1.1" ? $len : undef)
+ # XXX reading to EOF does not work with relayd
+ #read_char($self, $vers eq "1.1" ? $len : undef)
+ read_char($self, $len)
if $method eq "PUT";
- my @request = ("HTTP/$vers 200 OK");
+ my @response = ("HTTP/$vers 200 OK");
if (ref($len) eq 'ARRAY') {
- push @request, "Transfer-Encoding: chunked"
+ push @response, "Transfer-Encoding: chunked"
if $vers eq "1.1";
} else {
- push @request, "Content-Length: $len"
+ push @response, "Content-Length: $len"
if $vers eq "1.1" && $method eq "GET";
}
- push @request, "";
- print STDERR map { ">>> $_\n" } @request;
- print map { "$_\r\n" } @request;
+ push @response, "";
+ print STDERR map { ">>> $_\n" } @response;
+ print map { "$_\r\n" } @response;
if (ref($len) eq 'ARRAY') {
write_chunked($self, @$len);
@@ -307,12 +319,16 @@ sub check_len {
my @lengths = map { ref eq 'ARRAY' ? @$_ : $_ }
@{$args{lengths} || []};
foreach my $len (@lengths) {
- my $clen = shift @clen;
- $clen eq "LEN: $len\n"
- or die "client: $clen", "len $len expected";
- my $slen = shift @slen;
- $slen eq "LEN: $len\n"
- or die "server: $slen", "len $len expected";
+ unless ($args{client}{nocheck}) {
+ my $clen = shift @clen;
+ $clen eq "LEN: $len\n"
+ or die "client: $clen", "len $len expected";
+ }
+ unless ($args{server}{nocheck}) {
+ my $slen = shift @slen;
+ $slen eq "LEN: $len\n"
+ or die "server: $slen", "len $len expected";
+ }
}
}
diff --git a/regress/usr.sbin/relayd/relayd.pl b/regress/usr.sbin/relayd/relayd.pl
index 93af16a20ac..ebf0a583beb 100644
--- a/regress/usr.sbin/relayd/relayd.pl
+++ b/regress/usr.sbin/relayd/relayd.pl
@@ -1,5 +1,5 @@
#!/usr/bin/perl
-# $OpenBSD: relayd.pl,v 1.7 2013/01/04 14:01:49 bluhm Exp $
+# $OpenBSD: relayd.pl,v 1.8 2013/02/07 22:56:27 bluhm Exp $
# Copyright (c) 2010-2013 Alexander Bluhm <bluhm@openbsd.org>
#
@@ -45,7 +45,7 @@ my $s = Server->new(
listenaddr => "127.0.0.1",
listenport => $sport,
%{$args{server}},
-);
+) unless $args{server}{noserver};
my $r = Relayd->new(
forward => $ARGV[0],
listendomain => AF_INET,
@@ -65,14 +65,14 @@ my $c = Client->new(
%{$args{client}},
);
-$s->run;
+$s->run unless $args{server}{noserver};
$r->run;
$r->up;
$c->run->up;
-$s->up;
+$s->up unless $args{server}{noserver};
$c->down;
-$s->down;
+$s->down unless $args{server}{noserver};
$r->kill_child;
$r->down;
diff --git a/regress/usr.sbin/relayd/remote.pl b/regress/usr.sbin/relayd/remote.pl
index de1ae60d11c..b3394d988e2 100644
--- a/regress/usr.sbin/relayd/remote.pl
+++ b/regress/usr.sbin/relayd/remote.pl
@@ -1,5 +1,5 @@
#!/usr/bin/perl
-# $OpenBSD: remote.pl,v 1.2 2013/01/04 14:01:49 bluhm Exp $
+# $OpenBSD: remote.pl,v 1.3 2013/02/07 22:56:27 bluhm Exp $
# Copyright (c) 2010-2013 Alexander Bluhm <bluhm@openbsd.org>
#
@@ -102,7 +102,7 @@ my $s = Server->new(
listendomain => AF_INET,
listenaddr => ($mode eq "auto" ? $ARGV[1] : undef),
listenport => ($mode eq "manual" ? $ARGV[0] : undef),
-);
+) unless $args{server}{noserver};
if ($mode eq "auto") {
$r = Remote->new(
forward => $ARGV[0],
@@ -112,7 +112,7 @@ if ($mode eq "auto") {
remotessh => $ARGV[3],
listenaddr => $ARGV[2],
connectaddr => $ARGV[1],
- connectport => $s->{listenport},
+ connectport => $s ? $s->{listenport} : 1,
);
$r->run->up;
}
@@ -124,12 +124,12 @@ my $c = Client->new(
connectport => ($mode eq "manual" ? $ARGV[2] : $r->{listenport}),
);
-$s->run;
+$s->run unless $args{server}{noserver};
$c->run->up;
-$s->up;
+$s->up unless $args{server}{noserver};
$c->down;
-$s->down;
+$s->down unless $args{server}{noserver};
$r->close_child;
$r->down;