From: Christopher Faulet Date: Wed, 18 Nov 2026 07:55:51 +0000 (+0100) Subject: REGTEST: spoe: add large-frame tests for the applet and the mux X-Git-Url: https://git.kaiwu.me/http/%7B@url%7D?a=commitdiff_plain;h=d4e3269b00d3feddf240d269594184fecb532423;p=haproxy.git REGTEST: spoe: add large-frame tests for the applet and the mux Two tests exercising a near-max-size SPOP frame (a 14000-byte binary argument) through the SPOE applet and the SPOP mux: - largeframe.vtc, on-frontend-tcp-request event carrying req.payload(0,14000) sampled from a buffered 30KB request; - groupframe.vtc, http-request send-spoe-group carrying req.body, the rule yielding until the request is complete so args are encoded from the fully buffered body. Both rely on a protocol-correct python agent (spoa_largeframe.py), mirroring encode_varint()/decode_varint() from include/haproxy/intops.h. largeframe.vtc also uses a small raw TCP client (lf_client.py) for the 30KB request. --- diff --git a/reg-tests/spoe/groupframe.vtc b/reg-tests/spoe/groupframe.vtc new file mode 100644 index 000000000..ad5fcaf6a --- /dev/null +++ b/reg-tests/spoe/groupframe.vtc @@ -0,0 +1,73 @@ +varnishtest "SPOE: large SPOP frame via send-spoe-group through applet and mux" + +#REGTEST_TYPE=slow +feature ignore_unknown_macro +feature cmd "python3 --version" + +server s1 { + rxreq + txresp +} -start + +server s_agent {} -start +server s_agent -break + +process pagent "python3 ${testdir}/spoa_largeframe.py ${s_agent_port}" -start +process pagent -expect-text 0 0 "READY" + +shell { + cat > "${tmpdir}/spoe-lf.conf" << EOF +[test-engine] +spoe-agent test-agent + use-backend spoe-backend + option var-prefix spoe + option force-set-var + timeout hello 2s + timeout idle 2s + timeout processing 2s + groups large-group + +spoe-message check-large + args reqlen=req.len chunk=req.body + +spoe-group large-group + messages check-large +EOF +} + +haproxy h1 -conf { + global + tune.bufsize 16384 + + defaults + mode http + timeout connect 5s + timeout client 5s + timeout server 5s + + frontend fe + bind "fd@${fe}" + filter spoe engine test-engine config "${tmpdir}/spoe-lf.conf" + http-request send-spoe-group test-engine large-group + default_backend be + + backend be + server s1 ${s1_addr}:${s1_port} + + backend spoe-backend + mode spop + timeout connect 2s + timeout server 5s + server agent 127.0.0.1:${s_agent_port} +} -start + +# 14KB request body: send-spoe-group encodes args with the body fully +# buffered (the rule yields until the request is complete). The 14000-byte +# binary arg carried by req.body builds a near-max-size NOTIFY frame that goes +# through the SPOE applet and the SPOP mux. +client c1 -connect ${h1_fe_sock} { + txreq -req POST -bodylen 14000 + rxresp + expect resp.status == 200 +} -run +process pagent -expect-text 0 0 "NOTIFY_OK" diff --git a/reg-tests/spoe/largeframe.vtc b/reg-tests/spoe/largeframe.vtc new file mode 100644 index 000000000..0064b6a35 --- /dev/null +++ b/reg-tests/spoe/largeframe.vtc @@ -0,0 +1,70 @@ +varnishtest "SPOE: large SPOP frame through applet and mux" + +#REGTEST_TYPE=slow +feature ignore_unknown_macro +feature cmd "python3 --version" + +server s1 { + rxreq + txresp +} -start + +server s_agent {} -start +server s_agent -break + +process pagent "python3 ${testdir}/spoa_largeframe.py ${s_agent_port}" -start +process pagent -expect-text 0 0 "READY" + +shell { + cat > "${tmpdir}/spoe-lf.conf" << EOF +[test-engine] +spoe-agent test-agent + messages check-large + use-backend spoe-backend + option var-prefix spoe + option force-set-var + timeout hello 2s + timeout idle 2s + timeout processing 2s + +spoe-message check-large + args reqlen=req.len chunk=req.payload(0,14000) + event on-frontend-tcp-request +EOF +} + +haproxy h1 -conf { + global + tune.bufsize 16384 + + defaults + mode tcp + timeout connect 5s + timeout client 5s + timeout server 5s + + frontend fe + bind "fd@${fe}" + tcp-request inspect-delay 2s + acl req_rdy req.len ge 14000 + tcp-request content accept if req_rdy + filter spoe engine test-engine config "${tmpdir}/spoe-lf.conf" + default_backend be + + backend be + server s1 ${s1_addr}:${s1_port} + + backend spoe-backend + mode spop + timeout connect 2s + timeout server 5s + server agent 127.0.0.1:${s_agent_port} +} -start + +# 30KB request: the frontend buffers >= 14000 bytes before firing the event; +# the SPOE frame then carries a 14000-byte binary arg (~14KB frame) through +# the SPOE applet and the SPOP mux. +process pclient "python3 ${testdir}/lf_client.py ${h1_fe_addr} ${h1_fe_port}" -start +process pclient -wait + +process pagent -expect-text 0 0 "NOTIFY_OK" diff --git a/reg-tests/spoe/lf_client.py b/reg-tests/spoe/lf_client.py new file mode 100755 index 000000000..af05a0aee --- /dev/null +++ b/reg-tests/spoe/lf_client.py @@ -0,0 +1,21 @@ +import socket, sys, time + +host = sys.argv[1] +port = int(sys.argv[2]) +body = b"x" * 30000 +req = b"POST / HTTP/1.1\r\nHost: t\r\nContent-Length: %d\r\n\r\n" % len(body) + body + +c = socket.create_connection((host, port), timeout=8) +c.sendall(req) +time.sleep(1) +c.settimeout(5) +resp = b"" +try: + while True: + d = c.recv(65536) + if not d: + break + resp += d +except Exception: + pass +sys.exit(0 if resp.startswith(b"HTTP/1.1 200") else 1) diff --git a/reg-tests/spoe/spoa_largeframe.py b/reg-tests/spoe/spoa_largeframe.py new file mode 100755 index 000000000..616830fc7 --- /dev/null +++ b/reg-tests/spoe/spoa_largeframe.py @@ -0,0 +1,128 @@ +# SPOA for the large-frame SPOE regression test. +# Handshakes, then on every NOTIFY decodes args; the "chunk" arg is a +# 14000-byte binary payload. Logs NOTIFY_OK when a complete NOTIFY with the +# full chunk was received and ACKed. + +import socket, sys, struct, threading + +def enc_varint(i): + out = bytearray() + if i < 240: + out.append(i) + return bytes(out) + out.append(240 | (i & 0x0F)) + i = (i - 240) >> 4 + while i >= 128: + out.append((i | 128) & 0xFF) + i = (i - 128) >> 7 + out.append(i & 0xFF) + return bytes(out) + +def dec_varint(buf, off): + v = buf[off]; off += 1 + if v < 240: + return v, off + r = 4 + while True: + v += buf[off] << r + r += 7 + off += 1 + if buf[off-1] < 128: + return v, off + +def enc_str(s): + if isinstance(s, str): s = s.encode() + return enc_varint(len(s)) + s + +def read_frame(sock): + hdr = b"" + while len(hdr) < 4: + d = sock.recv(4 - len(hdr)) + if not d: return None + hdr += d + ln = int.from_bytes(hdr, 'big') + body = b"" + while len(body) < ln: + d = sock.recv(ln - len(body)) + if not d: return None + body += d + return hdr + body + +def send_frame(sock, payload): + sock.sendall(len(payload).to_bytes(4, 'big') + payload) + +HAPROXY_HELLO = 1 +AGENT_HELLO = 101 +HAPROXY_NOTIFY = 3 +AGENT_ACK = 103 +HAPROXY_DISCON = 2 +T_STR = 8 +T_UINT32 = 3 +SET_VAR = 1 +SCOPE_TXN = 0x30 + +def parse_typed(buf, off): + t = buf[off]; off += 1 + m = t & 0x0F + if m == 0: return None, off + if m == 1: return (t & 0x10) != 0, off + if 2 <= m <= 7: + v, off = dec_varint(buf, off); return v, off + if m in (8, 9): + l, off = dec_varint(buf, off) + v = buf[off:off+l]; off += l + return (m, v), off + return None, off + +def handle(c): + try: + while True: + f = read_frame(c) + if f is None: return + ftype = f[4] + off = 9 + sid, off = dec_varint(f, off) + fid, off = dec_varint(f, off) + + if ftype == HAPROXY_HELLO: + payload = bytes([AGENT_HELLO]) + (1).to_bytes(4, 'big') + enc_varint(0) + enc_varint(0) + payload += enc_str("version") + bytes([T_STR]) + enc_str("2.0") + payload += enc_str("max-frame-size") + bytes([T_UINT32]) + enc_varint(16380) + payload += enc_str("capabilities") + bytes([T_STR]) + enc_str("") + send_frame(c, payload) + + elif ftype == HAPROXY_NOTIFY: + moff = off + nlen, moff = dec_varint(f, moff) + moff += nlen # skip message name + nb = f[moff]; moff += 1 + kv = {} + for _ in range(nb): + klen, moff = dec_varint(f, moff) + k = f[moff:moff+klen].decode(); moff += klen + v, moff = parse_typed(f, moff) + kv[k] = v + chunk = kv.get("chunk") + ok = chunk is not None and chunk[0] == 9 and len(chunk[1]) == 14000 + print("NOTIFY reqlen=%s chunk_len=%s" % ( + kv.get("reqlen"), len(chunk[1]) if chunk else None), flush=True) + if ok: + print("NOTIFY_OK", flush=True) + ack = bytes([AGENT_ACK]) + (1).to_bytes(4, 'big') + enc_varint(sid) + enc_varint(fid) + if ok: + ack += bytes([SET_VAR, 3, SCOPE_TXN]) + enc_str("bigok") + bytes([T_UINT32]) + enc_varint(1) + send_frame(c, ack) + + elif ftype == HAPROXY_DISCON: + return + except Exception as e: + print("ERR %s" % e, flush=True) + finally: + c.close() + +srv = socket.socket(); srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) +srv.bind(("127.0.0.1", int(sys.argv[1]))); srv.listen(5) +print("READY", flush=True) +while True: + c, _ = srv.accept() + threading.Thread(target=handle, args=(c,), daemon=True).start()