From 857811824bfd91a898f1c85abb2045d40a40c0cc Mon Sep 17 00:00:00 2001 From: andre Date: Fri, 2 May 2014 14:10:03 +0000 Subject: [PATCH] Extends relayd regress-tests framework to support tweaks from test-code: tables definition on relayd.conf, customization of client/server cookies, client/server headers and request path. ok reyk --- regress/usr.sbin/relayd/Relayd.pm | 14 +++++++++++++- regress/usr.sbin/relayd/funcs.pl | 25 ++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/regress/usr.sbin/relayd/Relayd.pm b/regress/usr.sbin/relayd/Relayd.pm index 0b40257bbe3..d7994df4a41 100644 --- a/regress/usr.sbin/relayd/Relayd.pm +++ b/regress/usr.sbin/relayd/Relayd.pm @@ -1,4 +1,4 @@ -# $OpenBSD: Relayd.pm,v 1.6 2013/01/21 20:16:57 bluhm Exp $ +# $OpenBSD: Relayd.pm,v 1.7 2014/05/02 14:10:03 andre Exp $ # Copyright (c) 2010-2012 Alexander Bluhm # @@ -52,6 +52,8 @@ sub new { open(my $fh, '>', $self->{conffile}) or die ref($self), " conf file $self->{conffile} create failed: $!"; print $fh "log all\n"; + print $fh "table { $self->{connectaddr} }\n" + if defined($self->{table}); my @protocol = @{$self->{protocol}}; my $proto = shift @protocol; @@ -66,6 +68,10 @@ sub new { print $fh "\n}\n"; my @relay = @{$self->{relay}}; + my $connectport = $self->{connectport}; + my $connectaddr = $self->{connectaddr}; + my $listenaddr = $self->{listenaddr}; + my $listenport = $self->{listenport}; print $fh "relay relay-$test {"; print $fh "\n\tprotocol proto-$test" unless grep { /^protocol / } @relay; @@ -75,6 +81,12 @@ sub new { my $withssl = $self->{forwardssl} ? " with ssl" : ""; print $fh "\n\tforward$withssl to $self->{connectaddr} ". "port $self->{connectport}" unless grep { /^forward / } @relay; + my @raux = @relay; + @relay = (); + foreach my $s (@raux) { + $s =~ s/(\$\w+)/$1/eeg; + push @relay, $s; + } print $fh map { "\n\t$_" } @relay; print $fh "\n}\n"; diff --git a/regress/usr.sbin/relayd/funcs.pl b/regress/usr.sbin/relayd/funcs.pl index 48cef1a5aeb..5e19cb5f415 100644 --- a/regress/usr.sbin/relayd/funcs.pl +++ b/regress/usr.sbin/relayd/funcs.pl @@ -1,4 +1,4 @@ -# $OpenBSD: funcs.pl,v 1.9 2014/04/24 09:05:10 bluhm Exp $ +# $OpenBSD: funcs.pl,v 1.10 2014/05/02 14:10:03 andre Exp $ # Copyright (c) 2010-2013 Alexander Bluhm # @@ -16,7 +16,7 @@ use strict; use warnings; -no warnings 'experimental::smartmatch'; +#no warnings 'experimental::smartmatch'; use feature 'switch'; use Errno; use Digest::MD5; @@ -90,16 +90,23 @@ sub http_client { my $vers = $self->{lengths} ? "1.1" : "1.0"; my $method = $self->{method} || "GET"; my %header = %{$self->{header} || {}}; + my $cookie = $self->{cookie} || ""; foreach my $len (@lengths) { # encode the requested length or chunks into the url my $path = ref($len) eq 'ARRAY' ? join("/", @$len) : $len; + # overwrite path with custom path + if (defined($self->{path})) { + $path = $self->{path}; + } 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" && !defined $header{'Content-Length'}; push @request, "$_: $header{$_}" foreach sort keys %header; + push @request, "Cookie: $cookie" + if $cookie ne ""; push @request, ""; print STDERR map { ">>> $_\n" } @request; print map { "$_\r\n" } @request; @@ -119,7 +126,8 @@ sub http_client { chomp; print STDERR "<<< $_\n"; m{^HTTP/$vers 200 OK$} - or die ref($self), " http response not ok"; + or die ref($self), " http response not ok" + unless $self->{httpnok}; while () { chomp; print STDERR "<<< $_\n"; @@ -221,6 +229,8 @@ sub read_char { sub http_server { my $self = shift; + my %header = %{$self->{header} || {}}; + my $cookie = $self->{cookie} || ""; my($method, $url, $vers); do { @@ -246,6 +256,10 @@ sub http_server { $1 == $len or die ref($self), " bad content length $1"; } + if ($cookie eq "" && + /^Cookie: (.*)/) { + $cookie = $1; + } } } # XXX reading to EOF does not work with relayd @@ -254,6 +268,7 @@ sub http_server { if $method eq "PUT"; my @response = ("HTTP/$vers 200 OK"); + $len = defined($len) ? $len : scalar(split /|/,$url); if (ref($len) eq 'ARRAY') { push @response, "Transfer-Encoding: chunked" if $vers eq "1.1"; @@ -261,7 +276,11 @@ sub http_server { push @response, "Content-Length: $len" if $vers eq "1.1" && $method eq "GET"; } + push @response, "$_: $header{$_} " foreach sort keys %header; + push @response, "Set-Cookie: $cookie" + if $cookie ne ""; push @response, ""; + print STDERR map { ">>> $_\n" } @response; print map { "$_\r\n" } @response; -- 2.20.1