-
-
Notifications
You must be signed in to change notification settings - Fork 763
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
Extract security to middleware #1514
Conversation
@@ -390,6 +385,17 @@ def function(self): | |||
|
|||
return function | |||
|
|||
@property | |||
def _request_response_decorator(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lifted from the removed SecureOperation
as it's not actually related to security.
@@ -36,7 +36,6 @@ def test_security(oauth_requests, secure_endpoint_app): | |||
assert get_bye_no_auth.status_code == 401 | |||
assert get_bye_no_auth.content_type == 'application/problem+json' | |||
get_bye_no_auth_reponse = json.loads(get_bye_no_auth.data.decode('utf-8', 'replace')) # type: dict | |||
assert get_bye_no_auth_reponse['title'] == 'Unauthorized' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
starlette.HTTPException
does not have a title
attribute.
|
||
monkeypatch.setattr('connexion.security.flask_security_handler_factory.session.get', fake_get) | ||
|
||
class FakeClient: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored to work with httpx
instead of requests
.
definitions=DEFINITIONS, | ||
parameter_definitions=PARAMETER_DEFINITIONS, | ||
resolver=Resolver()) | ||
assert isinstance(operation.function, types.FunctionType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed intermediate security checks for tests not related to security.
|
||
assert operation.method == 'GET' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use SecurityOperation
and remove intermediate checks not related to security for tests related to security.
**kwargs | ||
): | ||
super().__init__(specification, *args, **kwargs) | ||
self.security_handler_factory = SecurityHandlerFactory('context') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded pass_context_arg_name
here.
Would propose to get rid of the parameter and choose a fixed name, but to do so in a follow-up PR.
16d4faf
to
3f34999
Compare
3f34999
to
2ef49d7
Compare
2ef49d7
to
e5dfc52
Compare
Pull Request Test Coverage Report for Build 2222571101
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First review - some initial comments/questions, but still need to go over it again and have a better look at test_operation2.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed half of the PR, left some questions and nitpicks. Will do the rest this weekend.
for path, methods in paths.items(): | ||
for method, operation in methods.items(): | ||
if method not in METHODS: | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it make more sense to handle this more upstream when parsing the spec? If not, we should warn here that a method is being skipped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is validated when parsing the spec, but there are other valid keys at this level. For instance for common parameters for a path. We want to skip those.
This reverts commit c1004c7.
c1f076d
to
d20ef93
Compare
Part of #1489.
Fixes #1120.
This PR adds the SecurityMiddleware, which checks the security for incoming requests.
Changes proposed in this pull request:
AbstractAPI
andFlaskApi
toSecurityApi
werkzeug
exceptions withstarlette.HTTPException
subclassesSecureOperation
base class and extract security from all operations to separateSecurityOperation
class only used in middlewareSecurityHandlerFactory
class.It's quite a big one, but unfortunately it wasn't possible to split this into smaller PRs that would still pass the tests.