diff --git a/.bumpversion.toml b/.bumpversion.toml index 9c5b5d2d..b27017bc 100644 --- a/.bumpversion.toml +++ b/.bumpversion.toml @@ -1,5 +1,5 @@ [tool.bumpversion] -current_version = "1.20.1+261112" +current_version = "1.20.2+261121" parse = "(?P\\d+)\\.(?P\\d+)\\.(?P\\d+)\\+(?P\\d+)" serialize = ["{major}.{minor}.{patch}+{build}"] search = "{current_version}" diff --git a/pyproject.toml b/pyproject.toml index f4aa878e..a40b39ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "rasenmaeher_api" -version = "1.20.1+261112" +version = "1.20.2+261121" description = "python-rasenmaeher-api" authors = [ { name = "Aciid", email = "703382+Aciid@users.noreply.github.com" }, diff --git a/src/rasenmaeher_api/__init__.py b/src/rasenmaeher_api/__init__.py index f4e020ff..ad9f2f95 100644 --- a/src/rasenmaeher_api/__init__.py +++ b/src/rasenmaeher_api/__init__.py @@ -1,3 +1,3 @@ """python-rasenmaeher-api""" -__version__ = "1.20.1+261112" # NOTE Use `bump-my-version` to bump versions correctly +__version__ = "1.20.2+261121" # NOTE Use `bump-my-version` to bump versions correctly diff --git a/src/rasenmaeher_api/kchelpers.py b/src/rasenmaeher_api/kchelpers.py index a70f3c0d..b5b2c3e8 100644 --- a/src/rasenmaeher_api/kchelpers.py +++ b/src/rasenmaeher_api/kchelpers.py @@ -232,7 +232,11 @@ async def delete_kc_user(self, user: KCUserData) -> bool: async def client_access_token(self) -> dict[str, str | int]: """Create initial access token for a client to register for OIDC""" - return cast(dict[str, str | int], await self.kcadmin.a_create_initial_access_token()) + # Keycloak reads expiration in seconds; python-keycloak defaults to 1, which expires before use. + return cast( + dict[str, str | int], + await self.kcadmin.a_create_initial_access_token(count=1, expiration=60), + ) async def ensure_product_groups(self) -> bool | None: """Make sure each product in manifest has a root level group and initial child-group""" diff --git a/tests/test_kchelpers.py b/tests/test_kchelpers.py new file mode 100644 index 00000000..8f82d5fe --- /dev/null +++ b/tests/test_kchelpers.py @@ -0,0 +1,16 @@ +"""Keycloak helper tests""" + +from unittest.mock import AsyncMock, MagicMock + +import pytest + +from rasenmaeher_api.kchelpers import KCClient + + +@pytest.mark.asyncio +async def test_client_access_token_outlives_registration() -> None: + """The initial access token must stay valid long enough to register a client""" + kcadmin = MagicMock() + kcadmin.a_create_initial_access_token = AsyncMock(return_value={"token": "x"}) + assert await KCClient(kcadmin).client_access_token() == {"token": "x"} + kcadmin.a_create_initial_access_token.assert_awaited_once_with(count=1, expiration=60) diff --git a/tests/test_rasenmaeher_api.py b/tests/test_rasenmaeher_api.py index 8d4b94c7..850b3bea 100644 --- a/tests/test_rasenmaeher_api.py +++ b/tests/test_rasenmaeher_api.py @@ -15,7 +15,7 @@ def test_version() -> None: """Make sure version matches expected""" - assert __version__ == "1.20.1+261112" + assert __version__ == "1.20.2+261121" @pytest.mark.asyncio(loop_scope="session") diff --git a/uv.lock b/uv.lock index ec647301..eaa8c0d1 100644 --- a/uv.lock +++ b/uv.lock @@ -2366,7 +2366,7 @@ wheels = [ [[package]] name = "rasenmaeher-api" -version = "1.20.1+261112" +version = "1.20.2+261121" source = { editable = "." } dependencies = [ { name = "aiodns" },