Fix erroneous requests due to HTTP-specific settings #497
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.
Description
The new
verb
HTTP specific option was handled by the SDK controllers, impacting all protocols, including WebSocket and MQTTImpacted routes:
document:mGet
andsecurity:mGetUsers
Those 2 routes send the
ids
argument to Kuzzle as a string, instead sending it as an array.Fortunately, Kuzzle makes no difference between requests sent using HTTP or WebSocket or any other protocol, and it sanitizes the request in such a way that this bug is invisible to common users.
But documents aren't sanitized the same way when the API route is invoked by a plugin. And when that happens, the two routes mentioned earlier make any plugin invoking them crash.
This PR removes any specificities from the SDK controllers and, instead, makes the HTTP protocol handle the new
verb
option itself.To do that, it simply converts any
body
object provided to a querystring if the selected API route uses theGET
method. The conversion code was already there, it just needed a small fix when converting arrays (that conversion was never used before).Other changes
mocha.opts
file to.mocharc.json
How to reproduce
Create a small plugin, and invoke
document:mGet
usingthis.context.sdk.document.mGet
The following error ensues:
Wrong type for argument "ids" (expected: array)