Files
zero/internal/sandbox/linux_helper_linux_test.go
Anandan 96859c9bd1 feat(sandbox): unify command execution and enforcement (#781)
* feat(sandbox): unify command execution and enforcement

* test(sandbox): make platform contracts portable

* fix(sandbox): close execution lifecycle races

Bound retained interactive output, preserve interruption state, and start workspace observation before process launch.

Protect active runtime roots with cross-platform leases, capture transient protected-path creation events, and restore process attributes after PTY fallback.

* fix(sandbox): restore strict macOS isolation

Remove Seatbelt host-local network allowances after native validation showed localhost filters can reach host interfaces.

Track process reap completion so retained sessions cannot signal a stale numeric PID.
2026-07-21 18:55:13 +05:30

68 lines
2.0 KiB
Go

//go:build linux
package sandbox
import (
"bytes"
"errors"
"testing"
)
func TestLinuxSandboxInnerStageReliesOnOuterNamespaceForNetworkDeny(t *testing.T) {
originalNetworkGuard := applyLinuxIsolatedNetworkGuardFilter
originalUnixBlock := applyUnixSocketBlockFilter
t.Cleanup(func() {
applyLinuxIsolatedNetworkGuardFilter = originalNetworkGuard
applyUnixSocketBlockFilter = originalUnixBlock
})
networkGuardCalls := 0
unixBlockCalls := 0
applyLinuxIsolatedNetworkGuardFilter = func() error {
networkGuardCalls++
return nil
}
applyUnixSocketBlockFilter = func() error {
unixBlockCalls++
return nil
}
var stderr bytes.Buffer
code := runLinuxSandboxInnerStage(LinuxSandboxHelperConfig{
PermissionProfile: PermissionProfile{Network: NetworkPolicy{Mode: NetworkDeny}},
BlockUnixSockets: true,
Command: []string{"definitely-not-a-real-zero-test-command"},
}, &stderr)
if code != 127 {
t.Fatalf("exit code = %d, want lookup failure 127 after Unix-socket filter; stderr=%s", code, stderr.String())
}
if networkGuardCalls != 1 {
t.Fatalf("isolated network guard calls = %d, want 1", networkGuardCalls)
}
if unixBlockCalls != 1 {
t.Fatalf("unix socket filter calls = %d, want 1", unixBlockCalls)
}
}
func TestLinuxSandboxInnerStageSkipsIsolatedNetworkGuardWhenNetworkAllowed(t *testing.T) {
originalNetworkGuard := applyLinuxIsolatedNetworkGuardFilter
t.Cleanup(func() {
applyLinuxIsolatedNetworkGuardFilter = originalNetworkGuard
})
applyLinuxIsolatedNetworkGuardFilter = func() error {
return errors.New("isolated network guard should not run")
}
var stderr bytes.Buffer
code := runLinuxSandboxInnerStage(LinuxSandboxHelperConfig{
PermissionProfile: PermissionProfile{Network: NetworkPolicy{Mode: NetworkAllow}},
Command: []string{"definitely-not-a-real-zero-test-command"},
}, &stderr)
if code != 127 {
t.Fatalf("exit code = %d, want lookup failure 127 without isolated network guard; stderr=%s", code, stderr.String())
}
}