//go:build linux package activator import ( "context" "errors" "os" "os/exec" "path/filepath" "testing" "github.com/carlosframework/platform/internal/cgroup" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/hostclaim" "github.com/carlosframework/platform/internal/hostguard" "github.com/carlosframework/platform/internal/hostwrite" ) func TestLaunchExecutableValidationPrecedesChild(t *testing.T) { ctx := t.Context() j, err := hostbox.OpenLaunchJournal(filepath.Join(t.TempDir(), "launch.db")) if err != nil { t.Fatal(err) } defer j.Close() target := hostguard.FenceTarget{Host: "app.test", Incarnation: "inc", Stamp: 1, Session: 1, Box: "box", Enrollment: "enroll", BootID: "boot", ControllerID: "ctrl"} if err := j.Prelaunch(ctx, hostbox.LaunchInventory{Target: target, ControllerPID: 42, ProcessStart: "start", Groups: []hostbox.LaunchGroup{{RelativePath: "parent", Device: 1, Inode: 1}}, NoState: true}); err != nil { t.Fatal(err) } work, _ := (hostwrite.Config{}).Select(ctx, target.Host, "spawn") invalid := errors.New("invalid executable") checked := false l := RoleLaunch{Parent: &cgroup.Prepared{}, ParentPath: "parent", Target: target, Work: work, Journal: j, RegisterProducer: func(context.Context, string) (RoleProducer, error) { t.Fatal("registered invalid executable") return RoleProducer{}, nil }, Executable: func(context.Context, *exec.Cmd) (*os.File, error) { checked = true; return nil, invalid }} attempt := hostclaim.WakeRetryAttempt{ID: "a", InvocationID: "inv", LaunchInputs: "inputs", Session: 1, Box: "box", Enrollment: "enroll", BootID: "boot", ControllerID: "ctrl"} _, child, _, err := l.prepareRoleReservation(ctx, "main", attempt, func() *exec.Cmd { return exec.Command("unused") }) if !errors.Is(err, invalid) || !checked || child != nil { t.Fatalf("checked=%v child=%v err=%v", checked, child, err) } in, err := j.Read(ctx, target) if err != nil || len(in.Reservations) != 0 || len(in.Groups) != 1 { t.Fatalf("invalid executable changed journal: %+v %v", in, err) } }