Skip to content

Commit 232a5f8

Browse files
Roland Bracewell Shoemakercpu
authored andcommitted
Fix ineffectual assignments (letsencrypt#4052)
* in boulder-ra we connected to the publisher and created a publisher gRPC client twice for no apparent reason * in the SA we ignored errors from `getChallenges` in `GetAuthorizations` which could result in a nil challenge being returned in an authorization
1 parent 57f97eb commit 232a5f8

File tree

14 files changed

+27
-17
lines changed

14 files changed

+27
-17
lines changed

ca/ca_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func TestIssueCertificate(t *testing.T) {
356356

357357
issueReq := &caPB.IssueCertificateRequest{Csr: testCase.csr, RegistrationID: &arbitraryRegID}
358358

359-
certDER := []byte{}
359+
var certDER []byte
360360
if mode.issuePrecertificate {
361361
response, err := ca.IssuePrecertificate(ctx, issueReq)
362362

cmd/boulder-ra/main.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,10 @@ func main() {
150150
// with a plain caPB.NewCertificateAuthorityClient.
151151
cac := bgrpc.NewCertificateAuthorityClient(caPB.NewCertificateAuthorityClient(caConn), nil)
152152

153-
raConn, err := bgrpc.ClientSetup(c.RA.PublisherService, tlsConfig, clientMetrics, clk)
154-
cmd.FailOnError(err, "Failed to load credentials and create gRPC connection to Publisher")
155-
pubc := bgrpc.NewPublisherClientWrapper(pubPB.NewPublisherClient(raConn))
156-
157153
var ctp *ctpolicy.CTPolicy
158154
conn, err := bgrpc.ClientSetup(c.RA.PublisherService, tlsConfig, clientMetrics, clk)
159155
cmd.FailOnError(err, "Failed to load credentials and create gRPC connection to Publisher")
160-
pubc = bgrpc.NewPublisherClientWrapper(pubPB.NewPublisherClient(conn))
156+
pubc := bgrpc.NewPublisherClientWrapper(pubPB.NewPublisherClient(conn))
161157

162158
// Boulder's components assume that there will always be CT logs configured.
163159
// Issuing a certificate without SCTs embedded is a miss-issuance event in the

cmd/boulder-wfe2/main_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ func TestLoadCertificateChains(t *testing.T) {
3434
crlfPEM, _ := ioutil.TempFile("", "crlf.pem")
3535
crlfPEMBytes := []byte(strings.Replace(string(certBytesB), "\n", "\r\n", -1))
3636
err = ioutil.WriteFile(crlfPEM.Name(), crlfPEMBytes, 0640)
37+
test.AssertNotError(t, err, "ioutil.WriteFile failed")
3738

3839
// Make a .pem file that is test-ca.pem but with no trailing newline
3940
abruptPEM, _ := ioutil.TempFile("", "abrupt.pem")
4041
abruptPEMBytes := certBytesA[:len(certBytesA)-1]
4142
err = ioutil.WriteFile(abruptPEM.Name(), abruptPEMBytes, 0640)
43+
test.AssertNotError(t, err, "ioutil.WriteFile failed")
4244

4345
testCases := []struct {
4446
Name string

cmd/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ func TestLogInfo(t *testing.T) {
174174

175175
fc := clock.NewFake()
176176
ld.TemporalSet = &TemporalSet{}
177-
uri, key, err = ld.Info(fc.Now())
177+
_, _, err = ld.Info(fc.Now())
178178
test.AssertError(t, err, "Info should fail with a TemporalSet with no viable shards")
179179
ld.TemporalSet.Shards = []LogShard{{WindowStart: fc.Now().Add(time.Hour), WindowEnd: fc.Now().Add(time.Hour * 2)}}
180-
uri, key, err = ld.Info(fc.Now())
180+
_, _, err = ld.Info(fc.Now())
181181
test.AssertError(t, err, "Info should fail with a TemporalSet with no viable shards")
182182

183183
fc.Add(time.Hour * 4)

cmd/expiration-mailer/main_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ func addExpiringCerts(t *testing.T, ctx *testCtx) []core.Certificate {
377377
}
378378

379379
setupDBMap, err := sa.NewDbMap(vars.DBConnSAFullPerms, 0)
380+
test.AssertNotError(t, err, "sa.NewDbMap failed")
380381
err = setupDBMap.Insert(certA)
381382
test.AssertNotError(t, err, "Couldn't add certA")
382383
err = setupDBMap.Insert(certB)
@@ -604,6 +605,7 @@ func TestLifetimeOfACert(t *testing.T) {
604605
}
605606

606607
setupDBMap, err := sa.NewDbMap(vars.DBConnSAFullPerms, 0)
608+
test.AssertNotError(t, err, "sa.NewDbMap failed")
607609
err = setupDBMap.Insert(certA)
608610
test.AssertNotError(t, err, "unable to insert Certificate")
609611
_, err = setupDBMap.Exec("INSERT INTO certificateStatus (serial, status, notAfter, lastExpirationNagSent, ocspLastUpdated, revokedDate, revokedReason, LockCol, subscriberApproved) VALUES (?,?,?,?,?,?,?,?,?)", serial1String, string(core.OCSPStatusGood), rawCertA.NotAfter, time.Time{}, time.Time{}, time.Time{}, 0, 0, false)
@@ -704,6 +706,7 @@ func TestDontFindRevokedCert(t *testing.T) {
704706
}
705707

706708
setupDBMap, err := sa.NewDbMap(vars.DBConnSAFullPerms, 0)
709+
test.AssertNotError(t, err, "sa.NewDbMap failed")
707710
err = setupDBMap.Insert(certA)
708711
test.AssertNotError(t, err, "unable to insert Certificate")
709712
_, err = setupDBMap.Exec("INSERT INTO certificateStatus (serial,status, lastExpirationNagSent, ocspLastUpdated, revokedDate, revokedReason, LockCol, subscriberApproved) VALUES (?,?,?,?,?,?,?,?)", serial1String, string(core.OCSPStatusRevoked), time.Time{}, time.Time{}, time.Time{}, 0, 0, false)
@@ -765,6 +768,7 @@ func TestDedupOnRegistration(t *testing.T) {
765768
}
766769

767770
setupDBMap, err := sa.NewDbMap(vars.DBConnSAFullPerms, 0)
771+
test.AssertNotError(t, err, "sa.NewDbMap failed")
768772
err = setupDBMap.Insert(certA)
769773
test.AssertNotError(t, err, "Couldn't add certA")
770774
err = setupDBMap.Insert(certB)

ra/ra_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ func TestPerformValidationExpired(t *testing.T) {
932932
test.AssertNotError(t, err, "AuthzToPB failed")
933933

934934
challIndex := int64(ResponseIndex)
935-
authzPB, err = ra.PerformValidation(ctx, &rapb.PerformValidationRequest{
935+
_, err = ra.PerformValidation(ctx, &rapb.PerformValidationRequest{
936936
Authz: authzPB,
937937
ChallengeIndex: &challIndex,
938938
})

sa/model_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ func TestV2AuthzModel(t *testing.T) {
8686
},
8787
}
8888

89-
model, err := authzPBToModel(authzPB)
89+
_, err := authzPBToModel(authzPB)
9090
test.AssertError(t, err, "authzPBToModel didn't fail when V2 wasn't set")
9191

9292
v2 := true
9393
authzPB.V2 = &v2
94-
model, err = authzPBToModel(authzPB)
94+
model, err := authzPBToModel(authzPB)
9595
test.AssertNotError(t, err, "authzPBToModel failed")
9696

9797
authzPBOut, err := modelToAuthzPB(model)

sa/sa.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,9 @@ func (ssa *SQLStorageAuthority) GetAuthorizations(
20632063
// Fetch each of the authorizations' associated challenges
20642064
for _, authz := range authzMap {
20652065
authz.Challenges, err = ssa.getChallenges(ssa.dbMap.WithContext(ctx), authz.ID)
2066+
if err != nil {
2067+
return nil, err
2068+
}
20662069
}
20672070
return authzMapToPB(authzMap)
20682071
}

sa/sa_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ func TestCountCertificatesByNames(t *testing.T) {
592592

593593
// Time range including now should find the cert
594594
counts, err = sa.CountCertificatesByNames(ctx, []string{"example.com"}, yesterday, now)
595+
test.AssertNotError(t, err, "sa.CountCertificatesByName failed")
595596
test.AssertEquals(t, len(counts), 1)
596597
test.AssertEquals(t, *counts[0].Name, "example.com")
597598
test.AssertEquals(t, *counts[0].Count, int64(1))
@@ -664,6 +665,7 @@ func TestMarkCertificateRevoked(t *testing.T) {
664665
const ocspResponse = "this is a fake OCSP response"
665666

666667
certificateStatusObj, err := sa.GetCertificateStatus(ctx, serial)
668+
test.AssertNotError(t, err, "sa.GetCertificateStatus failed")
667669
test.AssertEquals(t, certificateStatusObj.Status, core.OCSPStatusGood)
668670

669671
fc.Add(1 * time.Hour)
@@ -2028,6 +2030,7 @@ func TestStatusForOrder(t *testing.T) {
20282030

20292031
// Create a valid authz
20302032
validAuthz, err := sa.NewPendingAuthorization(ctx, newAuthz)
2033+
test.AssertNotError(t, err, "sa.NewPendingAuthorization failed")
20312034
validAuthz.Status = core.StatusValid
20322035
validAuthz.Identifier.Value = "valid.your.order.is.up"
20332036
err = sa.FinalizeAuthorization(ctx, validAuthz)

test/load-generator/boulder-calls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ func revokeCertificate(s *State, ctx *context) error {
991991
resp, err = s.post(fmt.Sprintf("%s%s", s.apiBase, revokeCertPath), requestPayload, ctx.ns)
992992
finished := time.Now()
993993
state := "good"
994-
s.callLatency.Add("POST /acme/revoke-cert", started, finished, state)
994+
defer func() { s.callLatency.Add("POST /acme/revoke-cert", started, finished, state) }()
995995
if err != nil {
996996
state = "error"
997997
return err

0 commit comments

Comments
 (0)