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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion functest_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pytest<10
pytest-custom_exit_code
pytest-xdist
pysequoia
python-gnupg
Comment thread
jobselko marked this conversation as resolved.
proxy.py~=2.4.10
trustme~=1.2.1

Expand Down
2 changes: 1 addition & 1 deletion pulpcore/app/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ def store(key_ids):
sig_data = signature.read()

try:
sig = Sig.from_bytes(sig_data)
if detached_data is not None:
sig = Sig.from_bytes(sig_data)
result = verify(file=detached_data, store=store, signature=sig)
else:
result = verify(bytes=sig_data, store=store)
Expand Down
47 changes: 9 additions & 38 deletions pulpcore/pytest_plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import aiohttp
import asyncio
import gnupg
import json
import os
import pathlib
Expand Down Expand Up @@ -1147,21 +1148,6 @@ def _sign_with_ascii_armored_detached_signing_service(filename):
return _sign_with_ascii_armored_detached_signing_service


class _GpgCompat:
"""Wrapper around a pysequoia Cert that provides the python-gnupg GPG interface needed by
downstream plugins (e.g. pulp_container) which access .gnupghome and .export_keys()."""

def __init__(self, cert, gnupghome):
self.cert = cert
self.gnupghome = gnupghome

def export_keys(self, keyids=None):
return str(self.cert)

def __str__(self):
return str(self.cert)


@pytest.fixture(scope="session")
def signing_gpg_metadata(signing_gpg_homedir_path):
"""A fixture that returns a GPG instance and related metadata (i.e., fingerprint, keyid)."""
Expand All @@ -1177,37 +1163,22 @@ def signing_gpg_metadata(signing_gpg_homedir_path):
with suppress(FileNotFoundError, PermissionError):
key_file.write_text(private_key_data)

from pysequoia import Cert
gpg = gnupg.GPG(gnupghome=signing_gpg_homedir_path)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use python-gnupg in functional tests, it's fine for now. Not worth trying to replace with layers of compat right now.

gpg.import_keys(private_key_data)

cert = Cert.from_bytes(private_key_data.encode())
fingerprint = cert.fingerprint.upper()
keyid = fingerprint[-16:]

gpg_cmd = ["gpg", "--homedir", str(signing_gpg_homedir_path)]
subprocess.run(
gpg_cmd + ["--import"],
input=private_key_data,
capture_output=True,
text=True,
check=True,
)
subprocess.run(
gpg_cmd + ["--import-ownertrust"],
input=f"{fingerprint}:6:\n",
capture_output=True,
text=True,
check=True,
)
key = gpg.list_keys()[0]
fingerprint = key["fingerprint"]
keyid = key["keyid"]

gpg = _GpgCompat(cert, str(signing_gpg_homedir_path))
gpg.trust_keys(fingerprint, "TRUST_ULTIMATE")
return gpg, fingerprint, keyid


@pytest.fixture(scope="session")
def pulp_trusted_public_key(signing_gpg_metadata):
"""Fixture to extract the ascii armored trusted public test key."""
gpg, _, keyid = signing_gpg_metadata
return str(gpg)
return gpg.export_keys([keyid])


@pytest.fixture(scope="session")
Expand All @@ -1223,7 +1194,7 @@ def _ascii_armored_detached_signing_service_name(
signing_gpg_homedir_path,
):
service_name = str(uuid.uuid4())
_, fingerprint, keyid = signing_gpg_metadata
_gpg, fingerprint, _keyid = signing_gpg_metadata

cmd = (
"pulpcore-manager",
Expand Down
Loading