forked from adamlaska/boulder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test.go
More file actions
169 lines (143 loc) · 4.43 KB
/
client_test.go
File metadata and controls
169 lines (143 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package notmain
import (
"context"
"fmt"
"math/big"
"testing"
"time"
"github.com/go-redis/redis/v8"
"github.com/jmhodges/clock"
capb "github.com/letsencrypt/boulder/ca/proto"
"github.com/letsencrypt/boulder/cmd"
"github.com/letsencrypt/boulder/core"
blog "github.com/letsencrypt/boulder/log"
"github.com/letsencrypt/boulder/metrics"
"github.com/letsencrypt/boulder/rocsp"
rocsp_config "github.com/letsencrypt/boulder/rocsp/config"
"github.com/letsencrypt/boulder/sa"
"github.com/letsencrypt/boulder/test"
"github.com/letsencrypt/boulder/test/vars"
"golang.org/x/crypto/ocsp"
"google.golang.org/grpc"
)
func makeClient() (*rocsp.WritingClient, clock.Clock) {
CACertFile := "../../test/redis-tls/minica.pem"
CertFile := "../../test/redis-tls/boulder/cert.pem"
KeyFile := "../../test/redis-tls/boulder/key.pem"
tlsConfig := cmd.TLSConfig{
CACertFile: &CACertFile,
CertFile: &CertFile,
KeyFile: &KeyFile,
}
tlsConfig2, err := tlsConfig.Load()
if err != nil {
panic(err)
}
rdb := redis.NewClusterClient(&redis.ClusterOptions{
Addrs: []string{"10.33.33.2:4218"},
Username: "unittest-rw",
Password: "824968fa490f4ecec1e52d5e34916bdb60d45f8d",
TLSConfig: tlsConfig2,
})
clk := clock.NewFake()
return rocsp.NewWritingClient(rdb, 500*time.Millisecond, clk, metrics.NoopRegisterer), clk
}
func TestGetStartingID(t *testing.T) {
clk := clock.NewFake()
dbMap, err := sa.NewDbMap(vars.DBConnSAFullPerms, sa.DbSettings{})
test.AssertNotError(t, err, "failed setting up db client")
defer test.ResetSATestDatabase(t)()
sa.SetSQLDebug(dbMap, blog.Get())
cs := core.CertificateStatus{
Serial: "1337",
NotAfter: clk.Now().Add(12 * time.Hour),
}
err = dbMap.Insert(&cs)
test.AssertNotError(t, err, "inserting certificate status")
firstID := cs.ID
cs = core.CertificateStatus{
Serial: "1338",
NotAfter: clk.Now().Add(36 * time.Hour),
}
err = dbMap.Insert(&cs)
test.AssertNotError(t, err, "inserting certificate status")
secondID := cs.ID
t.Logf("first ID %d, second ID %d", firstID, secondID)
clk.Sleep(48 * time.Hour)
startingID, err := getStartingID(context.Background(), clk, dbMap.Db)
test.AssertNotError(t, err, "getting starting ID")
test.AssertEquals(t, startingID, secondID)
}
func TestStoreResponse(t *testing.T) {
redisClient, clk := makeClient()
issuer, err := core.LoadCert("../../test/hierarchy/int-e1.cert.pem")
test.AssertNotError(t, err, "loading int-e1")
issuerKey, err := test.LoadSigner("../../test/hierarchy/int-e1.key.pem")
test.AssertNotError(t, err, "loading int-e1 key ")
response, err := ocsp.CreateResponse(issuer, issuer, ocsp.Response{
SerialNumber: big.NewInt(1337),
Status: 0,
ThisUpdate: clk.Now(),
NextUpdate: clk.Now().Add(time.Hour),
}, issuerKey)
test.AssertNotError(t, err, "creating OCSP response")
issuers, err := rocsp_config.LoadIssuers(map[string]int{
"../../test/hierarchy/int-e1.cert.pem": 23,
})
if err != nil {
t.Fatal(err)
}
cl := client{
issuers: issuers,
redis: redisClient,
db: nil,
ocspGenerator: nil,
clk: clk,
logger: blog.NewMock(),
}
ttl := time.Hour
err = cl.storeResponse(context.Background(), response, &ttl)
test.AssertNotError(t, err, "storing response")
}
type mockOCSPGenerator struct{}
func (mog mockOCSPGenerator) GenerateOCSP(ctx context.Context, in *capb.GenerateOCSPRequest, opts ...grpc.CallOption) (*capb.OCSPResponse, error) {
return &capb.OCSPResponse{
Response: []byte("phthpbt"),
}, nil
}
func TestLoadFromDB(t *testing.T) {
redisClient, clk := makeClient()
dbMap, err := sa.NewDbMap(vars.DBConnSA, sa.DbSettings{})
if err != nil {
t.Fatalf("Failed to create dbMap: %s", err)
}
defer test.ResetSATestDatabase(t)
for i := 0; i < 100; i++ {
err = dbMap.Insert(&core.CertificateStatus{
Serial: fmt.Sprintf("%036x", i),
OCSPResponse: []byte("phthpbt"),
NotAfter: clk.Now().Add(200 * time.Hour),
OCSPLastUpdated: clk.Now(),
})
if err != nil {
t.Fatalf("Failed to insert certificateStatus: %s", err)
}
}
rocspToolClient := client{
issuers: nil,
redis: redisClient,
db: dbMap.Db,
ocspGenerator: mockOCSPGenerator{},
clk: clk,
scanBatchSize: 10,
logger: blog.NewMock(),
}
speed := ProcessingSpeed{
RowsPerSecond: 10000,
ParallelSigns: 100,
}
err = rocspToolClient.loadFromDB(context.Background(), speed, 0)
if err != nil {
t.Fatalf("loading from DB: %s", err)
}
}