Repository navigation
Conversation
Headers that must never be copied between connections, per RFC 9110 section 7.6.1.
|
Thank you! Can you add a test as well? |
|
CI failure fixed with #76 after a rebase. |
header_match() gates all three header-copying directions (client to auth backend, auth backend to protected backend, auth backend to client), but none of them were covered for hop-by-hop suppression. Add test/header_match.lua, a standalone unit test that needs only a lua interpreter. It pins down all nine HOP_BY_HOP_HEADERS entries, asserts a blocklisted header stays blocked when an operator requests it by name, and checks that ordinary headers keep matching so widening the two hardcoded content-length/host comparisons into a table did not over-block. It self-locates auth-request.lua, so it runs from any working directory. Add three .vtc tests, one per copying direction, and run the unit test in CI next to the vtest suite. Verified against the pre-fix condition (header == "content-length" or header == "host"): the unit test reports 14 failing checks and each .vtc test fails on an expected header, so none of them pass for the wrong reason. The full suite is green on HAProxy 3.4.8: 23 passed, 1 skipped, 0 failed. Two headers are deliberately not asserted end-to-end. HAProxy 3.4 strips a client "connection" or "upgrade" header before req_get_headers() is visible to Lua, and rejects a client request carrying both "connection: upgrade" and "upgrade: <proto>" at the frontend, with a 400 of its own, before any Lua action runs. Assertions on those would pass without the blocklist, so header_match.lua covers them directly instead.
lua-json depends only on lua-lpeg, so nothing in the job guaranteed a Lua binary on PATH for test/header_match.lua. Install lua5.4 alongside it and call that binary directly instead of probing PATH. The unit test itself is version-independent: it passes under lua5.1 and lua5.4 unchanged.
Check. |
215d19c to
39c7843
Compare
TimWolla
left a comment
There was a problem hiding this comment.
Thank you. I cleaned out the useless comments from the integration tests (I assume they come from some agent?) and pushed the changes.
For the standalone Lua test I'm looking forward to your feedback if you have reasons for it to stay that I'm missing or if we can just delete it, because an overzealous agent suggested adding it.
| -- 5. The blocklist keys must stay lowercase to keep matching the names HAProxy | ||
| -- and haproxy-lua-http hand back. A future edit writing "Connection" would | ||
| -- be invisible to the end-to-end tests, so catch it here. | ||
| for _, header in ipairs(HOP_BY_HOP) do | ||
| check("blocklist key is lowercase: " .. header, header, header:lower()) | ||
| end |
There was a problem hiding this comment.
I'm not sure this is testing something useful: HOP_BY_HOP is the table that is local to this test, not the one in the actual script.
There was a problem hiding this comment.
Overall I'm not sure if the premise of this test if worth introducing unit tests in addition to the integration tests. Getting a “table lookup” correct in Lua is not all that complicated and has little chance for regressions that are not also caught by the integration tests.
We can delete it, no problem. |
Headers that must never be copied between connections, per RFC 9110 section 7.6.1.
I ran into a problem where Websocket upgrade headers were causing HAProxy errors. It turns out that copying "connection: upgrade" plus "upgrade: websocket" from the client makes HAProxy's strict H1 parser reject the synthesized auth probe with
<BADREQ>, because the probe is a plain HEAD that the frontend cannot service as an upgrade request. Suppressing "connection" also lets haproxy-lua-http add its intended "connection: close".