//go:build unix package hostguard import "testing" func TestPlan14GenerationInstallationInventory(t *testing.T) { for _, attack := range []string{"none", "unknown-file", "malformed", "uninitialized", "quarantined", "pending"} { t.Run(attack, func(t *testing.T) { f, target, captured := fenceFixture(t) store := &rootTestStore{dir: t.TempDir()} f.g.Root = NewRootAuthority(store) f.obs.Claim.Holder.Account, f.obs.Claim.Holder.App = "bab", "console" in := RootInstallation{Host: target.Host, Incarnation: captured.Incarnation, Stamp: captured.Stamp, Account: "bab", App: "console", Record: "record", Box: target.Box, Enrollment: target.Enrollment, Migration: 1, InventoryRevision: 1} if err := f.g.EstablishRoot(t.Context(), in, allow); err != nil { t.Fatal(err) } switch attack { case "unknown-file": if err := store.Write("unknown", nil); err != nil { t.Fatal(err) } case "malformed": if err := store.Write(target.Host+".json", []byte("{}")); err != nil { t.Fatal(err) } case "uninitialized", "quarantined", "pending": r, err := f.g.Root.read(target.Host) if err != nil { t.Fatal(err) } switch attack { case "uninitialized": r.installation.InventoryRevision = 0 case "quarantined": r.quarantined = true case "pending": r.pendingInstallation = &in r.pendingInventory = []byte("pending") } if err := f.g.Root.write(r); err != nil { t.Fatal(err) } } got, err := f.g.Root.GenerationInstallations(t.Context()) if attack == "none" { if err != nil || len(got) != 1 || got[0].Installation != in { t.Fatalf("installations: %+v %v", got, err) } } else if err == nil { t.Fatal("incomplete installation certified") } }) } }