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

BGDIINF_SB-2197: Returns 415 in case of wrong content-type #93

Merged
merged 2 commits into from
Feb 24, 2022

Conversation

ltshb
Copy link
Contributor

@ltshb ltshb commented Feb 24, 2022

If the request was done with an invalid content-type, then the service
returned a 400, "No 'geom' given, cannot create a profile without coordinates".

This was kind of misleading, for example when doing a request with curl without
specifying the content-type (curl used application/x-www-form-urlencoded) but
with valid payload.

The issue was that request.is_json in flask is set based on the content-type header
and not on the payload being a valid json.

In flask no need to path the request object around, but use the flask global request object.

Also avoid linting similarities warning.

Removed unnecessary `methods=["GET"]` for the checker, that is the default in Flask and
it is then consistent with the /height route.
@ltshb ltshb requested a review from pakb February 24, 2022 11:53
Comment on lines 91 to 100
@patch('app.routes.georaster_utils')
def test_profile_validation_wrong_content_type(self, mock_georaster_utils):
prepare_mock(mock_georaster_utils)
response = self.test_instance.post('/rest/services/profile.json', headers=self.headers)
self.assert_response(response, expected_status=415)

Copy link
Contributor

Choose a reason for hiding this comment

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

seems like the CI let this go (as before) to a 400, shouldn't we force the Content-Type to something wrong here so that we are sure to hit the right portion of the if...else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Strange was working locally, but your right it would be wiser here to be more explicit, I'll change the test.

@ltshb
Copy link
Contributor Author

ltshb commented Feb 24, 2022

@pakb can we remove the service-alti-python2 codebuild project, apparently we don't need to support python2 anymore and this codebuild project used anyway python 3.7.

@pakb
Copy link
Contributor

pakb commented Feb 24, 2022

@pakb can we remove the service-alti-python2 codebuild project, apparently we don't need to support python2 anymore and this codebuild project used anyway python 3.7.

As you are finalizing the migration to docker, that makes total sense yes. Python2 support was there only to accommodate vhost support

If the request was done with an invalid content-type, then the service
returned a 400, "No 'geom' given, cannot create a profile without coordinates".

This was kind of misleading, for example when doing a request with curl without
specifying the content-type (curl used application/x-www-form-urlencoded) but
with valid payload.

The issue was that `request.is_json` in flask is set based on the content-type header
and not on the payload being a valid json.
@ltshb ltshb force-pushed the bug-BGDIINF_SB-2197-wrong-content-type branch from 08f4fa3 to 4b84eb8 Compare February 24, 2022 13:39
@ltshb ltshb merged commit b713591 into develop Feb 24, 2022
@ltshb ltshb deleted the bug-BGDIINF_SB-2197-wrong-content-type branch February 24, 2022 13:44
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.

2 participants