carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package host
2
3import (
4 "context"
5 "errors"
6 "testing"
7 "time"
8
9 "github.com/carlosframework/platform/internal/hostclaim"
10 execlease "github.com/carlosframework/platform/internal/hostexec"
11 "github.com/carlosframework/platform/internal/hostguard"
12)
13
14func TestPlan14RetiredParticipationDischarge(t *testing.T) {
15 for _, mode := range []string{"retired", "live", "foreign box", "foreign enrollment", "foreign session", "foreign op", "foreign stamp", "no receipt", "corrupt receipt", "barrier", "read failure"} {
16 t.Run(mode, func(t *testing.T) {
17 binding := execlease.Binding{Host: "shop.example", Incarnation: "inc", Op: "delete", Box: "box", Enrollment: "enrollment"}
18 o := hostclaim.Observed{Host: binding.Host, Claim: &hostclaim.Claim{Host: binding.Host, Holder: &hostclaim.Holder{Incarnation: "inc", Stamp: 3, Session: 4}, Op: hostclaim.Op{Kind: hostclaim.KindParking, ID: "delete"}}}
19 target := hostguard.FenceTarget{Host: binding.Host, Incarnation: "inc", Stamp: 3, Session: 4, Box: "box", Enrollment: "enrollment", Op: "delete", Phase: "park", ObligationID: "park-local", FenceID: "fence", BootID: "boot", ControllerID: "controller", ClaimETag: "etag", ClaimGen: 5, DirectoryRevision: "1", RosterRevision: 1, Region: "ie"}
20 at := time.Now().UTC()
21 s := StopReceipt{V: 1, Kind: "stopped", Host: target.Host, Incarnation: target.Incarnation, InstallationStamp: target.Stamp, WriterSession: target.Session, Box: target.Box, Enrollment: target.Enrollment, OperationID: target.Op, Phase: target.Phase, ObligationID: target.ObligationID, FenceID: target.FenceID, BootID: target.BootID, ControllerID: target.ControllerID, ClaimETag: target.ClaimETag, ClaimGen: target.ClaimGen, DirectoryRevision: testReceiptNumeral(target), Binding: target.DirectoryRevision, Region: target.Region, EvidenceAt: at}
22 captured := hostguard.Captured{Incarnation: "inc", Stamp: 3}
23 view := hostguard.FenceView{Installation: hostguard.RootInstallation{Host: binding.Host, Incarnation: "inc", Stamp: 3, Box: "box", Enrollment: "enrollment"}, Retired: []hostguard.Captured{captured}, Receipts: []hostguard.FenceReceipt{{Target: target, Bytes: mustMarshalStopReceipt(s), EvidenceAt: at}}}
24 switch mode {
25 case "live":
26 view.Retired = nil
27 case "foreign box":
28 binding.Box = "other"
29 case "foreign enrollment":
30 binding.Enrollment = "other"
31 case "foreign session":
32 o.Claim.Holder.Session++
33 case "foreign op":
34 view.Receipts[0].Target.Op = "other"
35 case "foreign stamp":
36 view.Receipts[0].Target.Stamp++
37 case "no receipt":
38 view.Receipts = nil
39 case "corrupt receipt":
40 view.Receipts[0].Bytes = []byte("{}")
41 case "barrier":
42 view.Barrier = &target
43 }
44 a := ClaimAssembly{Guard: hostguard.Guard{FenceView: func(context.Context, string, hostguard.Captured) (hostguard.FenceView, error) {
45 if mode == "read failure" {
46 return hostguard.FenceView{}, errors.New("unreadable")
47 }
48 return view, nil
49 }}}
50 done, err := a.completedRetirementDischarge(t.Context(), o, binding)
51 if mode == "retired" {
52 if !done || err != nil {
53 t.Fatalf("discharge: %v %v", done, err)
54 }
55 } else if mode == "live" {
56 if done || err != nil {
57 t.Fatalf("live cleanup bypass: %v %v", done, err)
58 }
59 } else if err == nil {
60 t.Fatalf("unsafe discharge: %v", done)
61 }
62 })
63 }
64}
65