//go:build linux && rootrunner package host import ( "os" "os/exec" "path/filepath" "syscall" "testing" ) func TestPlan14GenerationRelocationUIDRootRunner(t *testing.T) { dir := generationRootRunnerDir(t) binary, err := os.Executable() if err != nil { t.Fatal(err) } raw, err := os.ReadFile(binary) if err != nil { t.Fatal(err) } installed := filepath.Join(dir, "runner.test") if err := os.WriteFile(installed, raw, 0755); err != nil { t.Fatal(err) } scratch := filepath.Join(dir, "service") if err := os.Mkdir(scratch, 0700); err != nil { t.Fatal(err) } if err := os.Chown(scratch, 65534, 65534); err != nil { t.Fatal(err) } cmd := exec.CommandContext(t.Context(), installed, "-test.run=^TestPlan14GenerationRelocationUIDPayload$", "-test.v", "-test.timeout=1m") cmd.Dir = scratch cmd.Env = []string{"PATH=/usr/bin:/bin", "HOME=" + scratch, "TMPDIR=" + scratch, "PLAN14_E41_UID=1"} cmd.SysProcAttr = &syscall.SysProcAttr{Credential: &syscall.Credential{Uid: 65534, Gid: 65534, Groups: []uint32{}}} if out, err := cmd.CombinedOutput(); err != nil { t.Fatalf("service UID relocation: %v\n%s", err, out) } else { t.Log(string(out)) } } func TestPlan14GenerationRelocationUIDPayload(t *testing.T) { if os.Getenv("PLAN14_E41_UID") != "1" || os.Geteuid() != 65534 { t.Fatal("invoke through TestPlan14GenerationRelocationUIDRootRunner") } TestPlan14GenerationRelocationDefaultMaterializer(t) }