diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/atlocal.in | 9 | ||||
-rw-r--r-- | tests/initdb.at | 4 | ||||
-rw-r--r-- | tests/rewrite07.at | 40 | ||||
-rw-r--r-- | tests/testsuite.at | 1 |
5 files changed, 52 insertions, 3 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 792ce24..28b795f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -46,12 +46,13 @@ TESTSUITE_AT = \ rewrite01.at\ rewrite02.at\ rewrite03.at\ rewrite04.at\ rewrite05.at\ rewrite06.at\ + rewrite07.at\ testsuite.at TESTSUITE = $(srcdir)/testsuite M4=m4 AUTOTEST = $(AUTOM4TE) --language=autotest diff --git a/tests/atlocal.in b/tests/atlocal.in index 18a0b69..14f3fd4 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -48,16 +48,23 @@ varnish v1 -vcl+backend { sub vcl_recv { dbrw.config("$DBRW_TEST_DBTYPE", "$DBRW_TEST_PARAMS", {"$1"}); set req.http.X-Redirect-To = dbrw.rewrite("host=" + req.http.Host + ";" + "url=" + req.url); - return(synth(301, "Redirect")); + if (req.http.X-Redirect-To != "") { + return(synth(301, "Redirect")); + } else if (req.http.X-VMOD-DBRW-Error == "1") { + return(synth(500, "DBRW Error")); + } } sub vcl_synth { + if (req.http.X-VMOD-DBRW-Error == "1") { + set resp.http.X-VMOD-DBRW-Error = "1"; + } if (resp.status == 301) { if (req.http.X-VMOD-DBRW-Status) { set resp.status = std.integer(req.http.X-VMOD-DBRW-Status, 301); } set resp.http.Location = req.http.X-Redirect-To; return (deliver); diff --git a/tests/initdb.at b/tests/initdb.at index 0355e3b..f7bfe0b 100644 --- a/tests/initdb.at +++ b/tests/initdb.at @@ -41,20 +41,20 @@ CREATE TABLE rewrite ( flags varchar(64) DEFAULT NULL ); CREATE INDEX source ON rewrite(host,url); INSERT INTO rewrite VALUES -('en.example.net','/local','http://uno.example.com/remote',NULL,NULL,NULL), +('en.example.net','/local','http://uno.example.com/remote',NULL,NULL,'eq'), ('en.example.net','/local','http://dos.example.com/$[]1','$url','/local/(.*)',NULL), ('en.example.net','/local2','http://to.example.net/$[]1$[]2','$url','/local2/([[^\\?]]*)(\\?.*)?',NULL), ('to.example.net','/local','http://dos.example.net/$[]1','$url','/local/(.*)','QSA'), ('tre.example.net','/local','http://dos.example.net/$[]1?i=10','$url','/local/(.*)','QSA,R=302'); EOT ], [0], [], [], [mv err $FAILFILE], [echo "OK" > $INITFILE]) -])
\ No newline at end of file +]) diff --git a/tests/rewrite07.at b/tests/rewrite07.at new file mode 100644 index 0000000..6554fc7 --- /dev/null +++ b/tests/rewrite07.at @@ -0,0 +1,40 @@ +# This file is part of vmod-dbrw -*- autotest -*- +# Copyright (C) 2013-2018 Sergey Poznyakoff +# +# Vmod-dbrw is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# Vmod-dbrw is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with vmod-dbrw. If not, see <http://www.gnu.org/licenses/>. + +AT_SETUP(Rewrite 7 - SQL error handling) +AT_KEYWORDS(rewrite rewrite07) + +AT_DBRW_INIT + +AT_CHECK([ +AT_DBINIT_PREREQ +# This test simulates rewrite failure in order to check whether +# the X-VMOD-DBRW-Error header is correctly set on return. +AT_VCL([SELECT dest,pattern,value,flags + FROM rewrite + WHERE host='$BADHOST' AND url IN ($(urlprefixes $url)) + ORDER BY LENGTH(dest),value DESC], + [txreq -url /local/foo/bar?x&y&z -hdr "Host:tre.example.net" + rxresp + expect resp.status == 500 + expect resp.http.X-VMOD-DBRW-Error == 1 +]) +AT_VARNISHTEST +], +[0], +[OK +]) +AT_CLEANUP diff --git a/tests/testsuite.at b/tests/testsuite.at index 5858b6a..203b667 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -57,9 +57,10 @@ m4_include([exact01.at]) m4_include([rewrite01.at]) m4_include([rewrite02.at]) m4_include([rewrite03.at]) m4_include([rewrite04.at]) m4_include([rewrite05.at]) m4_include([rewrite06.at]) +m4_include([rewrite07.at]) # End of testsuite.at |