| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "strconv" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/carlosframework/platform/internal/hostbox" |
| 9 | "github.com/carlosframework/platform/internal/hostguard" |
| 10 | ) |
| 11 | |
| 12 | // testReceiptNumeral is a hand-built receipt's directory_revision, taken the |
| 13 | // way every production receipt constructor takes it: from the fence target's |
| 14 | // persisted RosterRevision (roster binding N1). The receipt's binding is the |
| 15 | // target's DirectoryRevision. |
| 16 | func testReceiptNumeral(t hostguard.FenceTarget) string { |
| 17 | return strconv.FormatUint(t.RosterRevision, 10) |
| 18 | } |
| 19 | |
| 20 | // servingPriorBinding is equality with the fresh actor's binding, never an |
| 21 | // ordering: an older numeral stamp, a stamp from before a readmission, or |
| 22 | // any stamp against an actor without a binding is refused. |
| 23 | func TestServingPriorBindingIsEquality(t *testing.T) { |
| 24 | b0, b1 := strings.Repeat("a", 64), strings.Repeat("b", 64) |
| 25 | actor := hostbox.Actor{Revision: 9, Binding: b0} |
| 26 | for _, c := range []struct { |
| 27 | recorded string |
| 28 | actor hostbox.Actor |
| 29 | want bool |
| 30 | }{ |
| 31 | {b0, actor, true}, |
| 32 | {b0, hostbox.Actor{Revision: 10, Binding: b0}, true}, |
| 33 | {b1, actor, false}, |
| 34 | {"9", actor, false}, |
| 35 | {"8", actor, false}, |
| 36 | {"1", actor, false}, |
| 37 | {"", actor, false}, |
| 38 | {"", hostbox.Actor{Revision: 9}, false}, |
| 39 | {"9", hostbox.Actor{Revision: 9}, false}, |
| 40 | {b0 + " ", actor, false}, |
| 41 | } { |
| 42 | if got := servingPriorBinding(c.recorded, c.actor); got != c.want { |
| 43 | t.Errorf("servingPriorBinding(%q, %+v) = %v, want %v", c.recorded, c.actor, got, c.want) |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |