REGTESTS: Add reg tests for the HTTP return action

2 reg tests have been added to ensure the HTTP return action is functionnal. A
reg test is about returning error files. The other one is about returning
default responses and responses based on string or file payloads.
This commit is contained in:
Christopher Faulet 2020-02-05 16:46:38 +01:00
parent 700d9e88ad
commit c5a0aeef85
4 changed files with 156 additions and 0 deletions

View File

@ -0,0 +1,46 @@
varnishtest "Test the HTTP return action with errorfiles"
#REQUIRE_VERSION=2.2
# This config tests the HTTP return action when error files are used to reply to
# the client.
feature ignore_unknown_macro
haproxy h1 -conf {
http-errors errors-2
errorfile 400 ${testdir}/errors/400-2.http
defaults
mode http
timeout connect 1s
timeout client 1s
timeout server 1s
frontend fe1
bind "fd@${fe1}"
errorfile 400 ${testdir}/errors/400.http
http-request return status 400 default-errorfiles if { path /def }
http-request return status 400 errorfile ${testdir}/errors/400-1.http if { path /400-1 }
http-request return status 400 errorfiles errors-2 if { path /400-2 }
} -start
client c1 -connect ${h1_fe1_sock} {
txreq -req GET -url /def
rxresp
expect resp.status == 400
expect resp.http.x-err-type == "default"
} -run
client c1r2 -connect ${h1_fe1_sock} {
txreq -req GET -url /400-1
rxresp
expect resp.status == 400
expect resp.http.x-err-type == "errors-1"
} -run
client c1r3 -connect ${h1_fe1_sock} {
txreq -req GET -url /400-2
rxresp
expect resp.status == 400
expect resp.http.x-err-type == "errors-2"
} -run

View File

@ -0,0 +1,16 @@
s313l7hzIJ5FIXCmpr+zAyFK80lNfjOIRNZSXJJn/GQVNQsBqDl3AFcb7JQt1ler
KgBNE1LAiU02vTj4+hlW2qi4Xg1T3lshEOSSxJQN/ITQG/1KVmDiTtsjjSv8iWUj
T403xvLKQd0FB2h00N9pwd9ApbGPYF8uG1kjnNQmzJOqQ2Pz7jUkNpF+sAAQHaRD
ocjEucTsb676w8l9EqWNE+DK5IqoO2AK47bHbr4u38ZOwXjQWGw9MiUJZmVQEqdC
QZlmpFuSKQiig1SZFZlmKVidf1genz6q+4BT80IFU2UE+pWiay/HcZttwM++eG7w
n/Va7yd3D+ryK2j4rw0sOYM7Cu7AwleZeGEaCZINZmnVAWtg2OVFOTxx6jz8wNuY
VJPb3VFD72WnnBhtbik5mEqjzVJy530sQBlGlcxi3Tivq69ZnAk55RBN0LO+jWf4
DI4189LTIfY5WroA8AQeCCQYnzyXo5O/vDmic+uwKALlQ6TXzSuCNpHO8fL1UwHH
7KBqxHi+/yYJ0431V/LAvRBpVFPYJ8iED7Md67GRVQWy8o+tgC1PmycJtS5ADQGO
Jys46KjhL9cnaS3aP1YcuuGuSUOVMA7BjqPcz7r+hqYTCZ3akaY4w7AGRCZyRf8e
finlAkgFpzKSFwaa2M6H3vUE14WzHC0hJ/bO2epjlcOeoMcgBVn5uUMYMVroAK0+
vI9jg1RDV17oHberVmWj8VAXolDNS0pW2rt+JbqHsAVDDk/Ex3NJWFSYByHFyglQ
cjYMwrzIsWC09ykW6WhUN6IsopLlDk7O2jcKaHxZ6WaFiVxIGFkepfNhf4wYZ6O9
tjwMuOqTQtSjdP3MbbVEM6VpAkJW/Si1jmSW02ObMcdEpxJHTB9fC30waMM7e+T4
FT/AlwB49un/3yYU2iUndW+wenoED9UkdbZ7uvjyu+UgQ3bMaQhX9Z9eHxhfi6Gy
aRM2IJVeEpk5w0ifAQxrL4Wp+dFbzfGN1yPkI2UAo6WbWi63D

View File

@ -0,0 +1,93 @@
varnishtest "Test the HTTP return action"
#REQUIRE_VERSION=2.2
# This config tests the HTTP return action.
feature ignore_unknown_macro
haproxy h1 -conf {
defaults
mode http
timeout connect 1s
timeout client 1s
timeout server 1s
frontend fe1
bind "fd@${fe1}"
http-request return if { path /def-1 }
http-request return hdr "x-custom-hdr" "%[url]" if { path /def-2 }
http-request return status 403 if { path /def-3 }
http-request return content-type "text/plain" if { path /def-4 }
http-request return content-type "text/plain" string "hello" hdr "x-custom-hdr" "%[url]" if { path /string }
http-request return content-type "text/plain" lf-string "path is %[url]" hdr "x-custom-hdr" "%[url]" if { path /lf-string }
http-request return content-type "text/plain" file /dev/null hdr "x-custom-hdr" "%[url]" if { path /empty-file }
http-request return content-type "text/plain" file ${testdir}/1k.txt hdr "x-custom-hdr" "%[url]" if { path /file }
http-request return content-type "text/plain" lf-file ${testdir}/lf-file.txt hdr "x-custom-hdr" "%[url]" if { path /lf-file }
} -start
client c1 -connect ${h1_fe1_sock} {
txreq -req GET -url /def-1
rxresp
expect resp.status == 200
expect resp.http.content-length == 0
expect resp.http.content-type == <undef>
expect resp.http.x-custom-hdr == <undef>
txreq -req GET -url /def-2
rxresp
expect resp.status == 200
expect resp.http.content-length == 0
expect resp.http.content-type == <undef>
expect resp.http.x-custom-hdr == "/def-2"
txreq -req GET -url /def-3
rxresp
expect resp.status == 403
expect resp.http.content-length == 0
expect resp.http.content-type == <undef>
txreq -req GET -url /def-4
rxresp
expect resp.status == 200
expect resp.http.content-length == 0
expect resp.http.content-type == <undef>
txreq -req GET -url /string
rxresp
expect resp.status == 200
expect resp.http.content-length == 5
expect resp.http.content-type == "text/plain"
expect resp.http.x-custom-hdr == "/string"
expect resp.body == "hello"
txreq -req GET -url /lf-string
rxresp
expect resp.status == 200
expect resp.http.content-length == 18
expect resp.http.content-type == "text/plain"
expect resp.http.x-custom-hdr == "/lf-string"
expect resp.body == "path is /lf-string"
txreq -req GET -url /empty-file
rxresp
expect resp.status == 200
expect resp.http.content-length == 0
expect resp.http.content-type == <undef>
expect resp.http.x-custom-hdr == "/empty-file"
txreq -req GET -url /file
rxresp
expect resp.status == 200
expect resp.http.content-length == 1024
expect resp.http.content-type == "text/plain"
expect resp.http.x-custom-hdr == "/file"
txreq -req GET -url /lf-file
rxresp
expect resp.status == 200
expect resp.http.content-length == 17
expect resp.http.content-type == "text/plain"
expect resp.http.x-custom-hdr == "/lf-file"
expect resp.body == "path is /lf-file\n"
} -run

View File

@ -0,0 +1 @@
path is %[url]