Skip to content

Commit ad29ffd

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent aa948e0 commit ad29ffd

File tree

2 files changed

+52
-25
lines changed

2 files changed

+52
-25
lines changed

tests/norun/test_registry.py

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import shutil
55
import socket
66
import subprocess
7-
from tempfile import TemporaryDirectory
8-
from base64 import b64encode
97
import time
10-
import bcrypt
8+
from base64 import b64encode
119
from pathlib import Path
10+
from tempfile import TemporaryDirectory
1211

12+
import bcrypt
1313
import pytest
1414
import requests
1515

@@ -87,7 +87,9 @@ def registry(host_ip):
8787
port = get_free_port()
8888
username = "user"
8989
password = secrets.token_hex(16)
90-
bcrypted_pw = bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt(rounds=12)).decode("utf-8")
90+
bcrypted_pw = bcrypt.hashpw(
91+
password.encode("utf-8"), bcrypt.gensalt(rounds=12)
92+
).decode("utf-8")
9193

9294
# We put our password here, and mount it into the container.
9395
# put it in current dir than in /tmp because on macos, current dir is likely to
@@ -100,12 +102,22 @@ def registry(host_ip):
100102
registry_image = "registry:3.0.0-rc.3"
101103
subprocess.check_call(["docker", "pull", registry_image])
102104

103-
cmd = ["docker", "run", "--rm",
104-
"-e", "REGISTRY_AUTH=htpasswd",
105-
"-e", "REGISTRY_AUTH_HTPASSWD_REALM=basic",
106-
"-e", "REGISTRY_AUTH_HTPASSWD_PATH=/opt/htpasswd/htpasswd.conf",
107-
"--mount", f"type=bind,src={htpasswd_dir},dst=/opt/htpasswd",
108-
"-p", f"{port}:5000", registry_image]
105+
cmd = [
106+
"docker",
107+
"run",
108+
"--rm",
109+
"-e",
110+
"REGISTRY_AUTH=htpasswd",
111+
"-e",
112+
"REGISTRY_AUTH_HTPASSWD_REALM=basic",
113+
"-e",
114+
"REGISTRY_AUTH_HTPASSWD_PATH=/opt/htpasswd/htpasswd.conf",
115+
"--mount",
116+
f"type=bind,src={htpasswd_dir},dst=/opt/htpasswd",
117+
"-p",
118+
f"{port}:5000",
119+
registry_image,
120+
]
109121
proc = subprocess.Popen(cmd)
110122
health_url = f"http://{host_ip}:{port}/v2"
111123
# Wait for the registry to actually come up
@@ -144,19 +156,24 @@ def test_registry_explicit_creds(registry, dind):
144156
os.environ["DOCKER_HOST"] = docker_host
145157
os.environ["DOCKER_CERT_PATH"] = str(cert_dir / "client")
146158
os.environ["DOCKER_TLS_VERIFY"] = "1"
147-
os.environ["CONTAINER_ENGINE_REGISTRY_CREDENTIALS"] = json.dumps({
148-
"registry": f"http://{registry_host}",
149-
"username": username,
150-
"password": password
151-
})
159+
os.environ["CONTAINER_ENGINE_REGISTRY_CREDENTIALS"] = json.dumps(
160+
{
161+
"registry": f"http://{registry_host}",
162+
"username": username,
163+
"password": password,
164+
}
165+
)
152166
r2d.start()
153167

154-
155-
proc = subprocess.run(["docker", "manifest", "inspect", "--insecure", image_name])
168+
proc = subprocess.run(
169+
["docker", "manifest", "inspect", "--insecure", image_name]
170+
)
156171
assert proc.returncode == 0
157172

158173
# Validate that we didn't leak our registry creds into existing docker config
159-
docker_config_path = Path(os.environ.get("DOCKER_CONFIG", "~/.docker/config.json")).expanduser()
174+
docker_config_path = Path(
175+
os.environ.get("DOCKER_CONFIG", "~/.docker/config.json")
176+
).expanduser()
160177
if docker_config_path.exists():
161178
# Just check that our randomly generated password is not in this file
162179
# 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):
184201
os.environ["DOCKER_CERT_PATH"] = str(cert_dir / "client")
185202
os.environ["DOCKER_TLS_VERIFY"] = "1"
186203
with TemporaryDirectory() as d:
187-
(Path(d) / "config.json").write_text(json.dumps(
188-
({"auths":{f"http://{registry_host}":{"auth":b64encode(f"{username}:{password}".encode()).decode()}}})
189-
))
204+
(Path(d) / "config.json").write_text(
205+
json.dumps(
206+
{
207+
"auths": {
208+
f"http://{registry_host}": {
209+
"auth": b64encode(
210+
f"{username}:{password}".encode()
211+
).decode()
212+
}
213+
}
214+
}
215+
)
216+
)
190217
os.environ["DOCKER_CONFIG"] = d
191218
r2d.start()
192219

193-
194-
proc = subprocess.run(["docker", "manifest", "inspect", "--insecure", image_name])
220+
proc = subprocess.run(
221+
["docker", "manifest", "inspect", "--insecure", image_name]
222+
)
195223
assert proc.returncode == 0
196224
finally:
197225
os.environ.clear()
198-
os.environ.update(old_environ)
226+
os.environ.update(old_environ)

tests/unit/test_argumentvalidation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ def test_invalid_container_port_protocol_mapping_fail(temp_cwd):
212212
assert not validate_arguments(builddir, args_list, "Port specification")
213213

214214

215-
216215
def test_docker_no_build_success(temp_cwd):
217216
"""
218217
Test to check if r2d succeeds with --no-build argument with not being able to connect to docker daemon

0 commit comments

Comments
 (0)