Commit c0eb36c1 authored by Eric Chiang's avatar Eric Chiang Committed by GitHub

Merge pull request #494 from ericchiang/return-409-if-resource-is-already-created

return 409 status code on duplicate email errors
parents a95a2bfa 47ce264f
...@@ -81,7 +81,7 @@ var ( ...@@ -81,7 +81,7 @@ var (
client.ErrorInvalidClientSecret: errorMaker("bad_request", "Secret must be a base64 encoded string", http.StatusBadRequest), client.ErrorInvalidClientSecret: errorMaker("bad_request", "Secret must be a base64 encoded string", http.StatusBadRequest),
user.ErrorNotFound: errorMaker("resource_not_found", "Resource could not be found.", http.StatusNotFound), user.ErrorNotFound: errorMaker("resource_not_found", "Resource could not be found.", http.StatusNotFound),
user.ErrorDuplicateEmail: errorMaker("bad_request", "Email already in use.", http.StatusBadRequest), user.ErrorDuplicateEmail: errorMaker("bad_request", "Email already in use.", http.StatusConflict),
user.ErrorInvalidEmail: errorMaker("bad_request", "invalid email.", http.StatusBadRequest), user.ErrorInvalidEmail: errorMaker("bad_request", "invalid email.", http.StatusBadRequest),
adminschema.ErrorInvalidRedirectURI: errorMaker("bad_request", "invalid redirectURI.", http.StatusBadRequest), adminschema.ErrorInvalidRedirectURI: errorMaker("bad_request", "invalid redirectURI.", http.StatusBadRequest),
......
...@@ -201,7 +201,7 @@ func TestCreateAdmin(t *testing.T) { ...@@ -201,7 +201,7 @@ func TestCreateAdmin(t *testing.T) {
Email: "Email-1@example.com", Email: "Email-1@example.com",
Password: "foopass", Password: "foopass",
}, },
errCode: http.StatusBadRequest, errCode: http.StatusConflict,
}, },
{ {
// missing Email // missing Email
......
...@@ -409,6 +409,24 @@ func TestCreateUser(t *testing.T) { ...@@ -409,6 +409,24 @@ func TestCreateUser(t *testing.T) {
}, },
}, },
}, },
{
// Duplicate email
req: schema.UserCreateRequest{
User: &schema.User{
Email: "Email-1@example.com",
DisplayName: "New User",
EmailVerified: true,
Admin: false,
CreatedAt: clock.Now().Format(time.RFC3339),
},
RedirectURL: testRedirectURL.String(),
},
token: userGoodToken,
wantCode: http.StatusConflict,
},
{ {
req: schema.UserCreateRequest{ req: schema.UserCreateRequest{
......
...@@ -31,7 +31,7 @@ var ( ...@@ -31,7 +31,7 @@ var (
ErrorInvalidClient = newError("invalid_client", "invalid email.", http.StatusBadRequest) ErrorInvalidClient = newError("invalid_client", "invalid email.", http.StatusBadRequest)
ErrorDuplicateEmail = newError("duplicate_email", "Email already in use.", http.StatusBadRequest) ErrorDuplicateEmail = newError("duplicate_email", "Email already in use.", http.StatusConflict)
ErrorResourceNotFound = newError("resource_not_found", "Resource could not be found.", http.StatusNotFound) ErrorResourceNotFound = newError("resource_not_found", "Resource could not be found.", http.StatusNotFound)
ErrorUnauthorized = newError("unauthorized", "Necessary credentials not provided.", http.StatusUnauthorized) ErrorUnauthorized = newError("unauthorized", "Necessary credentials not provided.", http.StatusUnauthorized)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment