diff --git a/apis/record_crud.go b/apis/record_crud.go index ea8790f7..f2977e77 100644 --- a/apis/record_crud.go +++ b/apis/record_crud.go @@ -227,14 +227,14 @@ func (api *recordApi) create(c echo.Context) error { testErr := testForm.DrySubmit(func(txDao *daos.Dao) error { foundRecord, err := txDao.FindRecordById(collection.Id, testRecord.Id, createRuleFunc) if err != nil { - return err + return fmt.Errorf("DrySubmit create rule failure: %v", err) } hasFullManageAccess = hasAuthManageAccess(txDao, foundRecord, requestData) return nil }) if testErr != nil { - return NewBadRequestError("Failed to create record.", fmt.Errorf("DrySubmit error: %v", testErr)) + return NewBadRequestError("Failed to create record.", testErr) } } diff --git a/apis/record_crud_test.go b/apis/record_crud_test.go index 4e47b7a8..9b21baa6 100644 --- a/apis/record_crud_test.go +++ b/apis/record_crud_test.go @@ -818,6 +818,14 @@ func TestRecordCrudCreate(t *testing.T) { ExpectedStatus: 403, ExpectedContent: []string{`"data":{}`}, }, + { + Name: "submit nil body", + Method: http.MethodPost, + Url: "/api/collections/demo2/records", + Body: nil, + ExpectedStatus: 400, + ExpectedContent: []string{`"data":{}`}, + }, { Name: "submit invalid format", Method: http.MethodPost, @@ -827,12 +835,17 @@ func TestRecordCrudCreate(t *testing.T) { ExpectedContent: []string{`"data":{}`}, }, { - Name: "submit nil body", - Method: http.MethodPost, - Url: "/api/collections/demo2/records", - Body: nil, - ExpectedStatus: 400, - ExpectedContent: []string{`"data":{}`}, + Name: "submit empty json body", + Method: http.MethodPost, + Url: "/api/collections/nologin/records", + Body: strings.NewReader(`{}`), + ExpectedStatus: 400, + ExpectedContent: []string{ + `"data":{`, + `"email":{"code":"validation_required"`, + `"password":{"code":"validation_required"`, + `"passwordConfirm":{"code":"validation_required"`, + }, }, { Name: "guest submit in public collection", @@ -1316,6 +1329,17 @@ func TestRecordCrudUpdate(t *testing.T) { "OnRecordBeforeUpdateRequest": 1, }, }, + { + Name: "trigger field validation", + Method: http.MethodPatch, + Url: "/api/collections/demo2/records/0yxhwia2amd8gec", + Body: strings.NewReader(`{"title":"a"}`), + ExpectedStatus: 400, + ExpectedContent: []string{ + `data":{`, + `"title":{"code":"validation_min_text_constraint"`, + }, + }, { Name: "guest submit in public collection", Method: http.MethodPatch, diff --git a/tests/data/data.db b/tests/data/data.db index 87d713c8..012e067d 100644 Binary files a/tests/data/data.db and b/tests/data/data.db differ diff --git a/tests/data/logs.db b/tests/data/logs.db index 62f9fe56..ed29281c 100644 Binary files a/tests/data/logs.db and b/tests/data/logs.db differ