Add data validation to the node server request handler #22
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.
This pull request aims at adding data validation to the request handlers used in the node server for adding entries to the MongoDB.
Since
req.body
's shape is based on user-controlled input, it should not always be trusted.I introduce a Joi schema matching the following record type:
learn-ocaml/src/app/learnocaml_exercise_main.ml
Lines 74 to 79 in 82ae88e
The following code snippet is responsible for making POST requests from the LearnOCaml server to the node server.
It seems like the
mongo_solution
is marshalled into an object with the proper keys.learn-ocaml/src/app/learnocaml_exercise_main.ml
Lines 98 to 102 in 82ae88e
I was surprised to find in the node request handler that the
mongo_solution
gets unmarshalled as an array.Is this a limitation of
js_of_ocaml
?learn-ocaml/node/app.js
Lines 32 to 43 in 82ae88e
Testing would be required to ensure that this PR does not break unmarshalling of the request's body.