diff --git a/src/testcontainers/core/auth.py b/src/testcontainers/core/auth.py index afabe9e9..1ffd9427 100644 --- a/src/testcontainers/core/auth.py +++ b/src/testcontainers/core/auth.py @@ -36,7 +36,7 @@ def process_docker_auth_config_encoded(auth_config_dict: dict[str, dict[str, dic for registry, auth in auths.items(): auth_str = str(auth.get("auth")) auth_str = base64.b64decode(auth_str).decode("utf-8") - username, password = auth_str.split(":") + username, password = auth_str.split(":", 1) auth_info.append(DockerAuthInfo(registry, username, password)) return auth_info diff --git a/tests/core/test_auth.py b/tests/core/test_auth.py index f518fff2..9cc8b06d 100644 --- a/tests/core/test_auth.py +++ b/tests/core/test_auth.py @@ -1,3 +1,4 @@ +import base64 import json import pytest @@ -58,6 +59,19 @@ def test_parse_docker_auth_config_encoded_multiple(): ) +@pytest.mark.parametrize( + "username, password", + [ + ("user", "pass:word:"), + ("_json_key", '{"type": "service_account", "token_uri": "https://oauth2.googleapis.com/token"}'), + ], +) +def test_parse_docker_auth_config_password_with_colon(username: str, password: str): + auth = base64.b64encode(f"{username}:{password}".encode()).decode() + auth_info = parse_docker_auth_config(json.dumps({"auths": {"gcr.io": {"auth": auth}}})) + assert auth_info == [DockerAuthInfo(registry="gcr.io", username=username, password=password)] + + def test_parse_docker_auth_config_unknown(): auth_config_str = '{"key": "value"}' assert parse_docker_auth_config(auth_config_str) is None