Files
slocker-lite/tests
ceamac 80cc49d898 Add [integration][net] rootless container-run tests
tests/integration/test_rootless_run.cpp runs a real busybox image through
the exact real -r/--run dispatch path (dispatch_command(), commands.h) --
mount, resolve, run_bwrap, unmount, cleanup, in-process rather than via a
subprocess -- and confirms bwrap's *default* sandboxing (no -n/-p at all)
is genuinely isolating: a fresh network namespace with nothing but
loopback, and pid/uts/ipc namespaces that differ from this test process's
own. No root needed, same as a plain `-r image.tar -- <command>` already
isn't.

New tests/support helpers: CapturedStdout (RAII, redirects this process's
own fd 1 -- and anything a forked/exec'd child inherits from it -- to a
throwaway temp file for its lifetime) so the sandboxed command's own
output can actually be asserted on.

Two real, non-obvious findings from getting this working, not assumed:
1. bwrap's own sandbox mounts --proc /proc and --dev /dev, but *not*
   /sys -- confirmed directly (`ls /sys/class/net` inside the sandbox:
   "No such file or directory", reproduced identically via the real CLI,
   not just this test). Switched the loopback-only check to
   /proc/net/dev instead (two header lines + one "<iface>: ..." line per
   interface), which correctly shows only "lo".
2. spdlog's default sink writes to stdout, not stderr, same as the plain
   "mounted image at: ..." success line (see CLAUDE.md) -- so a naive
   capture-and-line-split mixed slocker-lite's own status/log output in
   with the sandboxed command's real output. Fixed by having the
   sandboxed command bracket its own output between two unique markers
   and extracting only what's strictly between them.

Verified: both tests pass repeatably, 15 stress-test runs of the full
combined [unit]+[integration] suite with zero failures, plus a full run
as root.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gv3s5jckJKzh6JkMoi2Akz
2026-09-04 11:23:24 +00:00
..