//go:build linux package release import ( "github.com/carlosframework/platform/internal/rootstate" "testing" ) func TestPlan14GenerationNamespaceProof(t *testing.T) { path := "/opt/carlos/versions/v1/lifecycle" before := rootstate.FileIdentity{Boot: "boot", Device: 66305, Inode: 131086, Filesystem: "ext4:volume", Handle: "file-handle", HandleType: 1, Mode: 0100755, MountRoot: "/opt/carlos", MountPoint: "/opt/carlos", MountNamespace: "private", Mount: 306, MountUnique: 306, NamespaceUnique: 1, MountLineage: "/opt/carlos\t/opt/carlos\n/\t/\n"} after := before after.MountRoot, after.MountPoint, after.MountNamespace, after.Mount = "/", "/", "host", 127 after.MountLineage = "/\t/\n" after.MountUnique, after.NamespaceUnique = 127, 2 if before.Same(after) { t.Fatal("fixture must cross mount layouts") } if !GenerationFileProof(path, before, after) { t.Fatal("same file through host mount refused") } for _, field := range []string{"source", "point", "namespace", "device", "filesystem", "handle", "inode", "owner", "mode", "missing"} { bad := after switch field { case "source": bad.MountRoot = "/other" case "point": bad.MountPoint = "/opt" case "namespace": bad.MountNamespace = before.MountNamespace bad.NamespaceUnique = before.NamespaceUnique case "device": bad.Device++ case "filesystem": bad.Filesystem = "other" case "handle": bad.Handle = "other" case "inode": bad.Inode++ case "owner": bad.UID++ case "mode": bad.Mode++ case "missing": bad.Handle = "" } if GenerationFileProof(path, before, bad) { t.Fatal("substitution accepted", field) } } } func TestPlan14GenerationMountSubstitution(t *testing.T) { path := "/opt/carlos/versions/v1/app" before := rootstate.FileIdentity{Boot: "old", Device: 1, Inode: 2, Filesystem: "fs", Handle: "handle", Mount: 3, MountUnique: 3, NamespaceUnique: 1, MountNamespace: "mnt:[1]", MountRoot: "/", MountPoint: "/", MountLineage: "/\t/\n"} for _, boot := range []string{before.Boot, "new"} { for _, point := range []string{"/opt/carlos", "/opt/carlos/versions/v1", path, "/"} { after := before after.Boot = boot after.MountRoot, after.MountPoint = point, point after.MountLineage = point + "\t" + point + "\n" + before.MountLineage if GenerationFileProof(path, before, after) { t.Fatal("substituted mount accepted", boot, point) } } } }