Add regression tests to relayd to cover a few key types/actions combinations.
authorandre <andre@openbsd.org>
Fri, 2 May 2014 14:50:26 +0000 (14:50 +0000)
committerandre <andre@openbsd.org>
Fri, 2 May 2014 14:50:26 +0000 (14:50 +0000)
ok reyk

regress/usr.sbin/relayd/args-http-append.pl [new file with mode: 0644]
regress/usr.sbin/relayd/args-http-change.pl [new file with mode: 0644]
regress/usr.sbin/relayd/args-http-expect.pl [new file with mode: 0644]
regress/usr.sbin/relayd/args-http-filter-cookie.pl [new file with mode: 0644]
regress/usr.sbin/relayd/args-http-filter-url.pl [new file with mode: 0644]
regress/usr.sbin/relayd/args-http-hash.pl [new file with mode: 0644]
regress/usr.sbin/relayd/args-http-label.pl [new file with mode: 0644]
regress/usr.sbin/relayd/args-http-mark.pl [new file with mode: 0644]
regress/usr.sbin/relayd/args-http-remove.pl [new file with mode: 0644]
regress/usr.sbin/relayd/args-http-return.pl [new file with mode: 0644]

diff --git a/regress/usr.sbin/relayd/args-http-append.pl b/regress/usr.sbin/relayd/args-http-append.pl
new file mode 100644 (file)
index 0000000..3086336
--- /dev/null
@@ -0,0 +1,22 @@
+use strict;
+use warnings;
+
+our %args = (
+    client => {
+       func => \&http_client,
+       len => 1,
+       loggrep => { "X-Server-Append: 127.0.0.1:.*" => 1 },
+    },
+    relayd => {
+       protocol => [ "http",
+           'request header append "$REMOTE_ADDR:$REMOTE_PORT" to X-Client-Append',
+           'response header append "$SERVER_ADDR:$SERVER_PORT" to X-Server-Append',
+       ],
+    },
+    server => {
+       func => \&http_server,
+       loggrep => { "X-Client-Append: 127.0.0.1:.*" => 1 },
+    },
+);
+
+1;
diff --git a/regress/usr.sbin/relayd/args-http-change.pl b/regress/usr.sbin/relayd/args-http-change.pl
new file mode 100644 (file)
index 0000000..941a2f6
--- /dev/null
@@ -0,0 +1,30 @@
+use strict;
+use warnings;
+
+my %header = ("X-Test-Header" => "XOriginalValue");
+our %args = (
+    client => {
+       func => \&http_client,
+       nocheck => 1,
+       loggrep => {
+               qr/X-Test-Header: XChangedValue/ => 1,
+               qr/Host: foo.bar/ => 1,
+       }
+    },
+    relayd => {
+       protocol => [ "http",
+           'request header change "Host" to "foobar.changed"',
+           'response header change "X-Test-Header" to "XChangedValue"',
+       ],
+    },
+    server => {
+       func => \&http_server,
+       header => \%header,
+       loggrep => {
+               qr/X-Test-Header: XOriginalValue/ => 1,
+               qr/Host: foobar.changed/ => 1,
+       },
+    },
+);
+
+1;
diff --git a/regress/usr.sbin/relayd/args-http-expect.pl b/regress/usr.sbin/relayd/args-http-expect.pl
new file mode 100644 (file)
index 0000000..c9fb482
--- /dev/null
@@ -0,0 +1,22 @@
+use strict;
+use warnings;
+
+my @lengths = (21);
+our %args = (
+    client => {
+       func => \&http_client,
+       lengths => \@lengths,
+       path => "query?foo=bar&ok=yes"
+    },
+    relayd => {
+       protocol => [ "http",
+           'request query expect "bar" from "foo" log',
+       ],
+    },
+    server => {
+       func => \&http_server,
+    },
+    lengths => \@lengths,
+);
+
+1;
diff --git a/regress/usr.sbin/relayd/args-http-filter-cookie.pl b/regress/usr.sbin/relayd/args-http-filter-cookie.pl
new file mode 100644 (file)
index 0000000..e53f4ca
--- /dev/null
@@ -0,0 +1,26 @@
+# test http block
+
+use strict;
+use warnings;
+
+our %args = (
+    client => {
+       func => sub { eval { http_client(@_) }; warn $@ },
+       loggrep => qr/Client missing http 251 response/,
+       cookie => "med=thx; domain=.foo.bar; path=/; expires=Mon, 27-Oct-2014 04:11:56 GMT;",
+       path => "anypath",
+       nocheck => 1,
+    },
+    relayd => {
+       protocol => [ "http",
+           'request cookie filter "thx" from "med" log',
+       ],
+       loggrep => qr/rejecting request, \[med: thx\]/,
+    },
+    server => {
+       noserver => 1,
+       nocheck => 1,
+    },
+);
+
+1;
diff --git a/regress/usr.sbin/relayd/args-http-filter-url.pl b/regress/usr.sbin/relayd/args-http-filter-url.pl
new file mode 100644 (file)
index 0000000..534be4c
--- /dev/null
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+
+our %args = (
+    client => {
+       func => \&http_client,
+       path => "a/b/c/d/e/f/gindex.html",
+       loggrep => [
+           qr/403 Forbidden/,
+           qr/Server: OpenBSD relayd/,
+           qr/Connection: close/,
+       ],
+       httpnok => 1,
+    },
+    relayd => {
+       protocol => [ "http",
+           'return error',
+           'request url filter "foo.bar/a/b/" log',
+       ],
+       loggrep => {
+           qr/rejecting request \(403 Forbidden\)/ => 1,
+           qr/\[foo.bar\/a\/b\/:/ => 1,
+       },
+    },
+    server => {
+       noserver => 1,
+       nocheck => 1,
+    },
+);
+
+1;
diff --git a/regress/usr.sbin/relayd/args-http-hash.pl b/regress/usr.sbin/relayd/args-http-hash.pl
new file mode 100644 (file)
index 0000000..e14890d
--- /dev/null
@@ -0,0 +1,28 @@
+use strict;
+use warnings;
+
+our %args = (
+    client => {
+       func => \&http_client,
+       path => "query?foobar",
+       len => 21,
+       nocheck => 1,
+    },
+    relayd => {
+       table => 1,
+       protocol => [ "http",
+           'path hash "/query" log',
+       ],
+       relay => 'forward to <table-$test> port $connectport',
+       loggrep => {
+               qr/done, \[\/query: foobar\]/ => 1,
+               qr/relay_handle_http: hash 0xfde460be/ => 1,
+       },
+    },
+    server => {
+       func => \&http_server,
+       nocheck => 1,
+    },
+);
+
+1;
diff --git a/regress/usr.sbin/relayd/args-http-label.pl b/regress/usr.sbin/relayd/args-http-label.pl
new file mode 100644 (file)
index 0000000..5185d73
--- /dev/null
@@ -0,0 +1,26 @@
+use strict;
+use warnings;
+
+our %args = (
+    client => {
+       func => \&http_client,
+       loggrep => qr/403 Forbidden/,
+       path => "query?foo=bar&ok=yes",
+       httpnok => 1,
+    },
+    relayd => {
+       protocol => [ "http",
+           'return error',
+           'label "expect_foobar_label"',
+           'request query filter "bar" from "foo" log',
+           'no label',
+       ],
+       loggrep => qr/.*403 Forbidden.*expect_foobar_label.*foo: bar/,
+    },
+    server => {
+       noserver => 1,
+       nocheck => 1,
+    },
+);
+
+1;
diff --git a/regress/usr.sbin/relayd/args-http-mark.pl b/regress/usr.sbin/relayd/args-http-mark.pl
new file mode 100644 (file)
index 0000000..a96d892
--- /dev/null
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+
+our %args = (
+    client => {
+       func => \&http_client,
+       path => "foobar?path",
+    },
+    relayd => {
+       protocol => [ "http",
+           'request path mark "*" from "/foobar" with 55',
+           'request path change "path" to "foobarchangedpath" marked 55',
+       ],
+       loggrep => { ", 55,.*done" => 1 },
+    },
+    server => {
+       func => \&http_server,
+    },
+);
+
+1;
diff --git a/regress/usr.sbin/relayd/args-http-remove.pl b/regress/usr.sbin/relayd/args-http-remove.pl
new file mode 100644 (file)
index 0000000..e8a6cac
--- /dev/null
@@ -0,0 +1,32 @@
+use strict;
+use warnings;
+
+my %header = (
+       "X-Header-Foo" => "foo",
+       "X-Header-Bar" => "bar",
+);
+our %args = (
+    client => {
+       func => \&http_client,
+       loggrep => {
+           "X-Header-Foo: foo" => 0,
+           "X-Header-Bar: bar" => 1,
+       },
+    },
+    relayd => {
+       protocol => [ "http",
+           'response header remove X-Header-Foo log',
+       ],
+       loggrep => { qr/done, \[X-Header-Foo: foo\s*\]/ => 1 },
+    },
+    server => {
+       func => \&http_server,
+       header => \%header,
+       loggrep => {
+           "X-Header-Foo: foo" => 1,
+           "X-Header-Bar: bar" => 1,
+       },
+    },
+);
+
+1;
diff --git a/regress/usr.sbin/relayd/args-http-return.pl b/regress/usr.sbin/relayd/args-http-return.pl
new file mode 100644 (file)
index 0000000..3d06bd7
--- /dev/null
@@ -0,0 +1,29 @@
+use strict;
+use warnings;
+
+our %args = (
+    client => {
+       func => \&http_client,
+       # XXX add more paths to match a case where it pass
+       path => "query?foo=bar&ok=yes",
+       nocheck => 1,
+       httpnok => 1,
+    },
+    relayd => {
+       protocol => [ "http",
+           'return error',
+           'label "expect_foobar_return_test"',
+           'request query expect "baz" from "foo" log',
+           'no label',
+       ],
+       loggrep => {
+           ' \(403 Forbidden\), \[expect_foobar_return_test, foo: bar\]' => 1
+       },
+    },
+    server => {
+       noserver => 1,
+       nocheck => 1,
+    },
+);
+
+1;