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

Function testUpdateCertificateAndGetCertificate

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

Source from the content-addressed store, hash-verified

230}
231
232func testUpdateCertificateAndGetCertificate(ta TestAccessor, t *testing.T) {
233 ta.Truncate()
234
235 expiry := time.Now().Add(time.Hour)
236 want := certdb.CertificateRecord{
237 PEM: "fake cert data",
238 Serial: "fake serial 3",
239 AKI: fakeAKI,
240 Status: "good",
241 Reason: 0,
242 Expiry: expiry,
243 }
244
245 // Make sure the revoke on a non-existent cert fails
246 if err := ta.Accessor.RevokeCertificate(want.Serial, want.AKI, 2); err == nil {
247 t.Fatal("Expected error")
248 }
249
250 if err := ta.Accessor.InsertCertificate(want); err != nil {
251 t.Fatal(err)
252 }
253
254 // reason 2 is CACompromise
255 if err := ta.Accessor.RevokeCertificate(want.Serial, want.AKI, 2); err != nil {
256 t.Fatal(err)
257 }
258
259 rets, err := ta.Accessor.GetCertificate(want.Serial, want.AKI)
260 if err != nil {
261 t.Fatal(err)
262 }
263
264 if len(rets) != 1 {
265 t.Fatal("should return exactly one record")
266 }
267
268 got := rets[0]
269
270 // reflection comparison with zero time objects are not stable as it seems
271 if want.Serial != got.Serial || got.Status != "revoked" ||
272 want.AKI != got.AKI || got.RevokedAt.IsZero() ||
273 want.PEM != got.PEM {
274 t.Errorf("want Certificate %+v, got %+v", want, got)
275 }
276
277 rets, err = ta.Accessor.GetRevokedAndUnexpiredCertificates()
278 if err != nil {
279 t.Fatal(err)
280 }
281
282 got = rets[0]
283
284 // reflection comparison with zero time objects are not stable as it seems
285 if want.Serial != got.Serial || got.Status != "revoked" ||
286 want.AKI != got.AKI || got.RevokedAt.IsZero() ||
287 want.PEM != got.PEM {
288 t.Errorf("want Certificate %+v, got %+v", want, got)
289 }

Callers 1

testEverythingFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…