From c255274572e6912695d741d44b0109e63d2adede Mon Sep 17 00:00:00 2001 From: max furman Date: Sat, 1 Feb 2020 17:35:41 -0800 Subject: [PATCH] Should be returning status code 400 for ACME Account Not Found. Issue #173 --- acme/api/account.go | 2 +- acme/api/account_test.go | 10 +++++----- acme/api/handler_test.go | 12 ++++++------ acme/api/middleware_test.go | 2 +- acme/api/order_test.go | 12 ++++++------ acme/errors.go | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/acme/api/account.go b/acme/api/account.go index fb43d4f9..bb6c92d6 100644 --- a/acme/api/account.go +++ b/acme/api/account.go @@ -96,7 +96,7 @@ func (h *Handler) NewAccount(w http.ResponseWriter, r *http.Request) { acc, err := accountFromContext(r) if err != nil { acmeErr, ok := err.(*acme.Error) - if !ok || acmeErr.Status != http.StatusNotFound { + if !ok || acmeErr.Status != http.StatusBadRequest { // Something went wrong ... api.WriteError(w, err) return diff --git a/acme/api/account_test.go b/acme/api/account_test.go index 193088f2..a3ebf55c 100644 --- a/acme/api/account_test.go +++ b/acme/api/account_test.go @@ -202,7 +202,7 @@ func TestHandlerGetOrdersByAccount(t *testing.T) { return test{ auth: &mockAcmeAuthority{}, ctx: context.WithValue(context.Background(), provisionerContextKey, prov), - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, @@ -212,7 +212,7 @@ func TestHandlerGetOrdersByAccount(t *testing.T) { return test{ auth: &mockAcmeAuthority{}, ctx: ctx, - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, @@ -378,7 +378,7 @@ func TestHandlerNewAccount(t *testing.T) { ctx = context.WithValue(ctx, payloadContextKey, &payloadInfo{value: b}) return test{ ctx: ctx, - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, @@ -569,7 +569,7 @@ func TestHandlerGetUpdateAccount(t *testing.T) { "fail/no-account": func(t *testing.T) test { return test{ ctx: context.WithValue(context.Background(), provisionerContextKey, prov), - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, @@ -578,7 +578,7 @@ func TestHandlerGetUpdateAccount(t *testing.T) { ctx = context.WithValue(ctx, accContextKey, nil) return test{ ctx: ctx, - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, diff --git a/acme/api/handler_test.go b/acme/api/handler_test.go index 3757882f..ebafbbb8 100644 --- a/acme/api/handler_test.go +++ b/acme/api/handler_test.go @@ -372,7 +372,7 @@ func TestHandlerGetAuthz(t *testing.T) { return test{ auth: &mockAcmeAuthority{}, ctx: context.WithValue(context.Background(), provisionerContextKey, prov), - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, @@ -382,7 +382,7 @@ func TestHandlerGetAuthz(t *testing.T) { return test{ auth: &mockAcmeAuthority{}, ctx: ctx, - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, @@ -504,7 +504,7 @@ func TestHandlerGetCertificate(t *testing.T) { return test{ auth: &mockAcmeAuthority{}, ctx: context.WithValue(context.Background(), provisionerContextKey, prov), - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, @@ -513,7 +513,7 @@ func TestHandlerGetCertificate(t *testing.T) { return test{ auth: &mockAcmeAuthority{}, ctx: ctx, - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, @@ -623,7 +623,7 @@ func TestHandlerGetChallenge(t *testing.T) { "fail/no-account": func(t *testing.T) test { return test{ ctx: context.WithValue(context.Background(), provisionerContextKey, prov), - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, @@ -632,7 +632,7 @@ func TestHandlerGetChallenge(t *testing.T) { ctx = context.WithValue(ctx, accContextKey, nil) return test{ ctx: ctx, - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, diff --git a/acme/api/middleware_test.go b/acme/api/middleware_test.go index f8aa322c..e617e5bd 100644 --- a/acme/api/middleware_test.go +++ b/acme/api/middleware_test.go @@ -842,7 +842,7 @@ func TestHandlerLookupJWK(t *testing.T) { }, }, ctx: ctx, - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, diff --git a/acme/api/order_test.go b/acme/api/order_test.go index 68bd4f46..0931d832 100644 --- a/acme/api/order_test.go +++ b/acme/api/order_test.go @@ -205,7 +205,7 @@ func TestHandlerGetOrder(t *testing.T) { return test{ auth: &mockAcmeAuthority{}, ctx: context.WithValue(context.Background(), provisionerContextKey, prov), - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, @@ -215,7 +215,7 @@ func TestHandlerGetOrder(t *testing.T) { return test{ auth: &mockAcmeAuthority{}, ctx: ctx, - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, @@ -343,7 +343,7 @@ func TestHandlerNewOrder(t *testing.T) { "fail/no-account": func(t *testing.T) test { return test{ ctx: context.WithValue(context.Background(), provisionerContextKey, prov), - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, @@ -352,7 +352,7 @@ func TestHandlerNewOrder(t *testing.T) { ctx = context.WithValue(ctx, accContextKey, nil) return test{ ctx: ctx, - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, @@ -597,7 +597,7 @@ func TestHandlerFinalizeOrder(t *testing.T) { return test{ auth: &mockAcmeAuthority{}, ctx: context.WithValue(context.Background(), provisionerContextKey, prov), - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, @@ -607,7 +607,7 @@ func TestHandlerFinalizeOrder(t *testing.T) { return test{ auth: &mockAcmeAuthority{}, ctx: ctx, - statusCode: 404, + statusCode: 400, problem: acme.AccountDoesNotExistErr(nil), } }, diff --git a/acme/errors.go b/acme/errors.go index 9facac5f..dd6f4aff 100644 --- a/acme/errors.go +++ b/acme/errors.go @@ -9,7 +9,7 @@ func AccountDoesNotExistErr(err error) *Error { return &Error{ Type: accountDoesNotExistErr, Detail: "Account does not exist", - Status: 404, + Status: 400, Err: err, } }