FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(keycloak): Fixed Keycloak testcontainer for latest version v26.1.0 by max-pfeiffer · Pull Request #766 · testcontainers/testcontainers-python · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 9 additions & 1 deletion modules/keycloak/testcontainers/keycloak/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
from testcontainers.core.waiting_utils import wait_container_is_ready, wait_for_logs

_DEFAULT_DEV_COMMAND = "start-dev"
# Since Keycloak v26.0.0
# See: https://www.keycloak.org/server/all-config#category-bootstrap_admin
ADMIN_USERNAME_ENVIRONMENT_VARIABLE = "KC_BOOTSTRAP_ADMIN_USERNAME"
ADMIN_PASSWORD_ENVIRONMENT_VARIABLE = "KC_BOOTSTRAP_ADMIN_PASSWORD"


class KeycloakContainer(DockerContainer):
Expand Down Expand Up @@ -57,6 +61,9 @@ def __init__(
self.cmd = cmd

def _configure(self) -> None:
self.with_env(ADMIN_USERNAME_ENVIRONMENT_VARIABLE, self.username)
self.with_env(ADMIN_PASSWORD_ENVIRONMENT_VARIABLE, self.password)
# legacy env vars (<= 26.0.0)
self.with_env("KEYCLOAK_ADMIN", self.username)
self.with_env("KEYCLOAK_ADMIN_PASSWORD", self.password)
# Enable health checks
Expand Down Expand Up @@ -89,7 +96,8 @@ def _readiness_probe(self) -> None:
response = requests.get(f"{self.get_url()}/health/ready", timeout=1)
response.raise_for_status()
if _DEFAULT_DEV_COMMAND in self._command:
wait_for_logs(self, "Added user .* to realm .*")
wait_for_logs(self, "started in \\d+\\.\\d+s")
wait_for_logs(self, "Created temporary admin user|Added user '")

def start(self) -> "KeycloakContainer":
super().start()
Expand Down
2 changes: 1 addition & 1 deletion modules/keycloak/tests/test_keycloak.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from testcontainers.keycloak import KeycloakContainer


@pytest.mark.parametrize("image_version", ["25.0", "24.0.1", "18.0"])
@pytest.mark.parametrize("image_version", ["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

Back | FazBrowse Home | New Git URL