X Tutup
Skip to content

Commit 3c4873b

Browse files
lucasamorimcajsha
authored andcommitted
Returns an Internal Server Error on grpc/db timeouts (letsencrypt#2624)
1 parent 9c1e8e6 commit 3c4873b

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

mocks/mocks.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mocks
22

33
import (
4+
"database/sql"
45
"encoding/json"
56
"encoding/pem"
67
"errors"
@@ -202,9 +203,11 @@ func (sa *StorageAuthority) GetAuthorization(_ context.Context, id string) (core
202203
authz.Expires = &exp
203204
authz.Challenges[0].URI = "http://localhost:4300/acme/challenge/expired/23"
204205
return authz, nil
206+
} else if id == "error_result" {
207+
return core.Authorization{}, fmt.Errorf("Unspecified database error")
205208
}
206209

207-
return core.Authorization{}, fmt.Errorf("authz not found")
210+
return core.Authorization{}, sql.ErrNoRows
208211
}
209212

210213
// RevokeAuthorizationsByDomain is a mock

sa/sa.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,7 @@ func (ssa *SQLStorageAuthority) GetAuthorization(ctx context.Context, id string)
172172
if err == sql.ErrNoRows {
173173
var fa authzModel
174174
err = tx.SelectOne(&fa, fmt.Sprintf("SELECT %s FROM authz WHERE id = ?", authzFields), id)
175-
if err == sql.ErrNoRows {
176-
err = fmt.Errorf("No pendingAuthorization or authz with ID %s", id)
177-
err = Rollback(tx, err)
178-
return
179-
}
180175
if err != nil {
181-
err = Rollback(tx, err)
182176
return
183177
}
184178
authz = fa.Authorization

wfe/wfe.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package wfe
33
import (
44
"bytes"
55
"crypto/x509"
6+
"database/sql"
67
"encoding/hex"
78
"encoding/json"
89
"errors"
@@ -986,8 +987,11 @@ func (wfe *WebFrontEndImpl) Challenge(
986987

987988
authz, err := wfe.SA.GetAuthorization(ctx, authorizationID)
988989
if err != nil {
989-
// TODO(#1198): handle db errors etc
990-
notFound()
990+
if err == sql.ErrNoRows {
991+
notFound()
992+
} else {
993+
wfe.sendError(response, logEvent, probs.ServerInternal("Problem getting authorization"), err)
994+
}
991995
return
992996
}
993997

wfe/wfe_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,27 @@ func TestChallenge(t *testing.T) {
942942
test.AssertEquals(t, responseWriter.Code, http.StatusNotFound)
943943
assertJSONEquals(t, responseWriter.Body.String(),
944944
`{"type":"urn:acme:error:malformed","detail":"Expired authorization","status":404}`)
945+
946+
// Challenge Not found
947+
challengeURL = ""
948+
responseWriter = httptest.NewRecorder()
949+
wfe.Challenge(ctx, newRequestEvent(), responseWriter,
950+
makePostRequestWithPath(challengeURL,
951+
signRequest(t, `{"resource":"challenge"}`, wfe.nonceService)))
952+
test.AssertEquals(t, responseWriter.Code, http.StatusNotFound)
953+
assertJSONEquals(t, responseWriter.Body.String(),
954+
`{"type":"urn:acme:error:malformed","detail":"No such challenge","status":404}`)
955+
956+
// Unspecified database error
957+
errorURL := "error_result/24"
958+
responseWriter = httptest.NewRecorder()
959+
wfe.Challenge(ctx, newRequestEvent(), responseWriter,
960+
makePostRequestWithPath(errorURL,
961+
signRequest(t, `{"resource":"challenge"}`, wfe.nonceService)))
962+
test.AssertEquals(t, responseWriter.Code, http.StatusInternalServerError)
963+
assertJSONEquals(t, responseWriter.Body.String(),
964+
`{"type":"urn:acme:error:serverInternal","detail":"Problem getting authorization","status":500}`)
965+
945966
}
946967

947968
func TestBadNonce(t *testing.T) {

0 commit comments

Comments
 (0)
X Tutup