Commit Graph
6 Commits
Author SHA1 Message Date
eric dbad0e80b8 test(e2e): connections that end mid-handshake or mid-read or write
The audit asked for shutdown to be checked with two Go plugins loaded and
connections that close during the handshake or with a read or write
pending. plugin-cleanup/ does that over chain[go-tls, ws, go-trojan], and
over the Rust TLS plugin with leaf's own Trojan, so that a fault the host
shares can be told from one in the Go plugins.

The host now logs, at trace, each engine instance it creates and each one
whose destroy_instance has returned; the cases require the two to balance
and the node to shut down. The Go SDK's destroy waits for the
connection's goroutines, so one that never finished would show up here.

Both chains failed the handshake case before the previous commit: no
instance was destroyed while the server stayed silent.
2026-12-04 09:55:40 +08:00
eric 1cf7f109b3 fix(plugin): drop a datagram the engine refuses, not the session
On an unreliable transport, a decode_packet failure ended the receive
side of the session, which leaf then removed. Every reference plugin
reports a reply it rejects -- failed authentication, an address it cannot
parse -- with PLUGIN_FAILURE, and a reply that fails authentication needs
no key. So one forged packet sent to the client's socket discarded every
reply that arrived before the client next sent something.

A frame the engine refuses with PLUGIN_FAILURE on an unreliable
transport is now dropped like any other damaged packet. Any other status
-- an argument the engine cannot use, an unsupported call, an output it
still cannot fit -- says the engine itself cannot go on, and still ends
the session. So does any failure on a reliable transport, since the
stream cannot be resynchronised, and an engine that breaks the ABI's
contract. The ABI documents the exception.

The e2e case now keeps one association, sends a good reply straight behind
each bad one, and adds a forged reply. It fails on the old host.
2026-12-04 09:55:40 +08:00
eric 9725f0a85e test(e2e): a release plugin survives a truncated reply address
The address parser fix is about a panic that only a release build turns
into an abort, since a debug plugin's guard catches it. A unit test cannot
show that the process lives, so this case loads the Shadowsocks plugin
built with the release profile, whatever profile the run uses.

A stand-in server speaking Shadowsocks AEAD UDP with leaf's own codec
echoes datagrams, and answers a request for a malformed reply with an
authenticated one whose address is cut short: a lone domain type byte, and
a domain one byte short of its port. The client must refuse both and keep
carrying traffic. On the old parser the case process dies with SIGABRT at
either reply.

Fixtures can now name a cargo profile of their own.
2026-12-04 08:35:38 +08:00
eric 518517d502 fix(e2e): stop upstream servers when a case process dies
An upstream server was killed from Drop, which never runs when the case
process does not unwind: a plugin that brings the Go runtime down, or the
runner killing a case that overran. One lost run left dozens of sing-box and
mihomo processes behind.

The server now runs under a small shell that holds a copy of its stdin and
kills it at end of file. The case holds the write end, so however the case
ends, the operating system closes it and the server goes with it. Drop takes
the same path.
2026-12-03 19:31:53 +08:00
eric bedc609506 test(e2e): run the reference plugins against upstream servers
A new interop lane puts a real leaf with each plugin in front of the servers
people deploy, built from source at pinned revisions: anytls-go, sing-box
stable and its testing branch, mihomo, and the original shadow-tls. Every
pair runs the stream behaviours, plus the server's padding scheme checked on
the wire, fingerprints, and the connections that must fail: wrong password,
hijacked to the real site, TLS 1.2 site in strict mode.

AnyTLS skips half-close-tail, which its protocol cannot carry. ShadowTLS
marks it a known defect: the host shuts the socket's write side while an
engine is still handshaking.

`make interop` runs the lane, `make e2e` leaves it out, and CI runs it in a
job of its own with the built servers cached. The harness no longer hands
out a port twice in one process, and builds upstream Rust servers with their
own toolchain, outside the workspace.
2026-12-03 19:31:53 +08:00
eric 9ef8d0d343 test(e2e): add the end-to-end suite for the plugin host
`leaf-e2e` starts real leaf instances and drives them from the outside over
SOCKS5, so a case covers the path a deployment takes -- config parsing, plugin
loading, routing, the dispatcher, the C ABI data plane -- and nothing reaches
into leaf to build a handler by hand. Cases are values rather than `#[test]`
functions, so the suite is a matrix of implementation, protocol, transport and
behaviour instead of a wall of copies, and each runs in its own process, free
to crash, hang, or set load-time environment.

The lanes:

- `differential` runs a behaviour natively and again with a plugin substituted
  for one stage, and requires the two to agree. The server is stock leaf, so
  these are interoperability tests. `protocols`, `halfclose` and `teardown`
  extend that across every stack, relay and selector, the end of a request on
  each transport, and shutdown.
- `abi`, `loader` and `coexist` check what the host accepts, refuses, and can
  load at once, through a real `dlopen`.
- `hostile` and `datagram` drive conformance plugins -- one in Rust, one in Go
  -- that misbehave on request, exercising the host's bounds checks, clamps,
  buffer growth and `decode_packet` handling.
- `stress` and the meters measure both sides back to back and assert the ratio,
  since absolute numbers from a shared runner say little; throughput, latency,
  setup cost and cpu cost land in `meters.json` beside the case logs. What the
  process is holding is asserted directly instead, against the case's own
  allocator, because what matters there is that it stopped growing.
- `blackbox` runs the shipped binary: on a config file, and on a plugin
  library through `--verify-plugin`, whose report has to agree with what the
  loader itself would do.

Plugins are built by the harness, and a case whose toolchain is missing is
reported as ignored with the reason; `--strict`, which CI passes, makes that a
failure, so the suite cannot go green by running nothing. The suite runs on
Windows too, where a pause is never shorter than 16ms and cases that dribble
bytes bound their pauses instead.
2026-12-03 19:31:53 +08:00