REG-TESTS: map_redirect: Don't use hdr_dom in ACLs with "-m end" matching method
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 1 Sep 2025 13:37:50 +0000 (15:37 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 1 Oct 2025 14:48:34 +0000 (16:48 +0200)
hdr_dom() is a alias of "hdr() -m dom". So using it with another explicit
matching method does not work because the matching on the domain will never
be performed. Only the last matching method is used. The scripts was working
by chance because no port was set on host header values.

The script was fixed by using "host_only" converter. In addition, host
header values were changed to have a port now.

(cherry picked from commit d09d7676d024f12a92390d7589895a2c4bae8e2b)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit ec64dcd295b0aaae77a8dcc840978266256edad4)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 5ff7dde86be5c759976c79c98710890e59c666c7)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

reg-tests/http-rules/map_redirect.vtc

index f55e0d8..b9c806e 100644 (file)
@@ -6,21 +6,21 @@ feature ignore_unknown_macro
 server s1 {
    rxreq
    expect req.method == "GET"
-   expect req.http.host == "test1.example.com"
+   expect req.http.host == "test1.example.com:1234"
    txresp -body "test1 ok"
 } -start
 
 server s2 {
    rxreq
    expect req.method == "GET"
-   expect req.http.host == "test2.example.com"
+   expect req.http.host == "test2.example.com:1234"
    txresp -body "test2 ok"
 } -start
 
 server s3 {
    rxreq
    expect req.method == "GET"
-   expect req.http.host == "test3.example.com"
+   expect req.http.host == "test3.example.com:1234"
    txresp -body "test3 ok"
 } -start
 
@@ -56,10 +56,10 @@ haproxy h1 -conf {
     use_backend %[req.hdr(Host),lower,map_dom(${testdir}/map_redirect-be.map)] if { hdr_dom(Host) -i test1.example.com || hdr_dom(Host) -i test2.example.com }
 
     # use map to select backend with default value(test3_be)
-    use_backend %[req.hdr(Host),lower,map_dom(${testdir}/map_redirect-be.map,test3_be)] if { hdr_dom(Host) -m end -i example.com }
+    use_backend %[req.hdr(Host),lower,map_dom(${testdir}/map_redirect-be.map,test3_be)] if { hdr(Host),host_only -m end -i example.com }
 
     # use map(after del map test1.example.com) default value(test4_be)
-    use_backend %[req.hdr(Host),lower,map_dom(${testdir}/map_redirect-be.map,test4_be)] if { hdr_dom(Host) -m end -i example.invalid }
+    use_backend %[req.hdr(Host),lower,map_dom(${testdir}/map_redirect-be.map,test4_be)] if { hdr(Host),host_only -m end -i example.invalid }
 
     default_backend be1
 
@@ -135,17 +135,17 @@ client c6 -connect ${h1_fe1_sock} {
 
 # Check map backend selection
 client c7 -connect ${h1_fe1_sock} {
-    txreq -hdr "Host: test1.example.com"
+    txreq -hdr "Host: test1.example.com:1234"
     rxresp
     expect resp.status == 200
     expect resp.body == "test1 ok"
 
-    txreq -hdr "Host: test2.example.com"
+    txreq -hdr "Host: test2.example.com:1234"
     rxresp
     expect resp.status == 200
     expect resp.body == "test2 ok"
 
-    txreq -hdr "Host: test3.example.com"
+    txreq -hdr "Host: test3.example.com:1234"
     rxresp
     expect resp.status == 200
     expect resp.body == "test3 ok"