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 KeyError if no Content-Type was provided in request #497

Merged
merged 4 commits into from
Aug 15, 2017
Merged

Fix KeyError if no Content-Type was provided in request #497

merged 4 commits into from
Aug 15, 2017

Conversation

f11r
Copy link

@f11r f11r commented Aug 2, 2017

At the moment if no Content-Type is provided in the request the validation wrapper raises a KeyError.

Can we expect a fix to make it into a release soon or should we look for a temporary workaround until that happens?

@coveralls
Copy link

coveralls commented Aug 2, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 26031bc on f11r:master into d51e9c8 on zalando:master.

@hjacobs
Copy link
Contributor

hjacobs commented Aug 2, 2017

@f11r looks good, thanks for the PR! Could you add a test for this case please? Thanks!

@hjacobs
Copy link
Contributor

hjacobs commented Aug 2, 2017

@f11r answering your question: yes, we can quickly release it, but please add a test 😄

@f11r
Copy link
Author

f11r commented Aug 2, 2017

@hjacobs tests/decorators/test_validation.py seems to only have tests for `ParameterValidator. Is this still the correct file to add a test or could you point me to the correct place to add it? I'm not really familiar with the tests here.

@hjacobs
Copy link
Contributor

hjacobs commented Aug 2, 2017

@f11r I think you can add it here: https://github.com/zalando/connexion/blob/6668835420231c15095a71e264b2e2b0e1a68bf3/tests/api/test_responses.py#L203

It currently only tests the status code (415) on "wrong" content type (i.e. not the case where Content-Type is missing).

@f11r
Copy link
Author

f11r commented Aug 3, 2017

It actually looks like you already did have the correct test here https://github.com/zalando/connexion/blob/6668835420231c15095a71e264b2e2b0e1a68bf3/tests/api/test_responses.py#L213, but werkzeug always sets Content-Type to an empty string if not provided in the post. I opened an issue (pallets/werkzeug#1159) over there.

@hjacobs
Copy link
Contributor

hjacobs commented Aug 3, 2017

@f11r maybe you can do an "artificial" manual HTTP request in the test and not use the test client?

@f11r
Copy link
Author

f11r commented Aug 3, 2017

Added a test, not particularly pretty. Not sure if something like requests.post() could actually work since if I understand it correctly the test server is just a "fake"-server.

@hjacobs
Copy link
Contributor

hjacobs commented Aug 3, 2017

Hmm, test is failing now: https://travis-ci.org/zalando/connexion/jobs/260553758

@f11r
Copy link
Author

f11r commented Aug 3, 2017

I seem to be on a roll here :D

In a clean python3.5 environment running pip install -r requirements-devel.txt && pip install typing && python setup.py test works, while pip install pytest typing && python setup.py test fails (on a unrelated note, typing seems to be missing somewhere so that I have to install it manually).

I'll try to figure out why tomorrow.

…for no-content-type-test since old flask<=0.12.2 does not support it.
@coveralls
Copy link

coveralls commented Aug 4, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling ee72325 on f11r:master into d51e9c8 on zalando:master.

@f11r
Copy link
Author

f11r commented Aug 4, 2017

Figured out what is going on: app_client is a flask.testing.FlaskClient which does not support passing an environment as the only argument to open() in flask<=0.12.2. This was only implemented recently in pallets/flask#2412. That's why it succeeded for the development builds but not for the "real" builds. I implemented a workaround but that doesn't make the test any prettier.

# (https://github.com/pallets/werkzeug/issues/1159)
# so that content-type is added to every request, we remove it here manually for our test
# this test can be removed once the werkzeug issue is addressed
from werkzeug.test import Client, EnvironBuilder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this import to the top level (beginning of the file)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@coveralls
Copy link

coveralls commented Aug 15, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 07ce38b on f11r:master into d51e9c8 on zalando:master.

@jmcs
Copy link
Contributor

jmcs commented Aug 15, 2017

👍

@jmcs jmcs merged commit ea955c3 into spec-first:master Aug 15, 2017
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.

4 participants