package hostbox import ( "testing" "github.com/carlosframework/platform/internal/rootstate" ) func TestPlan14InventoryIdentityBootBoundary(t *testing.T) { 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} b := a b.Boot, b.Device, b.Mount, b.MountNamespace = "new", 4, 5, "new-ns" if !sameInventoryIdentity(a, b) { t.Fatal("persistent object refused after renumbering") } for _, field := range []string{"boot", "filesystem", "handle", "inode", "owner", "mode", "mount-root", "mount-point"} { c := b switch field { case "boot": c.Boot = a.Boot c.MountNamespace = a.MountNamespace case "filesystem": c.Filesystem = "other" case "handle": c.Handle = "other" case "inode": c.Inode++ case "owner": c.UID++ case "mode": c.Mode++ case "mount-root": c.MountRoot = "/other" case "mount-point": c.MountPoint = "/other" } if sameInventoryIdentity(a, c) { t.Fatalf("accepted changed %s", field) } } a.Handle, b.Handle = "", "" if sameInventoryIdentity(a, b) { t.Fatal("cross-boot match without handle") } equalNumbers := a equalNumbers.Boot = "another-boot" if sameInventoryIdentity(a, equalNumbers) { t.Fatal("equal numeric identity crossed boots without evidence") } if !sameInventoryIdentity(a, a) { t.Fatal("same-boot unsupported filesystem refused") } if sameInventoryIdentity(rootstate.FileIdentity{}, rootstate.FileIdentity{}) { t.Fatal("missing identity accepted") } } func TestPlan14InventoryRequestBindsPersistentIdentity(t *testing.T) { 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}}}}} before := journalRequestHash(q) q.Inventory.Entries[0].Identity.Handle = "substituted" if before == journalRequestHash(q) { t.Fatal("inventory identity not covered by request digest") } }