Skip to content

Give the SOCKS5 proxy test a hermetic target - #107

Merged
madeye merged 1 commit into
mainfrom
fix/socks5-test-hermetic-target
Aug 26, 2026
Merged

Give the SOCKS5 proxy test a hermetic target#107
madeye merged 1 commit into
mainfrom
fix/socks5-test-hermetic-target

Conversation

@madeye

@madeye madeye commented Aug 26, 2026

Copy link
Copy Markdown
Owner

The problem

ProxyEngineIntegrationTests.httpRequestThroughSOCKS5 curled www.gstatic.com through the engine. It uses --socks5, not --socks5-hostname, so curl resolves the name itself and the engine receives a raw IP literal to dial — which is the point of the test, since that is exactly what the transparent proxy hands it for every TCP flow.

But it also means the assertion depends on that public IP being directly reachable. On a network that blocks Google by address, the DIRECT dial times out and the test fails for reasons that have nothing to do with the proxy chain. It fails 100% of the time on the maintainer's network; curl --resolve with no proxy anywhere in the path times out identically.

The fix

Serve the target locally. LocalHTTPServer binds 127.0.0.1 on a kernel-assigned port and answers 204 No Content; the test curls that through the SOCKS5 listener. The machinery under test is unchanged — SOCKS5 CONNECT with ATYP=0x01, rule match, DIRECT dial to an IPv4 literal, bidirectional relay — with no internet in the loop.

connectionTracking generated its traffic the same way. It never asserted on the curl result, so it passed regardless, but it burned the full 10s timeout and populated no connection to query. It now uses the local target too, which is what takes the suite from 41.9s to 21.3s.

--noproxy "" is load-bearing

curl 7.86+ silently bypasses the proxy for localhost targets. Without that flag the request never reaches the engine and the test passes for the wrong reason — a false green that looks identical to a real one.

Verified by mutation rather than assertion: pointing the test at a dead SOCKS port makes it fail with curl exit 7, refused by the proxy, rather than succeeding past it.

✘ Expectation failed: (result.exitCode → 7) == 0

Left alone on purpose

httpRequestThroughHTTPProxy keeps the public hostname. An HTTP proxy is handed a name, not an address, so it is the only test covering rule matching on a hostname and resolution through the engine's own dns: section — pointing it at loopback would turn it into a second IP-literal test. There is now a comment saying so.

Verification

  • swiftlint lint --strict — 0 violations
  • BaoLianDengTests — 213/213 pass, on a network where the old test could not pass

`httpRequestThroughSOCKS5` curled gstatic through the engine. It uses
`--socks5`, not `--socks5-hostname`, so curl resolves the name itself and
the engine receives a raw IP literal to dial — which is the point of the
test, since that is exactly what the transparent proxy hands it for every
TCP flow. But it also means the assertion depends on that public IP being
directly reachable, and on a network that blocks Google by address the
DIRECT dial times out and the test fails for reasons that have nothing to
do with the proxy chain.

Serve the target locally instead. `LocalHTTPServer` binds 127.0.0.1 on a
kernel-assigned port and answers `204 No Content`; the test curls that
through the SOCKS5 listener. Same machinery under test — SOCKS5 CONNECT
with ATYP=0x01, rule match, DIRECT dial to an IPv4 literal, bidirectional
relay — with no internet in the loop.

`connectionTracking` generated its traffic the same way. It never asserted
on the curl result, so it passed regardless, but it burned the full 10s
timeout and populated no connection to query. It now uses the local target
too, which is what takes the suite from 41.9s to 21.3s.

The curl helper gained `--noproxy ""`, and that flag is load-bearing:
curl 7.86+ silently bypasses the proxy for localhost targets, so without
it the request never reaches the engine and the test passes for the wrong
reason. Verified by mutation — pointing the test at a dead SOCKS port
fails with curl exit 7 (refused by the proxy), not a success that
sneaked past it.

`httpRequestThroughHTTPProxy` deliberately keeps the public hostname: an
HTTP proxy is handed a name, not an address, so it is the only test
covering rule matching on a hostname and resolution through the engine's
own `dns:` section.

Verified: swiftlint --strict (0 violations), BaoLianDengTests 213/213 on
a network where the old test could not pass.
@madeye
madeye merged commit 0266221 into main Aug 26, 2026
5 checks passed
@madeye
madeye deleted the fix/socks5-test-hermetic-target branch August 26, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant