From 4bb5d9780f3c46e942dc778d93c28391caee33c7 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Fri, 14 Mar 2025 17:51:29 +0900 Subject: ldd: run in native sandbox Signed-off-by: Ophestra --- internal/sandbox/container_test.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'internal') diff --git a/internal/sandbox/container_test.go b/internal/sandbox/container_test.go index 082d0dc3..6ef8cecd 100644 --- a/internal/sandbox/container_test.go +++ b/internal/sandbox/container_test.go @@ -69,10 +69,7 @@ func TestContainer(t *testing.T) { container.Uid = 1000 container.Gid = 100 container.Hostname = tc.host - container.CommandContext = func(ctx context.Context) *exec.Cmd { - return exec.CommandContext(ctx, os.Args[0], "-test.v", - "-test.run=TestHelperInit", "--", "init") - } + container.CommandContext = commandContext container.Flags |= tc.flags container.Stdout, container.Stderr = os.Stdout, os.Stderr container.Ops = tc.ops @@ -89,7 +86,11 @@ func TestContainer(t *testing.T) { Bind(os.Args[0], os.Args[0], 0) // in case test has cgo enabled var libPaths []string - if entries, err := ldd.Exec(ctx, os.Args[0]); err != nil { + if entries, err := ldd.ExecFilter(ctx, + commandContext, + func(v []byte) []byte { + return bytes.SplitN(v, []byte("TestHelperInit\n"), 2)[1] + }, os.Args[0]); err != nil { log.Fatalf("ldd: %v", err) } else { libPathsM := make(map[string]struct{}, len(entries)) @@ -175,3 +176,8 @@ func TestHelperCheckContainer(t *testing.T) { t.Run("seccomp", func(t *testing.T) { check.MustAssertSeccomp() }) t.Run("mntent", func(t *testing.T) { check.MustAssertMounts("", "/proc/mounts", "/proc/self/fd/0") }) } + +func commandContext(ctx context.Context) *exec.Cmd { + return exec.CommandContext(ctx, os.Args[0], "-test.v", + "-test.run=TestHelperInit", "--", "init") +} -- cgit v1.3.1