MCPcopy Create free account
hub / github.com/cloudflare/cfssl / testInsertCertificateAndGetCertificate

Function testInsertCertificateAndGetCertificate

certdb/sql/sql_test.go:63–115  ·  view source on GitHub ↗
(ta TestAccessor, t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func testInsertCertificateAndGetCertificate(ta TestAccessor, t *testing.T) {
64 ta.Truncate()
65
66 expiry := time.Date(2010, time.December, 25, 23, 0, 0, 0, time.UTC)
67 want := certdb.CertificateRecord{
68 PEM: "fake cert data",
69 Serial: "fake serial",
70 AKI: fakeAKI,
71 Status: "good",
72 Reason: 0,
73 Expiry: expiry,
74 }
75 want.SetMetadata(map[string]interface{}{"k": "v"})
76 if err := ta.Accessor.InsertCertificate(want); err != nil {
77 t.Fatal(err)
78 }
79
80 rets, err := ta.Accessor.GetCertificate(want.Serial, want.AKI)
81 if err != nil {
82 t.Fatal(err)
83 }
84
85 if len(rets) != 1 {
86 t.Fatal("should only return one record.")
87 }
88
89 got := rets[0]
90
91 // reflection comparison with zero time objects are not stable as it seems
92 if want.Serial != got.Serial || want.Status != got.Status ||
93 want.AKI != got.AKI || !got.RevokedAt.IsZero() ||
94 want.PEM != got.PEM || !roughlySameTime(got.Expiry, expiry) {
95 t.Errorf("want Certificate %+v, got %+v", want, got)
96 }
97 gotMeta, err := got.GetMetadata()
98 if err != nil {
99 t.Fatal(err)
100 }
101 expected := map[string]interface{}{"k": "v"}
102 if !reflect.DeepEqual(gotMeta, expected) {
103 t.Fatalf("expected: %+v, got: %+v", expected, gotMeta)
104 }
105
106 unexpired, err := ta.Accessor.GetUnexpiredCertificates()
107
108 if err != nil {
109 t.Fatal(err)
110 }
111
112 if len(unexpired) != 0 {
113 t.Error("should not have unexpired certificate record")
114 }
115}
116
117func testInsertCertificateAndGetUnexpiredCertificate(ta TestAccessor, t *testing.T) {
118 ta.Truncate()

Callers 1

testEverythingFunction · 0.85

Calls 8

SetMetadataMethod · 0.95
roughlySameTimeFunction · 0.85
TruncateMethod · 0.80
GetMetadataMethod · 0.80
InsertCertificateMethod · 0.65
GetCertificateMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…