Skip to content

Commit

Permalink
Add tests for relayd http put and https.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluhm committed Sep 2, 2011
1 parent 3945965 commit c4f6115
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 14 deletions.
7 changes: 3 additions & 4 deletions regress/usr.sbin/relayd/Makefile
@@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.1 2011/09/01 17:33:17 bluhm Exp $
# $OpenBSD: Makefile,v 1.2 2011/09/02 17:02:10 bluhm Exp $

# The following ports must be installed for the regression tests:
# p5-IO-Socket-INET6 object interface for AF_INET and AF_INET6 domain sockets
Expand Down Expand Up @@ -36,8 +36,7 @@ run-regress-$a: $a
server-cert.pem:
openssl req -batch -new -nodes -newkey rsa -keyout server-key.pem -subj /CN=localhost/ -x509 -out $@

${REGRESS_TARGETS:M*ssl-client*}: /etc/ssl/127.0.0.1.crt

${REGRESS_TARGETS:M*ssl-server*}: server-cert.pem
${REGRESS_TARGETS:M*ssl*} ${REGRESS_TARGETS:M*https*}: \
/etc/ssl/127.0.0.1.crt server-cert.pem

.include <bsd.regress.mk>
2 changes: 1 addition & 1 deletion regress/usr.sbin/relayd/args-http-persistent.pl
Expand Up @@ -3,7 +3,7 @@
use strict;
use warnings;

my @lengths = (251, 65536, 0, 1, 2, 3, 4, 5);
my @lengths = (251, 16384, 0, 1, 2, 3, 4, 5);
our %args = (
client => {
func => \&http_client,
Expand Down
26 changes: 26 additions & 0 deletions regress/usr.sbin/relayd/args-http-put.pl
@@ -0,0 +1,26 @@
# test persistent http 1.1 put over http relay

use strict;
use warnings;

my @lengths = (251, 16384, 0, 1, 2, 3, 4, 5);
our %args = (
client => {
func => \&http_client,
lengths => \@lengths,
method => "PUT",
},
relay => {
protocol => [ "http",
"request header log foo",
"response header log bar",
],
},
server => {
func => \&http_server,
},
lengths => \@lengths,
md5 => "bc3a3f39af35fe5b1687903da2b00c7f",
);

1;
29 changes: 29 additions & 0 deletions regress/usr.sbin/relayd/args-https-persistent.pl
@@ -0,0 +1,29 @@
# test persistent http 1.1 connection over http relay

use strict;
use warnings;

my @lengths = (251, 16384, 0, 1, 2, 3, 4, 5);
our %args = (
client => {
func => \&http_client,
lengths => \@lengths,
ssl => 1,
},
relay => {
protocol => [ "http",
"request header log foo",
"response header log bar",
],
forwardssl => 1,
listenssl => 1,
},
server => {
func => \&http_server,
ssl => 1,
},
lengths => \@lengths,
md5 => "bc3a3f39af35fe5b1687903da2b00c7f",
);

1;
30 changes: 30 additions & 0 deletions regress/usr.sbin/relayd/args-https-put.pl
@@ -0,0 +1,30 @@
# test persistent https 1.1 put over http relay

use strict;
use warnings;

my @lengths = (251, 16384, 0, 1, 2, 3, 4, 5);
our %args = (
client => {
func => \&http_client,
lengths => \@lengths,
method => "PUT",
ssl => 1,
},
relay => {
protocol => [ "http",
"request header log foo",
"response header log bar",
],
forwardssl => 1,
listenssl => 1,
},
server => {
func => \&http_server,
ssl => 1,
},
lengths => \@lengths,
md5 => "bc3a3f39af35fe5b1687903da2b00c7f",
);

1;
28 changes: 28 additions & 0 deletions regress/usr.sbin/relayd/args-https.pl
@@ -0,0 +1,28 @@
# test https connection over http relay

use strict;
use warnings;

our %args = (
client => {
func => \&http_client,
ssl => 1,
},
relay => {
protocol => [ "http",
"request header log foo",
"response header log bar",
],
forwardssl => 1,
listenssl => 1,

},
server => {
func => \&http_server,
ssl => 1,
},
len => 251,
md5 => "bc3a3f39af35fe5b1687903da2b00c7f",
);

1;
32 changes: 23 additions & 9 deletions regress/usr.sbin/relayd/funcs.pl
@@ -1,4 +1,4 @@
# $OpenBSD: funcs.pl,v 1.2 2011/09/02 10:45:36 bluhm Exp $
# $OpenBSD: funcs.pl,v 1.3 2011/09/02 17:02:10 bluhm Exp $

# Copyright (c) 2010,2011 Alexander Bluhm <bluhm@openbsd.org>
#
Expand Down Expand Up @@ -87,14 +87,18 @@ sub http_client {
my $self = shift;
my @lengths = @{$self->{lengths} || [ shift // $self->{len} // 251 ]};
my $vers = $self->{lengths} ? "1.1" : "1.0";
my $method = $self->{method} || "GET";

foreach my $len (@lengths) {
{
local $\ = "\r\n";
print "GET /$len HTTP/$vers";
print "$method /$len HTTP/$vers";
print "Host: foo.bar";
print "Content-Length: $len"
if $vers eq "1.1" && $method eq "PUT";
print "";
}
write_char($self, $len) if $method eq "PUT";
IO::Handle::flush(\*STDOUT);

{
Expand All @@ -115,7 +119,8 @@ sub http_client {
}
}
}
read_char($self, $vers eq "1.1" ? $len : undef);
read_char($self, $vers eq "1.1" ? $len : undef)
if $method eq "GET";
}
}

Expand Down Expand Up @@ -151,33 +156,42 @@ sub read_char {
sub http_server {
my $self = shift;

my($url, $vers);
my($method, $url, $vers);
do {
my $len;
{
local $\ = "\n";
local $/ = "\r\n";
local $_ = <STDIN>;
return unless defined $_;
chomp;
print STDERR;
($url, $vers) = m{^GET (.*) HTTP/(1\.[01])$}
($method, $url, $vers) = m{^(\w+) (.*) HTTP/(1\.[01])$}
or die ref($self), " http request not ok";
$method =~ /^(GET|PUT)$/
or die ref($self), " unknown method: $method";
($len) = $url =~ /(\d+)$/;
while (<STDIN>) {
chomp;
last if /^$/;
print STDERR;
if (/^Content-Length: (.*)/) {
$1 == $len or die ref($self),
" bad content length $1";
}
}
}
read_char($self, $vers eq "1.1" ? $len : undef)
if $method eq "PUT";

$url =~ /(\d+)$/;
my $len = $1;
{
local $\ = "\r\n";
print "HTTP/$vers 200 OK";
print "Content-Length: $len" if $vers eq "1.1";
print "Content-Length: $len"
if $vers eq "1.1" && $method eq "GET";
print "";
}
write_char($self, $len);
write_char($self, $len) if $method eq "GET";
IO::Handle::flush(\*STDOUT);
} while ($vers eq "1.1");
}
Expand Down

0 comments on commit c4f6115

Please sign in to comment.