| 1 | package hostbox |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/carlosframework/platform/internal/rootstate" |
| 7 | ) |
| 8 | |
| 9 | func TestPlan14InventoryIdentityBootBoundary(t *testing.T) { |
| 10 | a := rootstate.FileIdentity{Device: 1, Inode: 2, Boot: "old", Filesystem: "fs", Handle: "handle", HandleType: 1, MountRoot: "/", MountPoint: "/data", MountNamespace: "ns", Mount: 3, UID: 1001, GID: 1001, Mode: 0040700} |
| 11 | b := a |
| 12 | b.Boot, b.Device, b.Mount, b.MountNamespace = "new", 4, 5, "new-ns" |
| 13 | if !sameInventoryIdentity(a, b) { |
| 14 | t.Fatal("persistent object refused after renumbering") |
| 15 | } |
| 16 | for _, field := range []string{"boot", "filesystem", "handle", "inode", "owner", "mode", "mount-root", "mount-point"} { |
| 17 | c := b |
| 18 | switch field { |
| 19 | case "boot": |
| 20 | c.Boot = a.Boot |
| 21 | c.MountNamespace = a.MountNamespace |
| 22 | case "filesystem": |
| 23 | c.Filesystem = "other" |
| 24 | case "handle": |
| 25 | c.Handle = "other" |
| 26 | case "inode": |
| 27 | c.Inode++ |
| 28 | case "owner": |
| 29 | c.UID++ |
| 30 | case "mode": |
| 31 | c.Mode++ |
| 32 | case "mount-root": |
| 33 | c.MountRoot = "/other" |
| 34 | case "mount-point": |
| 35 | c.MountPoint = "/other" |
| 36 | } |
| 37 | if sameInventoryIdentity(a, c) { |
| 38 | t.Fatalf("accepted changed %s", field) |
| 39 | } |
| 40 | } |
| 41 | a.Handle, b.Handle = "", "" |
| 42 | if sameInventoryIdentity(a, b) { |
| 43 | t.Fatal("cross-boot match without handle") |
| 44 | } |
| 45 | equalNumbers := a |
| 46 | equalNumbers.Boot = "another-boot" |
| 47 | if sameInventoryIdentity(a, equalNumbers) { |
| 48 | t.Fatal("equal numeric identity crossed boots without evidence") |
| 49 | } |
| 50 | if !sameInventoryIdentity(a, a) { |
| 51 | t.Fatal("same-boot unsupported filesystem refused") |
| 52 | } |
| 53 | if sameInventoryIdentity(rootstate.FileIdentity{}, rootstate.FileIdentity{}) { |
| 54 | t.Fatal("missing identity accepted") |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func TestPlan14InventoryRequestBindsPersistentIdentity(t *testing.T) { |
| 59 | q := JournalRequest{V: 3, Op: "inventory-write", RecordKey: "record", RecordETag: "etag", Inventory: StopInventory{Entries: []StopInventoryEntry{{Device: 1, Inode: 2, Identity: rootstate.FileIdentity{Boot: "old", Device: 1, Inode: 2}}}}} |
| 60 | before := journalRequestHash(q) |
| 61 | q.Inventory.Entries[0].Identity.Handle = "substituted" |
| 62 | if before == journalRequestHash(q) { |
| 63 | t.Fatal("inventory identity not covered by request digest") |
| 64 | } |
| 65 | } |
| 66 | |