forked from letsencrypt/boulder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix new reg GetRegistrationByKey error check (letsencrypt#3895)
Fixes letsencrypt#3877.
- Loading branch information
Showing
2 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"crypto/x509" | ||
"encoding/json" | ||
"encoding/pem" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
|
@@ -2499,3 +2500,34 @@ func TestNewCertificateSCTError(t *testing.T) { | |
responseWriter.Body.String(), | ||
`{"type":"`+probs.V1ErrorNS+`serverInternal","detail":"Error creating new cert :: Unable to meet CA SCT embedding requirements","status":500}`) | ||
} | ||
|
||
type mockSAGetRegByKeyNotFoundAfterVerify struct { | ||
core.StorageGetter | ||
verified bool | ||
} | ||
|
||
func (sa *mockSAGetRegByKeyNotFoundAfterVerify) GetRegistrationByKey(ctx context.Context, jwk *jose.JSONWebKey) (core.Registration, error) { | ||
if !sa.verified { | ||
sa.verified = true | ||
return sa.StorageGetter.GetRegistrationByKey(ctx, jwk) | ||
} | ||
return core.Registration{}, errors.New("broke") | ||
} | ||
|
||
// If GetRegistrationByKey returns a non berrors.NotFound error NewRegistration should fail | ||
// out with an internal server error instead of continuing on and attempting to create a new | ||
// account. | ||
func TestNewRegistrationGetKeyBroken(t *testing.T) { | ||
wfe, fc := setupWFE(t) | ||
wfe.SA = &mockSAGetRegByKeyNotFoundAfterVerify{mocks.NewStorageAuthority(fc), false} | ||
payload := `{"resource":"new-reg","contact":["mailto:[email protected]"],"agreement":"` + agreementURL + `"}` | ||
responseWriter := httptest.NewRecorder() | ||
wfe.NewRegistration(ctx, newRequestEvent(), responseWriter, | ||
makePostRequest(signRequest(t, payload, wfe.nonceService))) | ||
var prob probs.ProblemDetails | ||
err := json.Unmarshal(responseWriter.Body.Bytes(), &prob) | ||
test.AssertNotError(t, err, "unmarshalling response") | ||
if prob.Type != probs.V1ErrorNS+probs.ServerInternalProblem { | ||
t.Errorf("Wrong type for returned problem: %#v", prob.Type) | ||
} | ||
} |