diff --git a/tests/norun/test_registry.py b/tests/norun/test_registry.py index 92aa1f6e..98a1d36c 100644 --- a/tests/norun/test_registry.py +++ b/tests/norun/test_registry.py @@ -4,12 +4,12 @@ import secrets import shutil import socket import subprocess -from tempfile import TemporaryDirectory -from base64 import b64encode import time -import bcrypt +from base64 import b64encode from pathlib import Path +from tempfile import TemporaryDirectory +import bcrypt import pytest import requests @@ -87,7 +87,9 @@ def registry(host_ip): port = get_free_port() username = "user" password = secrets.token_hex(16) - bcrypted_pw = bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt(rounds=12)).decode("utf-8") + bcrypted_pw = bcrypt.hashpw( + password.encode("utf-8"), bcrypt.gensalt(rounds=12) + ).decode("utf-8") # We put our password here, and mount it into the container. # put it in current dir than in /tmp because on macos, current dir is likely to @@ -100,12 +102,22 @@ def registry(host_ip): registry_image = "registry:3.0.0-rc.3" subprocess.check_call(["docker", "pull", registry_image]) - cmd = ["docker", "run", "--rm", - "-e", "REGISTRY_AUTH=htpasswd", - "-e", "REGISTRY_AUTH_HTPASSWD_REALM=basic", - "-e", "REGISTRY_AUTH_HTPASSWD_PATH=/opt/htpasswd/htpasswd.conf", - "--mount", f"type=bind,src={htpasswd_dir},dst=/opt/htpasswd", - "-p", f"{port}:5000", registry_image] + cmd = [ + "docker", + "run", + "--rm", + "-e", + "REGISTRY_AUTH=htpasswd", + "-e", + "REGISTRY_AUTH_HTPASSWD_REALM=basic", + "-e", + "REGISTRY_AUTH_HTPASSWD_PATH=/opt/htpasswd/htpasswd.conf", + "--mount", + f"type=bind,src={htpasswd_dir},dst=/opt/htpasswd", + "-p", + f"{port}:5000", + registry_image, + ] proc = subprocess.Popen(cmd) health_url = f"http://{host_ip}:{port}/v2" # Wait for the registry to actually come up @@ -144,19 +156,24 @@ def test_registry_explicit_creds(registry, dind): os.environ["DOCKER_HOST"] = docker_host os.environ["DOCKER_CERT_PATH"] = str(cert_dir / "client") os.environ["DOCKER_TLS_VERIFY"] = "1" - os.environ["CONTAINER_ENGINE_REGISTRY_CREDENTIALS"] = json.dumps({ - "registry": f"http://{registry_host}", - "username": username, - "password": password - }) + os.environ["CONTAINER_ENGINE_REGISTRY_CREDENTIALS"] = json.dumps( + { + "registry": f"http://{registry_host}", + "username": username, + "password": password, + } + ) r2d.start() - - proc = subprocess.run(["docker", "manifest", "inspect", "--insecure", image_name]) + proc = subprocess.run( + ["docker", "manifest", "inspect", "--insecure", image_name] + ) assert proc.returncode == 0 # Validate that we didn't leak our registry creds into existing docker config - docker_config_path = Path(os.environ.get("DOCKER_CONFIG", "~/.docker/config.json")).expanduser() + docker_config_path = Path( + os.environ.get("DOCKER_CONFIG", "~/.docker/config.json") + ).expanduser() if docker_config_path.exists(): # Just check that our randomly generated password is not in this file # Can this cause a conflict? Sure, if there's a different randomly generated password in here @@ -184,15 +201,26 @@ def test_registry_no_explicit_creds(registry, dind): os.environ["DOCKER_CERT_PATH"] = str(cert_dir / "client") os.environ["DOCKER_TLS_VERIFY"] = "1" with TemporaryDirectory() as d: - (Path(d) / "config.json").write_text(json.dumps( - ({"auths":{f"http://{registry_host}":{"auth":b64encode(f"{username}:{password}".encode()).decode()}}}) - )) + (Path(d) / "config.json").write_text( + json.dumps( + { + "auths": { + f"http://{registry_host}": { + "auth": b64encode( + f"{username}:{password}".encode() + ).decode() + } + } + } + ) + ) os.environ["DOCKER_CONFIG"] = d r2d.start() - - proc = subprocess.run(["docker", "manifest", "inspect", "--insecure", image_name]) + proc = subprocess.run( + ["docker", "manifest", "inspect", "--insecure", image_name] + ) assert proc.returncode == 0 finally: os.environ.clear() - os.environ.update(old_environ) \ No newline at end of file + os.environ.update(old_environ) diff --git a/tests/unit/test_argumentvalidation.py b/tests/unit/test_argumentvalidation.py index 466a7d7d..1439a653 100644 --- a/tests/unit/test_argumentvalidation.py +++ b/tests/unit/test_argumentvalidation.py @@ -212,7 +212,6 @@ def test_invalid_container_port_protocol_mapping_fail(temp_cwd): assert not validate_arguments(builddir, args_list, "Port specification") - def test_docker_no_build_success(temp_cwd): """ Test to check if r2d succeeds with --no-build argument with not being able to connect to docker daemon