//go:build linux package hostbox import ( "errors" "os" "path/filepath" "testing" "github.com/carlosframework/platform/internal/registry" ) func TestPlan9Fix4InventoryRefusesFlatRestartMarksArtifact(t *testing.T) { data := t.TempDir() host := "restart-marks.json" owner := "owner" victim := filepath.Join(data, host) if err := os.WriteFile(victim, []byte("root-written restart state"), 0600); err != nil { t.Fatal(err) } parker := TypedParker{Roots: map[string]string{"data": data}, ParkedRoot: data, Incarnation: "inc", Host: host, Retirement: "capture"} artifact, err := parker.CaptureArtifact("data", host, owner, ArtifactPath) if err != nil { t.Fatal(err) } inventory, err := OpenStopInventoryDB(filepath.Join(t.TempDir(), "inventory.db")) if err != nil { t.Fatal(err) } t.Cleanup(func() { inventory.Close() }) in := StopInventory{Complete: true, Host: host, Incarnation: "inc", InstallationStamp: 1, Box: "box", Enrollment: "enrollment", DirectoryRevision: "1", Entries: []StopInventoryEntry{{ Kind: "path", ArtifactID: "restart-marks", ManagedRoot: "data", RelativePath: artifact.Name, Ownership: artifact.Owner, Materialization: "materialized", Identity: artifact.Identity, Device: artifact.Dev, Inode: artifact.Ino, Type: artifact.Type, }}} if err = inventory.WriteStopInventory(t.Context(), in); err != nil { t.Fatal(err) } in, err = inventory.ReadInstallation(t.Context(), host, "inc", 1) if err != nil { t.Fatal(err) } row := registry.Route{Host: host, DBPath: filepath.Join(data, host+".db"), ClaimOwnership: registry.ClaimOwnership{ClaimIncarnation: "inc", ClaimStamp: 1, ClaimOwner: owner, ClaimRowID: "row"}} if err = ValidateAgentInventory(in, &row, data); !errors.Is(err, ErrTypedInventory) { t.Fatalf("flat inventory accepted root restart marks with captured identity: %v", err) } if body, err := os.ReadFile(victim); err != nil || string(body) != "root-written restart state" { t.Fatalf("refusal changed restart marks: %q %v", body, err) } }