| 1 | //go:build linux && rootrunner |
| 2 | |
| 3 | package host |
| 4 | |
| 5 | import ( |
| 6 | "github.com/carlosframework/platform/internal/hostbox" |
| 7 | "os" |
| 8 | "path/filepath" |
| 9 | "testing" |
| 10 | ) |
| 11 | |
| 12 | func TestPlan14RebootStopDescriptorIdentity(t *testing.T) { |
| 13 | root, err := os.MkdirTemp("/var/lib", "carlos-p3-stop-device-") |
| 14 | if err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | defer os.RemoveAll(root) |
| 18 | path := filepath.Join(root, "state") |
| 19 | if err := os.Mkdir(path, 0700); err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | persistent := testPersistentInventory(t, path) |
| 23 | oldDevice := persistent.Device + 1 |
| 24 | persistent.Boot = "previous-boot" |
| 25 | persistent.Device = oldDevice |
| 26 | persistent.Mount++ |
| 27 | entry := hostbox.StopInventoryEntry{Kind: "path", ManagedRoot: "data", RelativePath: "state", Materialization: "materialized", Device: oldDevice, Inode: persistent.Inode, Type: persistent.Mode & 0170000, Identity: persistent} |
| 28 | in := StopInventory{Complete: true, Entries: []hostbox.StopInventoryEntry{entry}} |
| 29 | k := LinuxStopKernel{ManagedRoots: map[string]string{"data": root}} |
| 30 | files, err := k.rebootStopFiles(t.Context(), in, []hostbox.StopFileIdentity{{Device: oldDevice, Inode: 71}}) |
| 31 | now := testPersistentInventory(t, path) |
| 32 | if err != nil || len(files) != 1 || files[0].Device != now.Device || files[0].Inode != 71 { |
| 33 | t.Fatal("old deny set not rebased", files, err) |
| 34 | } |
| 35 | if _, err = k.rebootStopFiles(t.Context(), in, []hostbox.StopFileIdentity{{Device: oldDevice + 1, Inode: 71}}); err == nil { |
| 36 | t.Fatal("unmapped filesystem accepted") |
| 37 | } |
| 38 | in.Entries[0].Identity.Filesystem = "foreign" |
| 39 | if _, err = k.rebootStopFiles(t.Context(), in, []hostbox.StopFileIdentity{{Device: oldDevice, Inode: 71}}); err == nil { |
| 40 | t.Fatal("foreign filesystem accepted") |
| 41 | } |
| 42 | } |
| 43 | |