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

Function testInsertCertificateAndGetUnexpiredCertificate

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

Source from the content-addressed store, hash-verified

115}
116
117func testInsertCertificateAndGetUnexpiredCertificate(ta TestAccessor, t *testing.T) {
118 ta.Truncate()
119
120 expiry := time.Now().Add(time.Minute)
121 want := certdb.CertificateRecord{
122 PEM: "fake cert data",
123 Serial: "fake serial 2",
124 AKI: fakeAKI,
125 Status: "good",
126 Reason: 0,
127 Expiry: expiry,
128 CALabel: "foo",
129 }
130
131 if err := ta.Accessor.InsertCertificate(want); err != nil {
132 t.Fatal(err)
133 }
134
135 rets, err := ta.Accessor.GetCertificate(want.Serial, want.AKI)
136 if err != nil {
137 t.Fatal(err)
138 }
139
140 if len(rets) != 1 {
141 t.Fatal("should return exactly one record")
142 }
143
144 got := rets[0]
145
146 // reflection comparison with zero time objects are not stable as it seems
147 if want.Serial != got.Serial || want.Status != got.Status ||
148 want.AKI != got.AKI || !got.RevokedAt.IsZero() ||
149 want.PEM != got.PEM || !roughlySameTime(got.Expiry, expiry) {
150 t.Errorf("want Certificate %+v, got %+v", want, got)
151 }
152
153 unexpired, err := ta.Accessor.GetUnexpiredCertificates()
154
155 if err != nil {
156 t.Fatal(err)
157 }
158
159 if len(unexpired) != 1 {
160 t.Error("Should have 1 unexpired certificate record:", len(unexpired))
161 }
162
163 unexpiredFiltered, err := ta.Accessor.GetUnexpiredCertificatesByLabel([]string{"foo"})
164 if err != nil {
165 t.Fatal(err)
166 }
167 if l := len(unexpiredFiltered); l != 1 {
168 t.Error("Should have 1 unexpiredFiltered certificate record:", l)
169 }
170 unexpiredFiltered, err = ta.Accessor.GetUnexpiredCertificatesByLabel([]string{"bar"})
171 if err != nil {
172 t.Fatal(err)
173 }
174 if l := len(unexpiredFiltered); l != 0 {

Callers 1

testEverythingFunction · 0.85

Calls 8

roughlySameTimeFunction · 0.85
TruncateMethod · 0.80
AddMethod · 0.65
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…