MCPcopy
hub / github.com/perkeep/perkeep / TestClaimDate

Function TestClaimDate

pkg/schema/sign_test.go:58–90  ·  view source on GitHub ↗

TestClaimDate makes sure that when we sign a schema, we set the claimDate to the time of the signature. It demonstrates that issue #917 is fixed.

(t *testing.T)

Source from the content-addressed store, hash-verified

56// the time of the signature.
57// It demonstrates that issue #917 is fixed.
58func TestClaimDate(t *testing.T) {
59 ent, err := jsonsign.NewEntity()
60 if err != nil {
61 t.Fatal(err)
62 }
63 armorPub, err := jsonsign.ArmoredPublicKey(ent)
64 if err != nil {
65 t.Fatal(err)
66 }
67 pubRef := blob.RefFromString(armorPub)
68 sig, err := NewSigner(pubRef, strings.NewReader(armorPub), ent)
69 if err != nil {
70 t.Fatalf("NewSigner: %v", err)
71 }
72
73 sigTime, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z")
74 if err != nil {
75 t.Fatal(err)
76 }
77 share := NewShareRef(ShareHaveRef, true).SetShareTarget(pubRef)
78 signed, err := share.SignAt(ctxbg, sig, sigTime)
79 if err != nil {
80 t.Fatal(err)
81 }
82
83 ss := &superset{}
84 if err := json.NewDecoder(strings.NewReader(signed)).Decode(ss); err != nil {
85 t.Fatal(err)
86 }
87 if !strings.HasPrefix(ss.ClaimDate.String(), "2006-01-02") {
88 t.Fatalf("wrong claimDate in superset: got %q, wanted %q", ss.ClaimDate, sigTime)
89 }
90}

Callers

nothing calls this directly

Calls 12

NewEntityFunction · 0.92
ArmoredPublicKeyFunction · 0.92
RefFromStringFunction · 0.92
NewSignerFunction · 0.85
NewShareRefFunction · 0.85
FatalMethod · 0.80
ParseMethod · 0.80
SetShareTargetMethod · 0.80
SignAtMethod · 0.80
HasPrefixMethod · 0.80
FatalfMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected