diff --git a/swh/auth/keycloak.py b/swh/auth/keycloak.py --- a/swh/auth/keycloak.py +++ b/swh/auth/keycloak.py @@ -40,12 +40,25 @@ self._keycloak = KeycloakOpenID( server_url=server_url, client_id=client_id, realm_name=realm_name, ) - self.server_url = server_url - self.realm_name = realm_name - self.client_id = client_id self.realm_public_key = realm_public_key + @property + def realm_name(self): + return self._keycloak.realm_name + + @realm_name.setter + def realm_name(self, value): + self._keycloak.realm_name = value + + @property + def client_id(self): + return self._keycloak.client_id + + @client_id.setter + def client_id(self, value): + self._keycloak.client_id = value + def well_known(self) -> Dict[str, Any]: """ Retrieve the OpenID Connect Well-Known URI registry from Keycloak. diff --git a/swh/auth/pytest_plugin.py b/swh/auth/pytest_plugin.py --- a/swh/auth/pytest_plugin.py +++ b/swh/auth/pytest_plugin.py @@ -13,7 +13,14 @@ import pytest from swh.auth.keycloak import KeycloakOpenIDConnect -from swh.auth.tests.sample_data import OIDC_PROFILE, RAW_REALM_PUBLIC_KEY, USER_INFO +from swh.auth.tests.sample_data import ( + CLIENT_ID, + OIDC_PROFILE, + RAW_REALM_PUBLIC_KEY, + REALM_NAME, + SERVER_URL, + USER_INFO, +) class KeycloackOpenIDConnectMock(KeycloakOpenIDConnect): @@ -193,3 +200,10 @@ # for backward compatibility # TODO: remove that alias once swh-deposit and swh-web use new function name keycloak_mock_factory = keycloak_oidc_factory + +# generic keycloak fixture that can be used within tests +# (cf. test_keycloak.py, test_utils.py, django related tests) +# or external modules using that pytest plugin +keycloak_oidc = keycloak_oidc_factory( + server_url=SERVER_URL, realm_name=REALM_NAME, client_id=CLIENT_ID, +) diff --git a/swh/auth/tests/conftest.py b/swh/auth/tests/conftest.py deleted file mode 100644 --- a/swh/auth/tests/conftest.py +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (C) 2021 The Software Heritage developers -# See the AUTHORS file at the top-level directory of this distribution -# License: GNU Affero General Public License version 3, or any later version -# See top-level LICENSE file for more information - - -from swh.auth.pytest_plugin import keycloak_oidc_factory -from swh.auth.tests.sample_data import CLIENT_ID, REALM_NAME, SERVER_URL - -# keycloak fixture used within tests (cf. test_keycloak.py, test_utils.py) -keycloak_oidc = keycloak_oidc_factory( - server_url=SERVER_URL, realm_name=REALM_NAME, client_id=CLIENT_ID, -) diff --git a/swh/auth/tests/django/test_utils.py b/swh/auth/tests/django/test_utils.py --- a/swh/auth/tests/django/test_utils.py +++ b/swh/auth/tests/django/test_utils.py @@ -108,8 +108,7 @@ KEYCLOAK_REALM_NAME=REALM_NAME, KEYCLOAK_CLIENT_ID=CLIENT_ID, ) -def test_keycloak_oidc_client_parameters_from_django_settings(mocker): - mocker.patch("swh.auth.keycloak.KeycloakOpenID") +def test_keycloak_oidc_client_parameters_from_django_settings(): kc_oidc_client = keycloak_oidc_client()