| 1 | //go:build unix |
| 2 | |
| 3 | package hostguard |
| 4 | |
| 5 | import "testing" |
| 6 | |
| 7 | func TestPlan14GenerationInstallationInventory(t *testing.T) { |
| 8 | for _, attack := range []string{"none", "unknown-file", "malformed", "uninitialized", "quarantined", "pending"} { |
| 9 | t.Run(attack, func(t *testing.T) { |
| 10 | f, target, captured := fenceFixture(t) |
| 11 | store := &rootTestStore{dir: t.TempDir()} |
| 12 | f.g.Root = NewRootAuthority(store) |
| 13 | f.obs.Claim.Holder.Account, f.obs.Claim.Holder.App = "bab", "console" |
| 14 | 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} |
| 15 | if err := f.g.EstablishRoot(t.Context(), in, allow); err != nil { |
| 16 | t.Fatal(err) |
| 17 | } |
| 18 | switch attack { |
| 19 | case "unknown-file": |
| 20 | if err := store.Write("unknown", nil); err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | case "malformed": |
| 24 | if err := store.Write(target.Host+".json", []byte("{}")); err != nil { |
| 25 | t.Fatal(err) |
| 26 | } |
| 27 | case "uninitialized", "quarantined", "pending": |
| 28 | r, err := f.g.Root.read(target.Host) |
| 29 | if err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | switch attack { |
| 33 | case "uninitialized": |
| 34 | r.installation.InventoryRevision = 0 |
| 35 | case "quarantined": |
| 36 | r.quarantined = true |
| 37 | case "pending": |
| 38 | r.pendingInstallation = &in |
| 39 | r.pendingInventory = []byte("pending") |
| 40 | } |
| 41 | if err := f.g.Root.write(r); err != nil { |
| 42 | t.Fatal(err) |
| 43 | } |
| 44 | } |
| 45 | got, err := f.g.Root.GenerationInstallations(t.Context()) |
| 46 | if attack == "none" { |
| 47 | if err != nil || len(got) != 1 || got[0].Installation != in { |
| 48 | t.Fatalf("installations: %+v %v", got, err) |
| 49 | } |
| 50 | } else if err == nil { |
| 51 | t.Fatal("incomplete installation certified") |
| 52 | } |
| 53 | }) |
| 54 | } |
| 55 | } |
| 56 | |