Skip to content

Add setup, fix bugs, introduce acl.AbstractACLGroupsCallback and new autz middleware, add pytests.#2

Open
ilex wants to merge 67 commits intognarlychicken:developfrom
ilex:develop
Open

Add setup, fix bugs, introduce acl.AbstractACLGroupsCallback and new autz middleware, add pytests.#2
ilex wants to merge 67 commits intognarlychicken:developfrom
ilex:develop

Conversation

@ilex
Copy link

@ilex ilex commented Jan 20, 2017

What do these changes do

  • Add setup functions for auth and acl middleware to install them in aiohttp fashion.
  • Add pytests: as the original tests don't run with current aiohttp version and require utils to
    be rewritten, I use a pytest lib with pytest-aiohttp plugin and unlike original tests
    with real aiohttp.Application. All tests were put into separate folder pytests:
    • All original tests were added with pytest.
    • Add some new tests to test untested functionality in auth and acl.
    • Add tests for all new functions, classes and modules.
  • Fix bugs:
    • The bug in acl_required decorator mentioned in acl_required decorator crash #1.
    • A possible security issue with acl groups. The issue is follow: the default behavior is
      to add user_id to groups for authenticated users by the acl middleware, but if
      user_id is equal to some of acl groups that user suddenly has the permissions he is not
      allowed for. So to avoid this kind of issue user_id is not added to groups any more. A test
      to reproduce the issue is also added.
  • Introduce AbstractACLGroupsCallback class in acl middleware to make it possible easily create
    callable object by inheriting from the abstract class and implementing acl_groups method. It
    can 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_callback parameter.
  • Introduce generic authorization middleware autz that performs authorization through the same
    interface (autz.permit coroutine and autz_required decorator) 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.
  • Add global aiohttp_auth.setup function to install auth and autz middlewares at once
    in aiohttp fashion.
  • Rewrite documentation in README.rst to reflect all changes. Introduce new modules and classes
    and usage examples in docs.

Known issues

There is one issue with auth middleware. In class TktAuthentication documentation says about
parameter 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 second
the value of ticket would be the same. So tests which test the reissue_time should wait a second
between requests to retrieve an actually new value.

gnarlychicken and others added 30 commits February 25, 2016 18:18
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.
ilex and others added 30 commits February 14, 2017 18:07
Readthedocs requires ``conda`` with python 3.5 to build API docs.
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
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