...
1 package live
2
3 import (
4 "context"
5 "errors"
6 "fmt"
7 "math/big"
8 "testing"
9
10 capb "github.com/letsencrypt/boulder/ca/proto"
11 "github.com/letsencrypt/boulder/core"
12 berrors "github.com/letsencrypt/boulder/errors"
13 "github.com/letsencrypt/boulder/ocsp/responder"
14 ocsp_test "github.com/letsencrypt/boulder/ocsp/test"
15 rapb "github.com/letsencrypt/boulder/ra/proto"
16 "github.com/letsencrypt/boulder/test"
17 "golang.org/x/crypto/ocsp"
18 "google.golang.org/grpc"
19 )
20
21
22
23 type mockOCSPGenerator struct {
24 resp []byte
25 }
26
27 func (m mockOCSPGenerator) GenerateOCSP(ctx context.Context, in *rapb.GenerateOCSPRequest, opts ...grpc.CallOption) (*capb.OCSPResponse, error) {
28 expectedSerial := core.SerialToString(big.NewInt(1))
29 if in.Serial != expectedSerial {
30 return nil, fmt.Errorf("expected serial %s, got %s", expectedSerial, in.Serial)
31 }
32
33 return &capb.OCSPResponse{Response: m.resp}, nil
34 }
35
36
37 type notFoundOCSPGenerator struct{}
38
39 func (n notFoundOCSPGenerator) GenerateOCSP(ctx context.Context, in *rapb.GenerateOCSPRequest, opts ...grpc.CallOption) (*capb.OCSPResponse, error) {
40 return nil, berrors.NotFoundError("not found")
41 }
42
43 func TestLiveResponse(t *testing.T) {
44 eeSerial := big.NewInt(1)
45 fakeResp, _, _ := ocsp_test.FakeResponse(ocsp.Response{
46 SerialNumber: eeSerial,
47 })
48 source := New(mockOCSPGenerator{fakeResp.Raw}, 1, 0)
49 resp, err := source.Response(context.Background(), &ocsp.Request{
50 SerialNumber: eeSerial,
51 })
52 test.AssertNotError(t, err, "getting response")
53 test.AssertByteEquals(t, resp.Raw, fakeResp.Raw)
54 expectedSerial := "000000000000000000000000000000000001"
55 if core.SerialToString(resp.SerialNumber) != expectedSerial {
56 t.Errorf("expected serial %s, got %s", expectedSerial, resp.SerialNumber)
57 }
58 }
59
60 func TestNotFound(t *testing.T) {
61 eeSerial := big.NewInt(1)
62 source := New(notFoundOCSPGenerator{}, 1, 0)
63 _, err := source.Response(context.Background(), &ocsp.Request{
64 SerialNumber: eeSerial,
65 })
66 if !errors.Is(err, responder.ErrNotFound) {
67 t.Errorf("expected responder.ErrNotFound, got %#v", err)
68 }
69 }
70
View as plain text