From 75269e817721c72722aacb85cb46825cc7e2650e Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Thu, 2 Sep 2021 01:45:11 +0300 Subject: [PATCH] fix codefactor errors --- setup.py | 2 +- src/ahriman/core/auth/auth.py | 5 +++-- src/ahriman/core/auth/mapping_auth.py | 4 +++- src/ahriman/web/middlewares/auth_handler.py | 2 +- tests/ahriman/core/auth/test_auth.py | 4 ++-- tests/ahriman/core/auth/test_mapping_auth.py | 4 ++-- tests/ahriman/web/middlewares/test_auth_handler.py | 2 +- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/setup.py b/setup.py index f294f92b..3cd0c2d8 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from typing import Any, Dict metadata_path = Path(__file__).resolve().parent / "src/ahriman/version.py" -metadata: Dict[str, Any] = dict() +metadata: Dict[str, Any] = {} with metadata_path.open() as metadata_file: exec(metadata_file.read(), metadata) # pylint: disable=exec-used diff --git a/src/ahriman/core/auth/auth.py b/src/ahriman/core/auth/auth.py index 84cd6cd8..ee81442a 100644 --- a/src/ahriman/core/auth/auth.py +++ b/src/ahriman/core/auth/auth.py @@ -90,12 +90,13 @@ class Auth: del username return True - def verify_access(self, username: str, required: UserAccess) -> bool: # pylint: disable=no-self-use + def verify_access(self, username: str, required: UserAccess, context: Optional[str]) -> bool: # pylint: disable=no-self-use """ validate if user has access to requested resource :param username: username :param required: required access level + :param context: URI request path :return: True in case if user is allowed to do this request and False otherwise """ - del username, required + del username, required, context return True diff --git a/src/ahriman/core/auth/mapping_auth.py b/src/ahriman/core/auth/mapping_auth.py index 6ecead80..873e591a 100644 --- a/src/ahriman/core/auth/mapping_auth.py +++ b/src/ahriman/core/auth/mapping_auth.py @@ -90,12 +90,14 @@ class MappingAuth(Auth): """ return self.get_user(username) is not None - def verify_access(self, username: str, required: UserAccess) -> bool: + def verify_access(self, username: str, required: UserAccess, context: Optional[str]) -> bool: """ validate if user has access to requested resource :param username: username :param required: required access level + :param context: URI request path :return: True in case if user is allowed to do this request and False otherwise """ + del context user = self.get_user(username) return user is not None and user.verify_access(required) diff --git a/src/ahriman/web/middlewares/auth_handler.py b/src/ahriman/web/middlewares/auth_handler.py index 8635850c..e2b8f860 100644 --- a/src/ahriman/web/middlewares/auth_handler.py +++ b/src/ahriman/web/middlewares/auth_handler.py @@ -62,7 +62,7 @@ class AuthorizationPolicy(aiohttp_security.AbstractAuthorizationPolicy): # type :param context: URI request path :return: True in case if user is allowed to perform this request and False otherwise """ - return self.validator.verify_access(identity, permission) + return self.validator.verify_access(identity, permission, context) def auth_handler(validator: Auth) -> MiddlewareType: diff --git a/tests/ahriman/core/auth/test_auth.py b/tests/ahriman/core/auth/test_auth.py index 37719171..6e8a2051 100644 --- a/tests/ahriman/core/auth/test_auth.py +++ b/tests/ahriman/core/auth/test_auth.py @@ -77,5 +77,5 @@ def test_verify_access(auth: Auth, user: User) -> None: """ must allow any access """ - assert auth.verify_access(user.username, user.access) - assert auth.verify_access(user.username, UserAccess.Write) + assert auth.verify_access(user.username, user.access, None) + assert auth.verify_access(user.username, UserAccess.Write, None) diff --git a/tests/ahriman/core/auth/test_mapping_auth.py b/tests/ahriman/core/auth/test_mapping_auth.py index 54fc69b0..e6fe1972 100644 --- a/tests/ahriman/core/auth/test_mapping_auth.py +++ b/tests/ahriman/core/auth/test_mapping_auth.py @@ -117,5 +117,5 @@ def test_verify_access(mapping_auth: MappingAuth, user: User) -> None: must verify user access """ mapping_auth._users[user.username] = user - assert mapping_auth.verify_access(user.username, user.access) - assert not mapping_auth.verify_access(user.username, UserAccess.Write) + assert mapping_auth.verify_access(user.username, user.access, None) + assert not mapping_auth.verify_access(user.username, UserAccess.Write, None) diff --git a/tests/ahriman/web/middlewares/test_auth_handler.py b/tests/ahriman/web/middlewares/test_auth_handler.py index ea381c29..a89f35f6 100644 --- a/tests/ahriman/web/middlewares/test_auth_handler.py +++ b/tests/ahriman/web/middlewares/test_auth_handler.py @@ -26,7 +26,7 @@ async def test_permits(authorization_policy: AuthorizationPolicy, user: User) -> authorization_policy.validator.verify_access.return_value = True assert await authorization_policy.permits(user.username, user.access, "/endpoint") - authorization_policy.validator.verify_access.assert_called_with(user.username, user.access) + authorization_policy.validator.verify_access.assert_called_with(user.username, user.access, "/endpoint") async def test_auth_handler_api(aiohttp_request: Any, auth: Auth, mocker: MockerFixture) -> None: