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

Function TestOCSPRefreshMain

cli/ocsprefresh/ocsprefresh_test.go:19–109  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17var dbAccessor certdb.Accessor
18
19func TestOCSPRefreshMain(t *testing.T) {
20 db := testdb.SQLiteDB("../../certdb/testdb/certstore_development.db")
21
22 certPEM, err := os.ReadFile("../../ocsp/testdata/cert.pem")
23 if err != nil {
24 t.Fatal(err)
25 }
26 cert, err := helpers.ParseCertificatePEM(certPEM)
27 if err != nil {
28 t.Fatal(err)
29 }
30
31 expirationTime := time.Now().AddDate(1, 0, 0)
32 certRecord := certdb.CertificateRecord{
33 Serial: cert.SerialNumber.String(),
34 AKI: hex.EncodeToString(cert.AuthorityKeyId),
35 Expiry: expirationTime,
36 PEM: string(certPEM),
37 Status: "good",
38 }
39
40 dbAccessor = sql.NewAccessor(db)
41 err = dbAccessor.InsertCertificate(certRecord)
42 if err != nil {
43 t.Fatal(err)
44 }
45
46 err = ocsprefreshMain([]string{}, cli.Config{
47 CAFile: "../../ocsp/testdata/ca.pem",
48 ResponderFile: "../../ocsp/testdata/server.crt",
49 ResponderKeyFile: "../../ocsp/testdata/server.key",
50 DBConfigFile: "../testdata/db-config.json",
51 Interval: helpers.OneDay,
52 })
53
54 if err != nil {
55 t.Fatal(err)
56 }
57
58 records, err := dbAccessor.GetUnexpiredOCSPs()
59 if err != nil {
60 t.Fatal("Failed to get OCSP responses")
61 }
62
63 if len(records) != 1 {
64 t.Fatal("Expected one OCSP response")
65 }
66
67 var resp *ocsp.Response
68 resp, err = ocsp.ParseResponse([]byte(records[0].Body), nil)
69 if err != nil {
70 t.Fatal("Failed to parse OCSP response")
71 }
72 if resp.Status != ocsp.Good {
73 t.Fatal("Expected cert status 'good'")
74 }
75
76 err = dbAccessor.RevokeCertificate(certRecord.Serial, certRecord.AKI, ocsp.KeyCompromise)

Callers

nothing calls this directly

Calls 8

SQLiteDBFunction · 0.92
ParseCertificatePEMFunction · 0.92
NewAccessorFunction · 0.92
ocsprefreshMainFunction · 0.85
InsertCertificateMethod · 0.65
GetUnexpiredOCSPsMethod · 0.65
RevokeCertificateMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…