Skip to content

Commit 7e3139a

Browse files
committed
Cleanup code
1 parent 149193b commit 7e3139a

5 files changed

Lines changed: 53 additions & 42 deletions

File tree

pulp_deb/app/models/signing_service.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import tempfile
88

99
from pulpcore.plugin.models import SigningService
10-
from importlib_resources import files
10+
from importlib.resources import files
1111

1212

1313
def prepare_gpg(temp_directory_name, public_key, pubkey_fingerprint):
@@ -215,11 +215,14 @@ def validate(self):
215215
# Prepare GPG:
216216
gpg = prepare_gpg(temp_directory_name, self.public_key, self.pubkey_fingerprint)
217217

218-
self._validate_deb_package(signed_deb, self.pubkey_fingerprint, temp_directory_name, gpg)
218+
self._validate_deb_package(
219+
signed_deb, self.pubkey_fingerprint, temp_directory_name, gpg
220+
)
219221

220-
221222
@staticmethod
222-
def _validate_deb_package(deb_package_path: str, pubkey_fingerprint: str, temp_directory_name: str, gpg: gnupg.GPG):
223+
def _validate_deb_package(
224+
deb_package_path: str, pubkey_fingerprint: str, temp_directory_name: str, gpg: gnupg.GPG
225+
):
223226
"""
224227
Validate that the deb package at @deb_package_path is correctly signed.
225228
@@ -245,8 +248,10 @@ def _validate_deb_package(deb_package_path: str, pubkey_fingerprint: str, temp_d
245248
with (temp_dir / "_gpgorigin").open("rb") as gpgorigin:
246249
verified = gpg.verify_file(gpgorigin, str(temp_dir / "combined"))
247250
if not verified.valid:
248-
raise Exception(f"GPG Verification of the signed package {deb_package_path} failed!")
251+
raise Exception(
252+
f"GPG Verification of the signed package {deb_package_path} failed!"
253+
)
249254
if verified.pubkey_fingerprint != pubkey_fingerprint:
250255
raise Exception(
251256
f"'{deb_package_path}' appears to have been signed using the wrong key!"
252-
)
257+
)

pulp_deb/app/viewsets/content.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from gettext import gettext as _ # noqa
22

33
from django_filters import Filter
4-
from pulpcore.app.serializers import AsyncOperationResponseSerializer
54
from pulpcore.plugin.models import Repository, RepositoryVersion, PulpTemporaryFile
5+
from pulpcore.plugin.serializers import AsyncOperationResponseSerializer
66
from pulpcore.plugin.serializers.content import ValidationError
77
from pulpcore.plugin.tasking import dispatch
88
from pulpcore.plugin.viewsets import (

pulp_deb/tests/functional/api/test_package_signing.py

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
import hashlib
33
import shutil
44
import uuid
5-
from importlib_resources import files
65

76
from pulp_deb.app.models import AptPackageSigningService
87
import requests
98
from pulp_deb.tests.functional.utils import get_local_package_absolute_path
109
import pytest
1110

11+
1212
@pytest.mark.parallel
1313
def test_register_rpm_package_signing_service(deb_package_signing_service):
1414
"""
1515
Register a sample rpmsign-based signing service and validate it works.
1616
"""
1717
service = deb_package_signing_service
1818
assert "/api/v3/signing-services/" in service.pulp_href
19-
19+
20+
2021
@dataclass
2122
class GPGMetadata:
2223
pubkey: str
@@ -45,7 +46,8 @@ def signing_gpg_extra(signing_gpg_metadata):
4546
GPGMetadata(pubkey_a, fingerprint_a, fingerprint_a[-8:]),
4647
GPGMetadata(pubkey_b, fingerprint_b, fingerprint_b[-8:]),
4748
)
48-
49+
50+
4951
@pytest.mark.parallel
5052
def test_sign_package_on_upload(
5153
tmp_path,
@@ -73,7 +75,9 @@ def test_sign_package_on_upload(
7375
tmp_path,
7476
)
7577
with pytest.raises(Exception, match="No such file or directory:.*"):
76-
AptPackageSigningService._validate_deb_package(file_to_upload, gpg_metadata_a.fingerprint, str(tmp_path), gpg)
78+
AptPackageSigningService._validate_deb_package(
79+
file_to_upload, gpg_metadata_a.fingerprint, str(tmp_path), gpg
80+
)
7781

7882
# Upload Package to Repository
7983
# The same file is uploaded, but signed with different keys each time
@@ -95,44 +99,38 @@ def test_sign_package_on_upload(
9599
downloaded_package.write_bytes(
96100
download_content_unit(distribution.base_path, "pool/upload/f/frigg/frigg_1.0_ppc64.deb")
97101
)
98-
AptPackageSigningService._validate_deb_package(str(downloaded_package), fingerprint, str(tmp_path), gpg)
99-
102+
AptPackageSigningService._validate_deb_package(
103+
str(downloaded_package), fingerprint, str(tmp_path), gpg
104+
)
105+
100106
# Test release override
101107
repository = deb_repository_factory(
102108
package_signing_service=deb_package_signing_service.pulp_href,
103109
package_signing_fingerprint=gpg_metadata_a.fingerprint,
104-
package_signing_fingerprint_release_overrides={"test": gpg_metadata_b.fingerprint}
105-
)
106-
107-
deb_release_factory(
108-
"test", "test", "test", repository=repository.pulp_href
109-
)
110-
deb_release_factory(
111-
"test2", "test2", "test2", repository=repository.pulp_href
110+
package_signing_fingerprint_release_overrides={"test": gpg_metadata_b.fingerprint},
112111
)
113-
112+
113+
deb_release_factory("test", "test", "test", repository=repository.pulp_href)
114+
deb_release_factory("test2", "test2", "test2", repository=repository.pulp_href)
115+
114116
deb_package_factory(
115117
file=file_to_upload,
116118
repository=repository.pulp_href,
117119
distribution="test",
118120
)
119-
# uncommenting this line causes a failure since it overrides the existing package with a version signed with fingerprint_a
120-
# deb_package_factory(
121-
# file=file_to_upload,
122-
# repository=repository.pulp_href,
123-
# distribution="test2",
124-
# )
125-
121+
126122
# Verify that the final served package is signed
127123
publication = deb_publication_factory(repository)
128124
distribution = deb_distribution_factory(publication=publication)
129125
downloaded_package = tmp_path / "package.deb"
130126
downloaded_package.write_bytes(
131127
download_content_unit(distribution.base_path, "pool/upload/f/frigg/frigg_1.0_ppc64.deb")
132128
)
133-
AptPackageSigningService._validate_deb_package(str(downloaded_package), gpg_metadata_b.fingerprint, str(tmp_path), gpg)
134-
135-
129+
AptPackageSigningService._validate_deb_package(
130+
str(downloaded_package), gpg_metadata_b.fingerprint, str(tmp_path), gpg
131+
)
132+
133+
136134
@pytest.fixture
137135
def pulpcore_chunked_file_factory(tmp_path):
138136
"""Returns a function to create chunks from file to be uploaded."""
@@ -189,7 +187,8 @@ def _upload_chunks(size, chunks, sha256, include_chunk_sha256=False):
189187
return upload
190188

191189
yield _upload_chunks
192-
190+
191+
193192
def test_sign_chunked_package_on_upload(
194193
tmp_path,
195194
download_content_unit,
@@ -217,7 +216,9 @@ def test_sign_chunked_package_on_upload(
217216
tmp_path,
218217
)
219218
with pytest.raises(Exception, match="No such file or directory:.*"):
220-
AptPackageSigningService._validate_deb_package(file_to_upload, gpg_metadata_a.fingerprint, str(tmp_path), gpg)
219+
AptPackageSigningService._validate_deb_package(
220+
file_to_upload, gpg_metadata_a.fingerprint, str(tmp_path), gpg
221+
)
221222

222223
# Upload Package to Repository
223224
# The same file is uploaded, but signed with different keys each time
@@ -244,4 +245,6 @@ def test_sign_chunked_package_on_upload(
244245
downloaded_package.write_bytes(
245246
download_content_unit(distribution.base_path, "pool/upload/f/frigg/frigg_1.0_ppc64.deb")
246247
)
247-
AptPackageSigningService._validate_deb_package(str(downloaded_package), fingerprint, str(tmp_path), gpg)
248+
AptPackageSigningService._validate_deb_package(
249+
str(downloaded_package), fingerprint, str(tmp_path), gpg
250+
)

pulp_deb/tests/functional/conftest.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
import subprocess
99
import uuid
1010

11-
from pulp_deb.tests.functional.constants import DEB_SIGNING_SCRIPT_STRING, DEB_PACKAGE_SIGNING_SCRIPT_STRING
11+
from pulp_deb.tests.functional.constants import (
12+
DEB_SIGNING_SCRIPT_STRING,
13+
DEB_PACKAGE_SIGNING_SCRIPT_STRING,
14+
)
1215
from pulpcore.client.pulp_deb import (
1316
ContentGenericContentsApi,
1417
ContentPackagesApi,
@@ -689,8 +692,6 @@ def _deb_domain_factory(name=None):
689692
return _deb_domain_factory
690693

691694

692-
693-
694695
@pytest.fixture(scope="session")
695696
def package_signing_script_path(signing_script_temp_dir, signing_gpg_homedir_path):
696697
signing_script_file = signing_script_temp_dir / "sign-deb-package.sh"
@@ -702,6 +703,7 @@ def package_signing_script_path(signing_script_temp_dir, signing_gpg_homedir_pat
702703

703704
return signing_script_file
704705

706+
705707
@pytest.fixture(scope="session")
706708
def signing_script_temp_dir(tmp_path_factory):
707709
return tmp_path_factory.mktemp("sigining_script_dir")
@@ -740,6 +742,7 @@ def _sign_with_deb_package_signing_service(filename):
740742

741743
return _sign_with_deb_package_signing_service
742744

745+
743746
@pytest.fixture(scope="session")
744747
def _deb_package_signing_service_name(
745748
bindings_cfg,
@@ -767,7 +770,7 @@ def _deb_package_signing_service_name(
767770
stdout=subprocess.PIPE,
768771
stderr=subprocess.PIPE,
769772
)
770-
773+
771774
assert completed_process.returncode == 0
772775

773776
yield service_name
@@ -785,9 +788,9 @@ def _deb_package_signing_service_name(
785788
stderr=subprocess.PIPE,
786789
)
787790

791+
788792
@pytest.fixture
789793
def deb_package_signing_service(_deb_package_signing_service_name, pulpcore_bindings):
790794
return pulpcore_bindings.SigningServicesApi.list(
791795
name=_deb_package_signing_service_name
792796
).results[0]
793-

pulp_deb/tests/functional/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,12 @@ def _clean_dict(d):
451451
export GNUPGHOME="HOMEDIRHERE"
452452
GPG_NAME="${PULP_SIGNING_KEY_FINGERPRINT}"
453453
454-
455454
# Sign the package
456455
tmpdir=$(mktemp -d)
457456
ctrl=$(ar t "$1" | grep -m1 '^control\.tar\.')
458457
data=$(ar t "$1" | grep -m1 '^data\.tar\.')
459-
ar p "$1" debian-binary "$ctrl" "$data" | gpg --openpgp --detach-sign --default-key "$GPG_NAME" > "$tmpdir/_gpgorigin"
458+
ar p "$1" debian-binary "$ctrl" "$data" | \
459+
gpg --openpgp --detach-sign --default-key "$GPG_NAME" > "$tmpdir/_gpgorigin"
460460
ar r "$1" "$tmpdir/_gpgorigin" >/dev/null
461461
462462
# Check the exit status

0 commit comments

Comments
 (0)