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

Validate the headers returned against the schema specification. #459

Closed
wants to merge 1 commit into from

Conversation

ttung
Copy link
Contributor

@ttung ttung commented May 31, 2017

Changes proposed in this pull request:

According to http://swagger.io/specification/#header-object-68, the headers should be validated. This adds a simple test for incorrect type (header returns a string where an integer is expected), and positive and negative tests against string length.

@coveralls
Copy link

coveralls commented May 31, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling b25f2a5 on ttung:headervalidation into 1f34e35 on zalando:master.

@jmcs
Copy link
Contributor

jmcs commented Jun 7, 2017

Thanks for the PR. Can you also update the documentation?(https://github.com/zalando/connexion/blob/master/docs/request.rst#request-validation)

@@ -56,6 +56,14 @@ def validate_response(self, data, status_code, headers, url):
msg = ("Keys in header don't match response specification. "
"Difference: {0}").format(pretty_list)
raise NonConformingResponseHeaders(message=msg)
# validate each of the existing keys.
for key, schema in response_definition.get("headers").items():
v = ResponseHeaderValidator(schema)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rename v to something like validator or header_validator.

@ttung
Copy link
Contributor Author

ttung commented Jun 8, 2017

Updated as per feedback (except I updated response.rst and not request.rst since I'm dealing with response headers).

@coveralls
Copy link

coveralls commented Jun 8, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 274b83b on ttung:headervalidation into 4403b66 on zalando:master.

@jmcs jmcs requested a review from last-ent June 8, 2017 12:53
error=exception))
six.reraise(*sys.exc_info())

return None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

# validate each of the existing keys.
for key, schema in response_definition.get("headers").items():
header_validator = ResponseHeaderValidator(schema)
for data in headers.getlist(key):
Copy link
Collaborator

Choose a reason for hiding this comment

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

The .getlist method is Flask specific. We are supposed to clear our core code from Flask specific stuff. I would recommend creating a new class ConnexionHeader that wraps this implementation. The ConnexionResponse class can instantiate this class when populating it's attribute self.headers. So whoever is going to implement a new framework support for Connexion will know they have to also implement a method called getlist (or maybe get_list?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is werkzeug.datastructures.Headers, not flask.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is werkzeug, not flask.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Still.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The response object here isn't even of type ConnexionResponse. I think this is somewhat premature.

Nevertheless, #464 is up for your review.

Copy link
Collaborator

@rafaelcaricio rafaelcaricio Jun 16, 2017

Choose a reason for hiding this comment

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

It is a ConnexionResponse instance. Not sure what you meant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's a flask.Response object.

Nevertheless, I've updated #464 as you suggested.

According to http://swagger.io/specification/#header-object-68, the headers should be validated.  This adds a simple test for incorrect type (header returns a string where an integer is expected), and positive and negative tests against string length.
@coveralls
Copy link

coveralls commented Jun 8, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 879ca49 on ttung:headervalidation into 4403b66 on zalando:master.

@ttung
Copy link
Contributor Author

ttung commented Aug 2, 2018

@jmcs jmcs added the waiting contributor feedback label 7 days ago

What feedback do you need from me?

@RobbeSneyders
Copy link
Member

Closing this since it's based on outdated code. Happy to review an updated PR on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants