package activator import ( "os/exec" "testing" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/instancectl" ) func TestPlan14BoundRoleLaunch(t *testing.T) { for _, attack := range []string{"none", "args", "env", "spec", "unit"} { t.Run(attack, func(t *testing.T) { f := newRootLaunchFixture(t) f.launch.Unit = &hostbox.UnitLaunchInputs{Unit: "woodstar.service", Args: []string{"serve"}, Env: []string{"ROOT_ENV=yes"}} f.launch.Spec = &hostbox.LaunchSpec{Args: []string{"serve"}, Env: []string{"ROOT_ENV=yes"}} f.build = func() *exec.Cmd { cmd := exec.Command(f.exe, "serve") cmd.Env = []string{"ROOT_ENV=yes"} if attack == "args" { cmd.Args[1] = "shell" } if attack == "env" { cmd.Env = []string{"ROOT_ENV=no"} } return cmd } if attack == "spec" { f.launch.Spec.Args = []string{"shell"} } if attack == "unit" { f.launch.Unit.Unit = "../other.service" } _, _, settle, _, err := f.launch.Start(t.Context(), "main", f.attempt, f.build, f.before) if attack != "none" { if err == nil || len(f.root.launches) != 0 { t.Fatal("changed launch reached root", err) } return } if err != nil { t.Fatal(err) } defer settle(t.Context()) if len(f.root.launches) != 1 || f.root.launches[0].Reservation.Group.RelativePath != instancectl.BoundClaimUnitControlGroup("tenant.test", "woodstar.service") { t.Fatal("wrong placement", f.root.launches) } }) } }