package host import ( "strconv" "strings" "testing" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/hostguard" ) // testReceiptNumeral is a hand-built receipt's directory_revision, taken the // way every production receipt constructor takes it: from the fence target's // persisted RosterRevision (roster binding N1). The receipt's binding is the // target's DirectoryRevision. func testReceiptNumeral(t hostguard.FenceTarget) string { return strconv.FormatUint(t.RosterRevision, 10) } // servingPriorBinding is equality with the fresh actor's binding, never an // ordering: an older numeral stamp, a stamp from before a readmission, or // any stamp against an actor without a binding is refused. func TestServingPriorBindingIsEquality(t *testing.T) { b0, b1 := strings.Repeat("a", 64), strings.Repeat("b", 64) actor := hostbox.Actor{Revision: 9, Binding: b0} for _, c := range []struct { recorded string actor hostbox.Actor want bool }{ {b0, actor, true}, {b0, hostbox.Actor{Revision: 10, Binding: b0}, true}, {b1, actor, false}, {"9", actor, false}, {"8", actor, false}, {"1", actor, false}, {"", actor, false}, {"", hostbox.Actor{Revision: 9}, false}, {"9", hostbox.Actor{Revision: 9}, false}, {b0 + " ", actor, false}, } { if got := servingPriorBinding(c.recorded, c.actor); got != c.want { t.Errorf("servingPriorBinding(%q, %+v) = %v, want %v", c.recorded, c.actor, got, c.want) } } }