- Rename `par` to `pred` (predecessor) in types, serialization, tests - Remove `pol`, `pol_decision` from core payload; move to `ect_ext` - Remove `sub` from payload (not part of ECT spec) - Update `typ` from `wimse-exec+jwt` to `exec+jwt` (accept both) - Rename MaxParLength to MaxPredLength everywhere - Update testdata, demos, READMEs with migration table - All Go tests pass, all 56 Python tests pass (90% coverage)
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package ect
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestMemoryLedger_AppendAndGet(t *testing.T) {
|
|
m := NewMemoryLedger()
|
|
p := &Payload{Jti: "jti-1", Iss: "iss", ExecAct: "act", Pred: []string{}, Iat: time.Now().Unix(), Exp: time.Now().Add(time.Hour).Unix()}
|
|
seq, err := m.Append("jws1", p)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if seq != 1 {
|
|
t.Errorf("seq: got %d", seq)
|
|
}
|
|
got := m.GetByTid("jti-1")
|
|
if got == nil || got.Jti != "jti-1" {
|
|
t.Errorf("GetByTid: got %v", got)
|
|
}
|
|
}
|
|
|
|
func TestMemoryLedger_ErrTaskIDExists(t *testing.T) {
|
|
m := NewMemoryLedger()
|
|
p := &Payload{Jti: "jti-dup", Iss: "i", ExecAct: "e", Pred: []string{}, Iat: 1, Exp: 2}
|
|
_, _ = m.Append("jws1", p)
|
|
_, err := m.Append("jws2", p)
|
|
if err != ErrTaskIDExists {
|
|
t.Errorf("expected ErrTaskIDExists, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestMemoryLedger_ContainsWid(t *testing.T) {
|
|
m := NewMemoryLedger()
|
|
p := &Payload{Jti: "j1", Wid: "wf1", Iss: "i", ExecAct: "e", Pred: []string{}, Iat: 1, Exp: 2}
|
|
_, _ = m.Append("jws", p)
|
|
if !m.Contains("j1", "") {
|
|
t.Error("Contains(j1, \"\") should be true")
|
|
}
|
|
if !m.Contains("j1", "wf1") {
|
|
t.Error("Contains(j1, wf1) should be true")
|
|
}
|
|
if m.Contains("j1", "wf2") {
|
|
t.Error("Contains(j1, wf2) should be false")
|
|
}
|
|
}
|
|
|
|
func TestMemoryLedger_AppendNilPayload(t *testing.T) {
|
|
m := NewMemoryLedger()
|
|
seq, err := m.Append("jws", nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if seq != 0 {
|
|
t.Errorf("Append(nil) should return 0, got %d", seq)
|
|
}
|
|
}
|