Skip to content

Commit a36524f

Browse files
authored
Merge branch 'main' into fix/generic-server-wait-strategy
2 parents 6bd25e5 + 898faf6 commit a36524f

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

modules/keycloak/testcontainers/keycloak/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,22 @@ def _configure(self) -> None:
7878
def get_url(self) -> str:
7979
host = self.get_container_host_ip()
8080
port = self.get_exposed_port(self.port)
81-
return f"http://{host}:{port}"
81+
82+
if "KC_HTTP_RELATIVE_PATH" in self.env:
83+
path = self.env.get("KC_HTTP_RELATIVE_PATH", "").strip("/")
84+
return f"http://{host}:{port}/{path}/"
85+
else:
86+
return f"http://{host}:{port}"
8287

8388
def get_management_url(self) -> str:
8489
host = self.get_container_host_ip()
8590
port = self.get_exposed_port(self.management_port)
86-
return f"http://{host}:{port}"
91+
92+
if "KC_HTTP_MANAGEMENT_RELATIVE_PATH" in self.env:
93+
path = self.env.get("KC_HTTP_MANAGEMENT_RELATIVE_PATH", "").strip("/")
94+
return f"http://{host}:{port}/{path}/"
95+
else:
96+
return f"http://{host}:{port}"
8797

8898
@wait_container_is_ready(requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout)
8999
def _readiness_probe(self) -> None:

modules/keycloak/tests/test_keycloak.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
from testcontainers.keycloak import KeycloakContainer
33

44

5-
@pytest.mark.parametrize("image_version", ["26.0.0", "25.0", "24.0.1", "18.0"])
5+
@pytest.mark.parametrize("image_version", ["26.4.0", "26.0.0", "25.0", "24.0.1", "18.0"])
66
def test_docker_run_keycloak(image_version: str):
77
with KeycloakContainer(f"quay.io/keycloak/keycloak:{image_version}") as keycloak_admin:
88
assert keycloak_admin.get_client().users_count() == 1
9+
10+
11+
def test_docker_run_keycloak_with_management_relative_path():
12+
with KeycloakContainer("quay.io/keycloak/keycloak:26.4.0").with_env(
13+
"KC_HTTP_MANAGEMENT_RELATIVE_PATH", "/some/deeply/nested/path"
14+
) as keycloak_admin:
15+
assert keycloak_admin.get_client().users_count() == 1

0 commit comments

Comments
 (0)