package sandbox import ( "os" "os/exec" "testing" ) func TestApplyProxy_Disabled(t *testing.T) { if err := ApplyProxy("", false, false); err != nil { t.Fatalf("expected nil when disabled, got %v", err) } } func TestApplyProxy_Subprocess(t *testing.T) { if os.Getenv("TEST_PROXY_SANDBOX_SUBPROCESS") == "1" { cacheDir, err := os.MkdirTemp("", "mats-proxy-test-*") if err != nil { t.Fatalf("failed creating temp dir: %v", err) } if err := ApplyProxy(cacheDir, true, true); err != nil { t.Fatalf("failed applying proxy sandbox: %v", err) } // Under seccomp, execve should fail or return error cmd := exec.Command("true") if err := cmd.Run(); err == nil { t.Fatalf("expected execve to be blocked under seccomp") } os.Exit(0) } cmd := exec.Command(os.Args[0], "-test.run=TestApplyProxy_Subprocess", "-test.v") cmd.Env = append(os.Environ(), "TEST_PROXY_SANDBOX_SUBPROCESS=1") out, err := cmd.CombinedOutput() if err != nil { t.Fatalf("proxy sandbox subprocess failed: %v\nOutput:\n%s", err, string(out)) } }