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

return 409 status code on duplicate email errors
This commit is contained in:
Eric Chiang 2016-06-28 14:14:05 -07:00 committed by GitHub
commit c0eb36c14b
4 changed files with 21 additions and 3 deletions

View file

@ -81,7 +81,7 @@ var (
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.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),
adminschema.ErrorInvalidRedirectURI: errorMaker("bad_request", "invalid redirectURI.", http.StatusBadRequest),

View file

@ -201,7 +201,7 @@ func TestCreateAdmin(t *testing.T) {
Email: "Email-1@example.com",
Password: "foopass",
},
errCode: http.StatusBadRequest,
errCode: http.StatusConflict,
},
{
// missing Email

View file

@ -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{

View file

@ -31,7 +31,7 @@ var (
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)
ErrorUnauthorized = newError("unauthorized", "Necessary credentials not provided.", http.StatusUnauthorized)