//go:build linux package host import ( "bytes" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/rootstate" "os" "testing" ) func testPersistentInventory(t *testing.T, path string) rootstate.FileIdentity { t.Helper() f, err := hostbox.OpenInventoryFile(path) if err != nil { t.Fatal(err) } defer f.Close() id, err := rootstate.ObjectIdentity(f) if err != nil { t.Fatal(err) } return id } func TestPlan14ProofFileSourceBootEvidence(t *testing.T) { before := proofUnitFile{Path: "/opt/app", Persistent: rootstate.FileIdentity{Boot: "old", Device: 1, Inode: 2, Filesystem: "fs", Handle: "handle", MountRoot: "/", MountPoint: "/", MountNamespace: "mnt:[1]", Mount: 3, MountLineage: "/\t/\n", MountUnique: 100, NamespaceUnique: 10}} after := before after.Persistent.Boot = "new" after.Persistent.Device++ after.Persistent.Mount++ after.Persistent.MountUnique++ after.Persistent.NamespaceUnique++ if !sameProofFiles([]proofUnitFile{before}, []proofUnitFile{after}) || !bytes.Equal(proofFileSource(before), proofFileSource(after)) { t.Fatal("unchanged persistent file lost its proof across reboot") } after = before after.Persistent.MountUnique++ if sameProofFiles([]proofUnitFile{before}, []proofUnitFile{after}) { t.Fatal("stable proof hash admitted a replacement mount") } if !bytes.Equal(proofFileSource(before), proofFileSource(after)) { t.Fatal("boot-local mount evidence entered the stable hash") } after = before after.Persistent.Handle = "other" if sameProofFiles([]proofUnitFile{before}, []proofUnitFile{after}) || bytes.Equal(proofFileSource(before), proofFileSource(after)) { t.Fatal("changed persistent file retained its proof") } } func TestPlan14InventoryWithoutPersistentEvidenceRefuses(t *testing.T) { path := t.TempDir() f, err := os.Open(path) if err != nil { t.Fatal(err) } defer f.Close() id, err := rootstate.Identity(f) if err != nil { t.Fatal(err) } e := hostbox.StopInventoryEntry{Device: id.Device, Inode: id.Inode, Type: 0040000} if err := hostbox.VerifyInventoryFile(f, e); err == nil { t.Fatal("old boot-unknown inventory admitted") } e.Identity = testPersistentInventory(t, path) if err := hostbox.VerifyInventoryFile(f, e); err != nil { t.Fatal(err) } }