Skip to content

E2E: tests/e2e ​

End-to-end scenarios in Docker: a real client, the proxy as a tproxy gateway and a target — in separate containers. The same scenario is run on our binary and on the reference.

The bench (tests/e2e/compose.yaml) ​

client 10.200.1.10 ──lan── proxy 10.200.1.254 / 10.200.2.254 ──wan── target 10.200.2.10
                                                                        (services on 203.0.113.10)
  • The client's default route is the proxy, and the proxy has net.ipv4.ip_forward=0: everything that reached the target went through the implementation under test.
  • The target's services (bin/target.sh) live on 203.0.113.10, which Docker knows nothing about: HTTP on tcp/8080 (ok, 8 MiB of random data and its sha256, a rule-set), a UDP echo on udp/9000, iperf3, held connections and so on.
  • bin/gateway.sh in the proxy container writes the nftables tproxy rules for port 7895, policy routing, and starts the implementation: sing-box run -c with the scenario's sing-box.json or ours run -c with its ours.yaml.
  • The images — tests/e2e/Dockerfile: Alpine with tools (curl, socat, iperf3, nft, python3), the sing-box target — the binary from the official v1.14.4 image by digest, xray — a release by sha256, ours — the binary is mounted from the host.
  • PROXY_CPUS, PEER_CPUS — the cpusets of the proxy and the peers.

Running ​

sh
PROXY=ours     tests/e2e/run.sh [--verbose] [scenario...]
PROXY=sing-box tests/e2e/run.sh [--verbose] [scenario...]
  • Without scenarios — all of tests/e2e/scenarios/.
  • PROXY — ours (the default), sing-box (the reference) or xray. For xray, gateway.sh expects xray.json in the scenario; only vless-fallback has it.
  • With PROXY=ours the script runs cargo build -p ours --target x86_64-unknown-linux-musl (as for OpenWrt; the binary works on Alpine; musl-gcc is needed) and takes it from CARGO_TARGET_DIR, or without it — from the checkout's target/. If the build directory is shared, the variable must be exported, otherwise the wrong binary gets into the container. OURS_BIN — a ready musl binary (for example, a frozen baseline), then no build happens.
  • The script enters the runner itself and loads the kernel modules nft_tproxy nf_tproxy_ipv4 nf_tproxy_ipv6 nft_fib_inet (the containers share the host kernel); sudo modprobe is called only for those not loaded yet.
  • Run ours and sing-box one after another: the compose projects (ours-e2e-<scenario>-<PROXY>) use the same subnets.

A scenario ​

tests/e2e/scenarios/<name>/:

  • check.sh — the checks, sourced by run.sh with . after the bench is up;
  • ours.yaml — our configuration, sing-box.json — the same for the reference (both are mandatory);
  • accompanying files (ca.pem, server.pem, server.key, binary.srs, dhcp.leases, alternative configurations for reload) are copied to /run/proxy.

The run.sh helpers:

  • on <service> <command…> — run in a container;
  • expect <name> <expectation> <service> <command…> — the command's output equals the expectation exactly;
  • expect_log <name> <service> <text> — the service's log has a line with the text (this is how it is proven that the traffic went through the protocol and not through direct).

The helpers in the containers — tests/e2e/bin/: dns.py, probe.py (a TLS handshake), socks5udp.py (UDP ASSOCIATE), hold.py (holding connections), udp_batch.py, udp_options.py, udp_pressure.py, ours-reload.sh (reload of our implementation to another configuration of the scenario). Branching on $PROXY inside check.sh is only for what the implementations do by different means (reload, selector, tls-fragment, udp-options).

The reference rule ​

A check that also fails on the reference (PROXY=sing-box) is wrong. First the scenario is fixed (or the check is removed), and only then is a bug looked for in our code. Intentional differences from sing-box are checked separately and described in differences.

Without Docker: tests/e2e/netns/auto-nft.sh ​

auto_nft end to end: client → router (ours, tproxy with auto_nft) → target, each in its own network namespace of its own user namespace — the host's netfilter and routing are not touched. Needs nft, ip, curl, socat, python3 and the same kernel modules. The target answers with the source address, from which one can see whether the flow went through the kernel, through the process (via-wan) or through direct. OURS_BIN — a ready binary, otherwise cargo build -p ours. At the end — what remains after SIGKILL: a start without auto_nft and ours clean remove the table and the rules, clean refuses while the process is alive, an error after the table is written (a busy --dashboard address) removes it.

Without Docker: tests/e2e/netns/tun.sh ​

The tun inbound, likewise without root: client → router (tun with auto_route, then with auto_redirect; then the redirect inbound behind an nftables rule) → target, IPv4 and IPv6. Checked are the TCP and UDP of the client and of the router itself, capture of DNS to the device's address and (with auto_redirect) to any server, reload with a changed inbound (ours only), removal of the rules and the table on stop, leftovers after SIGKILL and their removal by a start and by ours clean (ours only: sing-box also leaves its table and rules after SIGKILL). PROXY=sing-box SING_BOX_BIN=<sing-box 1.14> — the same scenario on the reference; the binary can be taken, for example, from the sbrs-e2e/sing-box image that PROXY=sing-box tests/e2e/run.sh builds (docker cp).

GPL-3.0-or-later