|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 | import requests |
| 8 | +import rpm_rs |
8 | 9 |
|
9 | 10 | from pulpcore.client.pulp_rpm.exceptions import ApiException |
10 | 11 | from pulpcore.exceptions.validation import InvalidSignatureError |
@@ -399,6 +400,58 @@ def test_already_signed_package( |
399 | 400 | assert task_result.created_resources == [repo_two.latest_version_href] |
400 | 401 |
|
401 | 402 |
|
| 403 | +def test_signing_with_primary_key_fingerprint( |
| 404 | + tmp_path, |
| 405 | + delete_orphans_pre, |
| 406 | + monitor_task, |
| 407 | + signing_gpg_metadata, |
| 408 | + rpm_package_signing_service, |
| 409 | + rpm_repository_factory, |
| 410 | + rpm_repository_api, |
| 411 | + rpm_package_factory, |
| 412 | + rpm_package_api, |
| 413 | + pulpcore_bindings, |
| 414 | +): |
| 415 | + """Test that signing_keys is correct when package_signing_fingerprint is a primary key. |
| 416 | +
|
| 417 | + When the signing key has a dedicated signing subkey, GnuPG signs with the subkey. |
| 418 | + signing_keys should reflect the actual signature fingerprints from the artifact. |
| 419 | + """ |
| 420 | + gpg, signing_subkey_fpr, _ = signing_gpg_metadata |
| 421 | + primary_fpr = gpg.list_keys()[0]["fingerprint"] |
| 422 | + assert primary_fpr != signing_subkey_fpr, "Test requires a key with a separate signing subkey" |
| 423 | + |
| 424 | + prefixed_primary = f"v4:{primary_fpr}" |
| 425 | + |
| 426 | + repository = rpm_repository_factory( |
| 427 | + package_signing_service=rpm_package_signing_service.pulp_href, |
| 428 | + package_signing_fingerprint=prefixed_primary, |
| 429 | + ) |
| 430 | + |
| 431 | + created_package = rpm_package_factory(url=RPM_UNSIGNED_URL) |
| 432 | + modify_response = rpm_repository_api.modify( |
| 433 | + repository.pulp_href, {"add_content_units": [created_package.pulp_href]} |
| 434 | + ) |
| 435 | + monitor_task(modify_response.task) |
| 436 | + |
| 437 | + repository = rpm_repository_api.read(repository.pulp_href) |
| 438 | + signed_package = rpm_package_api.list( |
| 439 | + repository_version=repository.latest_version_href |
| 440 | + ).results[0] |
| 441 | + |
| 442 | + assert signed_package.pulp_href != created_package.pulp_href |
| 443 | + |
| 444 | + # Check the actual signatures on the artifact |
| 445 | + artifact_response = pulpcore_bindings.ArtifactsApi.read(signed_package.artifact) |
| 446 | + artifact_path = tmp_path / "signed.rpm" |
| 447 | + artifact_path.write_bytes(requests.get(artifact_response.file).content) |
| 448 | + pkg = rpm_rs.PackageMetadata.open(str(artifact_path)) |
| 449 | + sig_fingerprints = [f"v4:{s.fingerprint.upper()}" for s in pkg.signatures() if s.fingerprint] |
| 450 | + |
| 451 | + # signing_keys must match the actual signature fingerprints on the artifact |
| 452 | + assert signed_package.signing_keys == sig_fingerprints |
| 453 | + |
| 454 | + |
402 | 455 | def test_signed_repo_rejects_on_demand_content( |
403 | 456 | init_and_sync, |
404 | 457 | rpm_package_signing_service, |
|
0 commit comments