Make it possible to create a user through the API - #693
Merged
Conversation
POST /api/v1/users could not create anybody. The controller built a user with no password, User.pass is NOT NULL with no default, and the insert died on the database: every call answered a 500 with "Field 'pass' doesn't have a default value". The endpoint has never worked. Take the password as a required parameter, as the web form does — the service already hashes it — and keep it out of the answer: the create response echoes the user built from the request, which is the one object in the API that holds a password in the clear. The edit response goes through the same filter. Covered by tests that read the stored hash back and check it against the password that was sent, and that assert the plaintext appears nowhere in the response body. The user endpoints have no help class, so a missing parameter is reported as "Wrong parameters" with an empty detail where the group and tag endpoints name what was wrong. Recorded in the test as the gap it is, not fixed here.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
POST /api/v1/userscould not create anybody. Every call answered:{"error":{"message":"Error while doing the query", "detail":"SQLSTATE[HY000]: General error: 1364 Field 'pass' doesn't have a default value"}}The controller built a
Userwith no password;User.passisNOT NULLwith no default; the insert died on the database. The endpoint has never worked — found while writing the first tests for this family.The fix
UserService::create()already hashes it.Testing
Extends
UserControllerTestto 19 tests against the real REST dispatch and the real database:One gap recorded, not fixed
The user endpoints have no help class (the account, category, client, config, tag and group ones do), so a missing parameter comes back as
Wrong parameterswith an emptydetailwhere the sibling endpoints name what was wrong. The test records that rather than asserting it is desirable.