]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REGTEST: added tests covering smp_fetch_hdr_ip()
authorOto Valek <oto@valek.net>
Fri, 24 Feb 2023 20:41:58 +0000 (21:41 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 1 Mar 2023 13:10:02 +0000 (14:10 +0100)
Added new testcases for all 4 branches of smp_fetch_hdr_ip():
- a plain IPv4 address
- an IPv4 address with an port number
- a plain IPv6 address
- an IPv6 address wrapped in [] brackets

reg-tests/http-rules/converters_ipmask_concat_strcmp_field_word.vtc

index 00d74ce287ac2dcd4ad7ae74e8bfb2de6cf0a27c..55bcb5f9c7d7ade1826dc8f276dfd3d55576c3ce 100644 (file)
@@ -1,7 +1,7 @@
 varnishtest "Minimal tests for 1.9 converters: ipmask,concat,strcmp,field,word"
 feature ignore_unknown_macro
 
-# ipmask tests server
+# ipmask,hdr_ip tests server
 server s1 {
    rxreq
    expect req.method == "GET"
@@ -28,6 +28,12 @@ server s1 {
    expect req.http.test5mask24 == "192.168.1.0"
    expect req.http.test6mask24 == "192.168.1.0"
    expect req.http.test6mask25 == "192.168.1.128"
+
+   expect req.http.ipv4plain    == "192.168.2.1"
+   expect req.http.ipv4port     == "192.168.2.1"
+   expect req.http.ipv6plain    == "2001:db8:c001:c01a:ffff:ffff:20:ffff"
+   expect req.http.ipv6brackets == "2001:db8:c001:c01a:ffff:ffff:20:ffff"
+
    txresp
 } -start
 
@@ -65,7 +71,7 @@ server s2 {
 } -start
 
 
-# ipmask tests with accept-proxy bind
+# ipmask,hdr_ip tests with accept-proxy bind
 haproxy h1 -conf {
   defaults
     mode http
@@ -113,6 +119,12 @@ haproxy h1 -conf {
     http-request track-sc1 hdr_ip(Addr4),ipmask(32) table be1
     http-request track-sc2 hdr_ip(Addr3),ipmask(24,64) table be1
 
+    # hdr_ip tests
+    http-request set-header IPv4plain    %[req.hdr_ip(AddrIPv4plain)]
+    http-request set-header IPv4port     %[req.hdr_ip(AddrIPv4port)]
+    http-request set-header IPv6plain    %[req.hdr_ip(AddrIPv6plain)]
+    http-request set-header IPv6brackets %[req.hdr_ip(AddrIPv6brackets)]
+
     default_backend be1
 
   backend be1
@@ -184,14 +196,18 @@ haproxy h2 -conf {
     server s2 ${s2_addr}:${s2_port}
 } -start
 
-# ipmask tests
+# ipmask,hdr_ip tests
 client c1 -connect ${h1_fe1_sock} -proxy2 "192.168.1.101:1234 127.0.0.1:2345" {
     txreq -hdr "Addr1: 2001:db8::1" \
         -hdr "Addr2: 2001:db8::bad:c0f:ffff" \
         -hdr "Addr3: 2001:db8:c001:c01a:ffff:ffff:10:ffff" \
         -hdr "Addr4: ::FFFF:192.168.1.101" \
         -hdr "Addr5: 192.168.1.2" \
-        -hdr "Addr6: 192.168.1.255"
+        -hdr "Addr6: 192.168.1.255" \
+        -hdr "AddrIPv4plain: 192.168.2.1" \
+        -hdr "AddrIPv4port: 192.168.2.1:6789" \
+        -hdr "AddrIPv6plain: 2001:db8:c001:c01a:ffff:ffff:20:ffff" \
+        -hdr "AddrIPv6brackets: [2001:db8:c001:c01a:ffff:ffff:20:ffff]"
     rxresp
     expect resp.status == 200
 } -run