diff --git a/modules/keycloak/testcontainers/keycloak/__init__.py b/modules/keycloak/testcontainers/keycloak/__init__.py index 21ffc4231..044ba0b2b 100644 --- a/modules/keycloak/testcontainers/keycloak/__init__.py +++ b/modules/keycloak/testcontainers/keycloak/__init__.py @@ -78,12 +78,22 @@ def _configure(self) -> None: def get_url(self) -> str: host = self.get_container_host_ip() port = self.get_exposed_port(self.port) - return f"http://{host}:{port}" + + if "KC_HTTP_RELATIVE_PATH" in self.env: + path = self.env.get("KC_HTTP_RELATIVE_PATH", "").strip("/") + return f"http://{host}:{port}/{path}/" + else: + return f"http://{host}:{port}" def get_management_url(self) -> str: host = self.get_container_host_ip() port = self.get_exposed_port(self.management_port) - return f"http://{host}:{port}" + + if "KC_HTTP_MANAGEMENT_RELATIVE_PATH" in self.env: + path = self.env.get("KC_HTTP_MANAGEMENT_RELATIVE_PATH", "").strip("/") + return f"http://{host}:{port}/{path}/" + else: + return f"http://{host}:{port}" @wait_container_is_ready(requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout) def _readiness_probe(self) -> None: diff --git a/modules/keycloak/tests/test_keycloak.py b/modules/keycloak/tests/test_keycloak.py index 24f533d11..4df0ca9c9 100644 --- a/modules/keycloak/tests/test_keycloak.py +++ b/modules/keycloak/tests/test_keycloak.py @@ -2,7 +2,14 @@ from testcontainers.keycloak import KeycloakContainer -@pytest.mark.parametrize("image_version", ["26.0.0", "25.0", "24.0.1", "18.0"]) +@pytest.mark.parametrize("image_version", ["26.4.0", "26.0.0", "25.0", "24.0.1", "18.0"]) def test_docker_run_keycloak(image_version: str): with KeycloakContainer(f"quay.io/keycloak/keycloak:{image_version}") as keycloak_admin: assert keycloak_admin.get_client().users_count() == 1 + + +def test_docker_run_keycloak_with_management_relative_path(): + with KeycloakContainer("quay.io/keycloak/keycloak:26.4.0").with_env( + "KC_HTTP_MANAGEMENT_RELATIVE_PATH", "/some/deeply/nested/path" + ) as keycloak_admin: + assert keycloak_admin.get_client().users_count() == 1