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
Python generator: Add OAuth2_Password security feature. #404
Python generator: Add OAuth2_Password security feature. #404
Conversation
Error detected on scope_names definition for OAuth2PasswordBearer flow:
API used for testing: Further work required. @spacether how can I add this API for the endpoint tests?? |
Can you edit this file: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator/blob/master/src/test/resources/3_0/security.yaml
|
9696449
to
46a5fd0
Compare
@JoftheV how are you involved in this project? Pull reviews need to be feature complete and have all tests passing before they are approved and merged to master. This PR is not yet feature complete and tests are not yet passing. Are you a user who wants this feature? If so a comment saying that would be more helpful than an approval of the PR. I also just updated PR review privledges to limit it to read and higher members of this project. |
47ac23a
to
f28933b
Compare
@@ -1368,6 +1373,10 @@ protected void updateModelForComposedSchema(CodegenSchema m, Schema schema, Stri | |||
} | |||
} | |||
|
|||
public LinkedHashSet<String> getOauthServerHostnames() { |
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.
How about returning null if oauthServerHostnames is empty?
Then you can simplify the call site to:
bundle.put("oauthServerHostnames", generator.getOauthServerHostnames());
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.
Could you provide me more details about this? I do not get it completely.
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.
You can update the code here to have:
if (oauthServerHostnames.isEmpty()) {
return null;
}
Then change the caller to remove the if statement and use bundle.put("oauthServerHostnames", generator.getOauthServerHostnames());
samples/client/openapi_features/security/python/docs/paths/path_with_security_from_root/get.md
Show resolved
Hide resolved
samples/client/openapi_features/security/python/docs/paths/path_with_security_from_root/get.md
Outdated
Show resolved
Hide resolved
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 PR is in good share but still needs some changes. Good work so far.
Remaining work
- please add a test in the tests_manual folder verifying that when the password auth info is configured and a route with password auth is used, that the auth is applied to the request. One can see an example test that verifies a request here: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator/blob/master/samples/client/petstore/python/tests_manual/test_paths/test_pet_pet_id/test_get.py#L54
- please make the updates described in the comments that I have left
Once those updates have been done and merged and all tests are passing in CI, this will be ready to merge. Good job, you are almost there!
@spacether review
…mentation errors in the tests.
Hi @spacether. I have added manual tests for oauth password in my last commit e46ba81 but still not working properly the tests. I ask for some support here to refine this tests. Could your team help me here? Test definition: test_get.py](https://github.com/openapi-json-schema-tools/openapi-json-schema-generator/pull/404/files/e46ba81b8c63ac1ad3091ea39bb5c77ad0e47773..92f013820df14846a2523e4858b3b0ffef7cf945#diff-69e9a5a27a59e261e79cc7cbec71aa0f2a6c3b616438879bd145424678c44e20) |
# I need a first call for the /api/oauth/token endpoint to provide the access token | ||
self.assert_pool_manager_request_called_with( | ||
mock_request, | ||
f'http://localhost:3000/api/oauth/token', | ||
method='POST', | ||
additional_headers={f'{access_token}': 'someAccessToken', 'token_type': 'Bearer'} | ||
) | ||
|
||
# I need a second call for the /pathWithOAuthPasswordSecurity endpoint to perform the actual request | ||
# it should contain the access token | ||
self.assert_pool_manager_request_called_with( | ||
mock_request, | ||
f'http://localhost:3000/pathWithOAuthPasswordSecurity', | ||
method='GET', | ||
additional_headers={'Authorization': f'Bearer {access_token}'} | ||
) |
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.
Further work is required to fix this test. @spacether
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.
Please patch the client.fetch_token call or the deeper requests call rather than patching the urllib3 call.
The deeper request call is at client.session.request I think, you will have to step through the code to see it. Or you can patch it like the authlib package does, see their tests here: https://github.com/lepture/authlib/blob/5ac468051098d544dd5bfad24f692ec1a6bc7ec1/tests/clients/test_requests/test_oauth2_session.py#L133
@@ -96,6 +100,7 @@ class ApiConfiguration(object): | |||
:param security_index_info: path to security_index information | |||
:param server_info: the servers that can be used to make endpoint calls | |||
:param server_index_info: index to servers configuration | |||
:param oauth_server_client_info: the oauth client_id and client_secret info |
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.
Please update the comment here. # the oauth client used for a specific oauth server
the current comment is incorrect
Closing this due to inactivity. If someone wants to reopen it later, rebase it, and fix the needed tests, then I am open to having that merged. |
This PR is part of #403
Not ready to merge.
Missing endpoint tests.
Note: this continues work started in #155
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/python*
.For Windows users, please run the script in Git BASH.