Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api)!: only accept json content #831

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

noaccOS
Copy link
Contributor

@noaccOS noaccOS commented Aug 1, 2023

  1. Clients can not send urlencoded/multipart requests.
    BREAKING CHANGE: this means that eg an appengine request on the endpoint
    interface_values_path POST /v1/:realm_name/devices/:device_id/interfaces/:interface/*path_token
    which previously could be successful with an urlencoded body of data=2 will not be successful anymore.

  2. Remove pass: ["*/*"]
    From the Plug.Parsers documentation, "This plug will raise Plug.Parsers.UnsupportedMediaTypeError by default if the request cannot be parsed by any of the given types and the MIME type has not been explicitly accepted with the :pass option".
    I believe this to be the desired behavior, as the application should return error code 415 if it is not parsable by one of the specified parsers.

Closes #263

@codecov
Copy link

codecov bot commented Aug 1, 2023

Codecov Report

Merging #831 (16c7f32) into master (e0fd426) will decrease coverage by 0.01%.
Report is 12 commits behind head on master.
The diff coverage is 33.33%.

❗ Current head 16c7f32 differs from pull request most recent head f3f4489. Consider uploading reports for the commit f3f4489 to get more accurate results

@@            Coverage Diff             @@
##           master     #831      +/-   ##
==========================================
- Coverage   67.42%   67.42%   -0.01%     
==========================================
  Files         264      264              
  Lines        6429     6428       -1     
==========================================
- Hits         4335     4334       -1     
  Misses       2094     2094              
Files Changed Coverage Δ
...ne_api/lib/astarte_appengine_api/device/queries.ex 80.92% <0.00%> (ø)
...ib/astarte_data_updater_plant/data_updater/impl.ex 62.16% <0.00%> (ø)
..._management/lib/astarte_realm_management/engine.ex 78.46% <100.00%> (ø)

... and 8 files with indirect coverage changes

1. Clients can not send urlencoded/multipart requests.
BREAKING CHANGE: this means that eg an appengine request on the endpoint
`interface_values_path  POST    /v1/:realm_name/devices/:device_id/interfaces/:interface/*path_token`

which previously _could_ be successful with an urlencoded body of `data=2`
will not be successful anymore.

2. Remove `pass: ["*/*"]`
From the [Plug.Parsers documentation](https://hexdocs.pm/plug/Plug.Parsers.html),
"This plug will raise Plug.Parsers.UnsupportedMediaTypeError by default
if the request cannot be parsed by any of the given types and the MIME
type has not been explicitly accepted with the :pass option".

I believe this to be the desired behavior, as the application should return
error code 415 if it is not parsable by one of the specified parsers.

Signed-off-by: Francesco Noacco <[email protected]>
@noaccOS noaccOS force-pushed the only-accept-json branch 2 times, most recently from c0a33b8 to f3f4489 Compare August 9, 2023 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove :urlencoded and :multipart from Plug.Parsers in all APIs
2 participants