@@ -52,6 +52,7 @@ func roughlySameTime(t1, t2 time.Time) bool {
5252func testEverything (ta TestAccessor , t * testing.T ) {
5353 testInsertCertificateAndGetCertificate (ta , t )
5454 testInsertCertificateAndGetUnexpiredCertificate (ta , t )
55+ testInsertCertificateAndGetUnexpiredCertificateNullCommonName (ta , t )
5556 testUpdateCertificateAndGetCertificate (ta , t )
5657 testInsertOCSPAndGetOCSP (ta , t )
5758 testInsertOCSPAndGetUnexpiredOCSP (ta , t )
@@ -153,6 +154,54 @@ func testInsertCertificateAndGetUnexpiredCertificate(ta TestAccessor, t *testing
153154 t .Error ("Should have 1 unexpired certificate record:" , len (unexpired ))
154155 }
155156}
157+ func testInsertCertificateAndGetUnexpiredCertificateNullCommonName (ta TestAccessor , t * testing.T ) {
158+ ta .Truncate ()
159+
160+ expiry := time .Now ().Add (time .Minute )
161+ want := certdb.CertificateRecord {
162+ PEM : "fake cert data" ,
163+ Serial : "fake serial 2" ,
164+ AKI : fakeAKI ,
165+ Status : "good" ,
166+ Reason : 0 ,
167+ Expiry : expiry ,
168+ }
169+
170+ if err := ta .Accessor .InsertCertificate (want ); err != nil {
171+ t .Fatal (err )
172+ }
173+
174+ // simulate situation where there are rows before migrate 002 has been run
175+ ta .DB .MustExec ("update certificates set common_name = NULL" )
176+
177+ rets , err := ta .Accessor .GetCertificate (want .Serial , want .AKI )
178+ if err != nil {
179+ t .Fatal (err )
180+ }
181+
182+ if len (rets ) != 1 {
183+ t .Fatal ("should return exactly one record" )
184+ }
185+
186+ got := rets [0 ]
187+
188+ // reflection comparison with zero time objects are not stable as it seems
189+ if want .Serial != got .Serial || want .Status != got .Status ||
190+ want .AKI != got .AKI || ! got .RevokedAt .IsZero () ||
191+ want .PEM != got .PEM || ! roughlySameTime (got .Expiry , expiry ) {
192+ t .Errorf ("want Certificate %+v, got %+v" , want , got )
193+ }
194+
195+ unexpired , err := ta .Accessor .GetUnexpiredCertificates ()
196+
197+ if err != nil {
198+ t .Fatal (err )
199+ }
200+
201+ if len (unexpired ) != 1 {
202+ t .Error ("Should have 1 unexpired certificate record:" , len (unexpired ))
203+ }
204+ }
156205
157206func testUpdateCertificateAndGetCertificate (ta TestAccessor , t * testing.T ) {
158207 ta .Truncate ()
0 commit comments