Add setup, fix bugs, introduce acl.AbstractACLGroupsCallback and new autz middleware, add pytests.#2
Open
ilex wants to merge 67 commits intognarlychicken:developfrom
Open
Add setup, fix bugs, introduce acl.AbstractACLGroupsCallback and new autz middleware, add pytests.#2ilex wants to merge 67 commits intognarlychicken:developfrom
ilex wants to merge 67 commits intognarlychicken:developfrom
Conversation
With this function auth middleware can be set up in aiohttp fashion.
- Add all tests that reflect original tests/test_auth.py with pytest library pytest-aiohttp plugin and using real aiohttp application. - Add some new tests to test untested functions in auth. - Add test for introduced auth.setup function.
- Add docs for introduced auth.setup function. - Add syntax highlighting for code blocks. - Add information how to run pytests.
- Move assert middleware and helper function to utils. - Move client fixture to conftest.py. - Edit test_auth.py in order to go with that changes.
With this function acl middleware can be set up in aiohttp fashion.
Add all tests that reflect original tests/test_acl.py with pytest lib and real application.
Fixed bug with UnboundLocalError raised in acl_required decorator.
Add some new tests to test untested cases.
Change code examples in README.rst in order to show how to setup acl middleware in aiohttp fashion.
auth_middleware and acl_middleware can be now set up at once in the aiohttp fashion. tests: Add Pytest test for this setup function.
Add Pytest test to reproduce bug when value of user_id is equal to some group name. As user_id is automatically added to groups by acl middleware such user can get unauthorized permissions.
acl middleware does not add user_id to user groups any more. So that fixes the bug when user_id is equal to group name user can have unauthorized permissions.
Remove docs where it says that user_id is added to groups by acl middleware for authenticated user.
Add abstract base class for callable objects which can be passed to acl setup as acl_groups_callback callable. tests: Add Pytest tests for this class.
- Extract acl permit logic into separate function. - Extract acl user groups modification logic into separate function.
- Add authorization middleware autz which define common authorization interface using different authorization policies. - Add ACL authorization policy based on acl middleware to use with autz. tests: - Add pytests to test autz middleware with acl policy. - Add pytests to test autz middleware with custom policy.
Replace setting up acl middleware with setting up autz middleware.
- Introduce autz authorization plugin. - Introduce autz ACL authorization policy usage. - Introduce autz custom authorization policy usage.
Add tox to run pytests with python3.5 and python3.6.
- Change name in setup. - Remove original tests. - Make pytests as default tests.
In order to distinguish auth error from autz error auth_required decorator now raises a web.HTTPUnauthorized error instead of web.HTTPForbidden.
Readthedocs requires ``conda`` with python 3.5 to build API docs.
0.2.0.post0
As current aiohttp version is not ready to work with yarl>=0.9.0 it requires to explicitly set version of the yarl lib.
- Move permit logic from context classes to AbstractACLAutzPolicy. - Remove AbstractACLContext, NaiveACLContext and ACLContex classes. - Change policy.acl module docstrings to reflect changes.
Yarl is fixed so no need in certain version.
- Move to aiohttp 2.x. - Add support of middlewares decorators for class based views. - Correct code in order to meet requirements of aiohttp 2.x. - Add uvloop as IO loop in tests.
Add aiohttp 2.x and 3.x to tox environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What do these changes do
setupfunctions forauthandaclmiddleware to install them in aiohttp fashion.be rewritten, I use a
pytestlib withpytest-aiohttpplugin and unlike original testswith real aiohttp.Application. All tests were put into separate folder
pytests:authandacl.acl_requireddecorator mentioned in acl_required decorator crash #1.aclgroups. The issue is follow: the default behavior isto add
user_idto groups for authenticated users by the acl middleware, but ifuser_idis equal to some of acl groups that user suddenly has the permissions he is notallowed for. So to avoid this kind of issue
user_idis not added to groups any more. A testto reproduce the issue is also added.
AbstractACLGroupsCallbackclass inaclmiddleware to make it possible easily createcallable object by inheriting from the abstract class and implementing
acl_groupsmethod. Itcan be useful to store additional information (such database connection etc.) within such class.
An instance of this subclass can be used in place of
acl_groups_callbackparameter.autzthat performs authorization through the sameinterface (
autz.permitcoroutine andautz_requireddecorator) but using different policies.Middleware has the acl authorization as the built in policy which works in the same way as acl
middleware. Users are free to add their own custom policies or to modify ACL one.
aiohttp_auth.setupfunction to installauthandautzmiddlewares at oncein aiohttp fashion.
and usage examples in docs.
Known issues
There is one issue with
authmiddleware. In classTktAuthenticationdocumentation says aboutparameter
reissue_time:If this value is 0, a new ticket will be reissued on every request which requires authentication.. But it seems that if two requests are handled during one secondthe value of ticket would be the same. So tests which test the
reissue_timeshould wait a secondbetween requests to retrieve an actually new value.