carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1//go:build linux && rootrunner
2
3package host
4
5import (
6 "os"
7 "os/exec"
8 "path/filepath"
9 "syscall"
10 "testing"
11)
12
13func TestPlan14GenerationRelocationUIDRootRunner(t *testing.T) {
14 dir := generationRootRunnerDir(t)
15 binary, err := os.Executable()
16 if err != nil {
17 t.Fatal(err)
18 }
19 raw, err := os.ReadFile(binary)
20 if err != nil {
21 t.Fatal(err)
22 }
23 installed := filepath.Join(dir, "runner.test")
24 if err := os.WriteFile(installed, raw, 0755); err != nil {
25 t.Fatal(err)
26 }
27 scratch := filepath.Join(dir, "service")
28 if err := os.Mkdir(scratch, 0700); err != nil {
29 t.Fatal(err)
30 }
31 if err := os.Chown(scratch, 65534, 65534); err != nil {
32 t.Fatal(err)
33 }
34 cmd := exec.CommandContext(t.Context(), installed, "-test.run=^TestPlan14GenerationRelocationUIDPayload$", "-test.v", "-test.timeout=1m")
35 cmd.Dir = scratch
36 cmd.Env = []string{"PATH=/usr/bin:/bin", "HOME=" + scratch, "TMPDIR=" + scratch, "PLAN14_E41_UID=1"}
37 cmd.SysProcAttr = &syscall.SysProcAttr{Credential: &syscall.Credential{Uid: 65534, Gid: 65534, Groups: []uint32{}}}
38 if out, err := cmd.CombinedOutput(); err != nil {
39 t.Fatalf("service UID relocation: %v\n%s", err, out)
40 } else {
41 t.Log(string(out))
42 }
43}
44
45func TestPlan14GenerationRelocationUIDPayload(t *testing.T) {
46 if os.Getenv("PLAN14_E41_UID") != "1" || os.Geteuid() != 65534 {
47 t.Fatal("invoke through TestPlan14GenerationRelocationUIDRootRunner")
48 }
49 TestPlan14GenerationRelocationDefaultMaterializer(t)
50}
51