]> git.kaiwu.me - haproxy.git/commitdiff
REGTESTS: http-rules: cover the rfc7239_nn and rfc7239_np converters
authorWilly Tarreau <w@1wt.eu>
Tue, 22 Sep 2026 19:46:38 +0000 (19:46 +0000)
committerWilly Tarreau <w@1wt.eu>
Wed, 30 Sep 2026 15:25:37 +0000 (17:25 +0200)
The test already covers rfc7239_field, rfc7239_is_valid, rfc7239_n2nn
and rfc7239_n2np, and the two converters which build a node name and a
node port were the only ones of the family left out. They are added to
the backend which already extracts the node of a "for" field, with one
IPv4, one IPv6, one string and one integer input, which covers both
branches of each: an address or a number is emitted as it is, an IPv6
is bracketed and a string becomes an obfuscated identifier prefixed
with an underscore.

reg-tests/http-rules/forwarded-header-7239.vtc

index a3e15e9f6ea2aa3ce9c930b5d8b4c13b2611c754..773e106dbe20fa432c5c4e45aa41b14435e49ce3 100644 (file)
@@ -11,6 +11,7 @@ haproxy h1 -conf {
     .if feature(THREAD)
         thread-groups 1
     .endif
+        chroot /
 
         # WT: limit false-positives causing "HTTP header incomplete" due to
         # idle server connections being randomly used and randomly expiring
@@ -52,7 +53,10 @@ haproxy h1 -conf {
 
     backend be4
        http-request set-var(req.fnode) req.hdr(forwarded),rfc7239_field(for)
-       http-request return status 200 hdr nodename "%[var(req.fnode),rfc7239_n2nn]" hdr nodeport "%[var(req.fnode),rfc7239_n2np]"
+       # rfc7239_nn and rfc7239_np perform the reverse operation: they build
+       # a node name and a node port out of an address, an integer or an
+       # obfuscated string, the latter being prefixed with an underscore
+       http-request return status 200 hdr nodename "%[var(req.fnode),rfc7239_n2nn]" hdr nodeport "%[var(req.fnode),rfc7239_n2np]" hdr nn4 "%[ipv4(127.9.0.1),rfc7239_nn]" hdr nn6 "%[ipv6(ab:cd::1),rfc7239_nn]" hdr nns "%[str(id),rfc7239_nn]" hdr npi "%[int(12),rfc7239_np]" hdr nps "%[str(id),rfc7239_np]"
 
 } -start
 
@@ -62,6 +66,7 @@ haproxy h2 -conf {
     .if feature(THREAD)
         thread-groups 1
     .endif
+        chroot /
 
         # WT: limit false-positives causing "HTTP header incomplete" due to
         # idle server connections being randomly used and randomly expiring
@@ -159,6 +164,13 @@ client c1 -connect ${h1_fe1_sock} {
     expect resp.status == 200
     expect resp.http.nodename == "::1"
     expect resp.http.nodeport == "_id"
+    # the node builders: an IPv6 address is bracketed, a string becomes an
+    # obfuscated identifier and an integer is left as it is
+    expect resp.http.nn4 == "127.9.0.1"
+    expect resp.http.nn6 == "[ab:cd::1]"
+    expect resp.http.nns == "_id"
+    expect resp.http.npi == "12"
+    expect resp.http.nps == "_id"
 
     txreq -req GET -url /req4 \
         -hdr "forwarded: for=127.9.0.1"