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

Function testUpsertOCSPAndGetOCSP

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

Source from the content-addressed store, hash-verified

441}
442
443func testUpsertOCSPAndGetOCSP(ta TestAccessor, t *testing.T) {
444 ta.Truncate()
445
446 want := certdb.OCSPRecord{
447 Serial: "fake serial 3",
448 AKI: fakeAKI,
449 Body: "fake body",
450 Expiry: time.Date(2010, time.December, 25, 23, 0, 0, 0, time.UTC),
451 }
452 setupGoodCert(ta, t, want)
453
454 if err := ta.Accessor.UpsertOCSP(want.Serial, want.AKI, want.Body, want.Expiry); err != nil {
455 t.Fatal(err)
456 }
457
458 rets, err := ta.Accessor.GetOCSP(want.Serial, want.AKI)
459 if err != nil {
460 t.Fatal(err)
461 }
462 if len(rets) != 1 {
463 t.Fatal("should return exactly one record")
464 }
465
466 got := rets[0]
467
468 if want.Serial != got.Serial || want.Body != got.Body ||
469 !roughlySameTime(want.Expiry, got.Expiry) {
470 t.Errorf("want OCSP %+v, got %+v", want, got)
471 }
472
473 newExpiry := time.Now().Add(time.Hour)
474 if err := ta.Accessor.UpsertOCSP(want.Serial, want.AKI, "fake body revoked", newExpiry); err != nil {
475 t.Fatal(err)
476 }
477
478 rets, err = ta.Accessor.GetOCSP(want.Serial, want.AKI)
479 if err != nil {
480 t.Fatal(err)
481 }
482 if len(rets) != 1 {
483 t.Fatal("should return exactly one record")
484 }
485
486 got = rets[0]
487
488 want.Expiry = newExpiry
489 if want.Serial != got.Serial || got.Body != "fake body revoked" ||
490 !roughlySameTime(newExpiry, got.Expiry) {
491 t.Errorf("want OCSP %+v, got %+v", want, got)
492 }
493}
494
495func setupGoodCert(ta TestAccessor, t *testing.T, r certdb.OCSPRecord) {
496 certWant := certdb.CertificateRecord{

Callers 1

testEverythingFunction · 0.85

Calls 6

setupGoodCertFunction · 0.85
roughlySameTimeFunction · 0.85
TruncateMethod · 0.80
UpsertOCSPMethod · 0.65
GetOCSPMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…