| 1 | package activator |
| 2 | |
| 3 | import ( |
| 4 | "os/exec" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/carlosframework/platform/internal/hostbox" |
| 8 | "github.com/carlosframework/platform/internal/instancectl" |
| 9 | ) |
| 10 | |
| 11 | func TestPlan14BoundRoleLaunch(t *testing.T) { |
| 12 | for _, attack := range []string{"none", "args", "env", "spec", "unit"} { |
| 13 | t.Run(attack, func(t *testing.T) { |
| 14 | f := newRootLaunchFixture(t) |
| 15 | f.launch.Unit = &hostbox.UnitLaunchInputs{Unit: "woodstar.service", Args: []string{"serve"}, Env: []string{"ROOT_ENV=yes"}} |
| 16 | f.launch.Spec = &hostbox.LaunchSpec{Args: []string{"serve"}, Env: []string{"ROOT_ENV=yes"}} |
| 17 | f.build = func() *exec.Cmd { |
| 18 | cmd := exec.Command(f.exe, "serve") |
| 19 | cmd.Env = []string{"ROOT_ENV=yes"} |
| 20 | if attack == "args" { |
| 21 | cmd.Args[1] = "shell" |
| 22 | } |
| 23 | if attack == "env" { |
| 24 | cmd.Env = []string{"ROOT_ENV=no"} |
| 25 | } |
| 26 | return cmd |
| 27 | } |
| 28 | if attack == "spec" { |
| 29 | f.launch.Spec.Args = []string{"shell"} |
| 30 | } |
| 31 | if attack == "unit" { |
| 32 | f.launch.Unit.Unit = "../other.service" |
| 33 | } |
| 34 | _, _, settle, _, err := f.launch.Start(t.Context(), "main", f.attempt, f.build, f.before) |
| 35 | if attack != "none" { |
| 36 | if err == nil || len(f.root.launches) != 0 { |
| 37 | t.Fatal("changed launch reached root", err) |
| 38 | } |
| 39 | return |
| 40 | } |
| 41 | if err != nil { |
| 42 | t.Fatal(err) |
| 43 | } |
| 44 | defer settle(t.Context()) |
| 45 | if len(f.root.launches) != 1 || f.root.launches[0].Reservation.Group.RelativePath != instancectl.BoundClaimUnitControlGroup("tenant.test", "woodstar.service") { |
| 46 | t.Fatal("wrong placement", f.root.launches) |
| 47 | } |
| 48 | }) |
| 49 | } |
| 50 | } |
| 51 | |