]> git.kaiwu.me - haproxy.git/commitdiff
REGTESTS: converter: add a test for the "be_sort" converter
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 17 Sep 2026 12:57:00 +0000 (12:57 +0000)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 17 Sep 2026 12:57:00 +0000 (12:57 +0000)
Check the 4 supported element sizes, the unsigned ordering (an element
made of 0xff bytes must be sorted last), a single-element input and an
input whose length is not a multiple of the element size, for which the
conversion must fail.

reg-tests/converter/be_sort.vtc [new file with mode: 0644]

diff --git a/reg-tests/converter/be_sort.vtc b/reg-tests/converter/be_sort.vtc
new file mode 100644 (file)
index 0000000..4de9867
--- /dev/null
@@ -0,0 +1,53 @@
+varnishtest "be_sort converter Test"
+
+feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(3.5-dev7)'"
+feature ignore_unknown_macro
+
+server s1 {
+       rxreq
+       txresp -hdr "Connection: close"
+} -start
+
+haproxy h1 -conf {
+    global
+    .if feature(THREAD)
+        thread-groups 1
+    .endif
+
+    defaults
+       mode http
+       timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
+       timeout client  "${HAPROXY_TEST_TIMEOUT-5s}"
+       timeout server  "${HAPROXY_TEST_TIMEOUT-5s}"
+
+    frontend fe
+       bind "fd@${fe}"
+
+       http-response set-header be_sort-1 "%[bin(0302000104),be_sort(1),hex]"
+       http-response set-header be_sort-2 "%[bin(1302130113031304),be_sort(2),hex]"
+       http-response set-header be_sort-4 "%[bin(00000002000000010000000300000000),be_sort(4),hex]"
+       # unsigned comparison: ffffffffffffffff must be sorted last
+       http-response set-header be_sort-8 "%[bin(0000000000000002ffffffffffffffff0000000000000001),be_sort(8),hex]"
+       # a single element is returned as-is
+       http-response set-header be_sort-single "%[bin(1302),be_sort(2),hex]"
+       # the input length is not a multiple of the element size, the conversion
+       # fails and the header ends up empty
+       http-response set-header be_sort-odd "%[bin(010203),be_sort(2),hex]"
+
+       default_backend be
+
+    backend be
+       server s1 ${s1_addr}:${s1_port}
+} -start
+
+client c1 -connect ${h1_fe_sock} {
+       txreq -url "/"
+       rxresp
+       expect resp.status == 200
+       expect resp.http.be_sort-1 == "0001020304"
+       expect resp.http.be_sort-2 == "1301130213031304"
+       expect resp.http.be_sort-4 == "00000000000000010000000200000003"
+       expect resp.http.be_sort-8 == "00000000000000010000000000000002FFFFFFFFFFFFFFFF"
+       expect resp.http.be_sort-single == "1302"
+       expect resp.http.be_sort-odd == ""
+} -run