@@ -2974,113 +2974,6 @@ func TestSerialsForIncident(t *testing.T) {
29742974 test .AssertNotError (t , err , "Error getting serials for incident" )
29752975}
29762976
2977- func TestGetRevokedCerts (t * testing.T ) {
2978- sa , _ , cleanUp := initSA (t )
2979- defer cleanUp ()
2980-
2981- // Add a cert to the DB to test with. We use AddPrecertificate because it sets
2982- // up the certificateStatus row we need. This particular cert has a notAfter
2983- // date of Mar 6 2023, and we lie about its IssuerNameID to make things easy.
2984- reg := createWorkingRegistration (t , sa )
2985- eeCert , err := core .LoadCert ("../test/hierarchy/ee-e1.cert.pem" )
2986- test .AssertNotError (t , err , "failed to load test cert" )
2987- _ , err = sa .AddSerial (ctx , & sapb.AddSerialRequest {
2988- RegID : reg .Id ,
2989- Serial : core .SerialToString (eeCert .SerialNumber ),
2990- Created : timestamppb .New (eeCert .NotBefore ),
2991- Expires : timestamppb .New (eeCert .NotAfter ),
2992- })
2993- test .AssertNotError (t , err , "failed to add test serial" )
2994- _ , err = sa .AddPrecertificate (ctx , & sapb.AddCertificateRequest {
2995- Der : eeCert .Raw ,
2996- RegID : reg .Id ,
2997- Issued : timestamppb .New (eeCert .NotBefore ),
2998- IssuerNameID : 1 ,
2999- })
3000- test .AssertNotError (t , err , "failed to add test cert" )
3001-
3002- // Check that it worked.
3003- status , err := sa .GetCertificateStatus (
3004- ctx , & sapb.Serial {Serial : core .SerialToString (eeCert .SerialNumber )})
3005- test .AssertNotError (t , err , "GetCertificateStatus failed" )
3006- test .AssertEquals (t , core .OCSPStatus (status .Status ), core .OCSPStatusGood )
3007-
3008- // Here's a little helper func we'll use to call GetRevokedCerts and count
3009- // how many results it returned.
3010- countRevokedCerts := func (req * sapb.GetRevokedCertsRequest ) (int , error ) {
3011- stream := make (chan * corepb.CRLEntry )
3012- mockServerStream := & fakeServerStream [corepb.CRLEntry ]{output : stream }
3013- var err error
3014- go func () {
3015- err = sa .GetRevokedCerts (req , mockServerStream )
3016- close (stream )
3017- }()
3018- entriesReceived := 0
3019- for range stream {
3020- entriesReceived ++
3021- }
3022- return entriesReceived , err
3023- }
3024-
3025- // The basic request covers a time range that should include this certificate.
3026- basicRequest := & sapb.GetRevokedCertsRequest {
3027- IssuerNameID : 1 ,
3028- ExpiresAfter : mustTimestamp ("2023-03-01 00:00" ),
3029- ExpiresBefore : mustTimestamp ("2023-04-01 00:00" ),
3030- RevokedBefore : mustTimestamp ("2023-04-01 00:00" ),
3031- }
3032- count , err := countRevokedCerts (basicRequest )
3033- test .AssertNotError (t , err , "zero rows shouldn't result in error" )
3034- test .AssertEquals (t , count , 0 )
3035-
3036- // Revoke the certificate.
3037- _ , err = sa .RevokeCertificate (context .Background (), & sapb.RevokeCertificateRequest {
3038- IssuerID : 1 ,
3039- Serial : core .SerialToString (eeCert .SerialNumber ),
3040- Date : mustTimestamp ("2023-01-01 00:00" ),
3041- Reason : 1 ,
3042- Response : []byte {1 , 2 , 3 },
3043- ShardIdx : 1 ,
3044- })
3045- test .AssertNotError (t , err , "failed to revoke test cert" )
3046-
3047- // Asking for revoked certs now should return one result.
3048- count , err = countRevokedCerts (basicRequest )
3049- test .AssertNotError (t , err , "normal usage shouldn't result in error" )
3050- test .AssertEquals (t , count , 1 )
3051-
3052- // Asking for revoked certs with an old RevokedBefore should return no results.
3053- count , err = countRevokedCerts (& sapb.GetRevokedCertsRequest {
3054- IssuerNameID : 1 ,
3055- ExpiresAfter : basicRequest .ExpiresAfter ,
3056- ExpiresBefore : basicRequest .ExpiresBefore ,
3057- RevokedBefore : mustTimestamp ("2020-03-01 00:00" ),
3058- })
3059- test .AssertNotError (t , err , "zero rows shouldn't result in error" )
3060- test .AssertEquals (t , count , 0 )
3061-
3062- // Asking for revoked certs in a time period that does not cover this cert's
3063- // notAfter timestamp should return zero results.
3064- count , err = countRevokedCerts (& sapb.GetRevokedCertsRequest {
3065- IssuerNameID : 1 ,
3066- ExpiresAfter : mustTimestamp ("2022-03-01 00:00" ),
3067- ExpiresBefore : mustTimestamp ("2022-04-01 00:00" ),
3068- RevokedBefore : mustTimestamp ("2023-04-01 00:00" ),
3069- })
3070- test .AssertNotError (t , err , "zero rows shouldn't result in error" )
3071- test .AssertEquals (t , count , 0 )
3072-
3073- // Asking for revoked certs from a different issuer should return zero results.
3074- count , err = countRevokedCerts (& sapb.GetRevokedCertsRequest {
3075- IssuerNameID : 5678 ,
3076- ExpiresAfter : basicRequest .ExpiresAfter ,
3077- ExpiresBefore : basicRequest .ExpiresBefore ,
3078- RevokedBefore : basicRequest .RevokedBefore ,
3079- })
3080- test .AssertNotError (t , err , "zero rows shouldn't result in error" )
3081- test .AssertEquals (t , count , 0 )
3082- }
3083-
30842977func TestGetRevokedCertsByShard (t * testing.T ) {
30852978 sa , _ , cleanUp := initSA (t )
30862979 defer cleanUp ()
0 commit comments