Skip to content

Commit 2ff3f4e

Browse files
committed
Add test to ensure that artifact downloading in _sign_rpm_content works
Create a test that syncs a repository, then syncs a completely different repository, and then re-syncs the first. Artifacts will be created during the first sync that will be orphaned (since signing creates a new artifact), and then, on the third sync, packages will be deduped to these artifacts. This test verifies that the artifact downloading in _sign_rpm_content works with these deduped artifacts. Signed-off-by: Jonathan Dieter <jdieter@ciq.com>
1 parent d5528e6 commit 2ff3f4e

1 file changed

Lines changed: 119 additions & 0 deletions

File tree

pulp_rpm/tests/functional/api/test_package_signing.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
RPM_PACKAGE_FILENAME,
1515
RPM_UNSIGNED_URL,
1616
RPM_UNSIGNED_MODIFIED_FIXTURE_URL,
17+
RPM_COMPLEX_FIXTURE_URL,
1718
RPM_PACKAGE_CONTENT_NAME,
1819
)
1920
from pulp_rpm.tests.functional.utils import get_package_repo_path
@@ -509,3 +510,121 @@ def test_no_resync_of_packages_on_second_sync(
509510
}
510511

511512
assert original_packages["zebra"] == mutated_packages["zebra"]
513+
514+
515+
def test_do_resync_of_packages_on_third_sync(
516+
init_and_sync,
517+
tmp_path,
518+
gen_object_with_cleanup,
519+
download_content_unit,
520+
signing_gpg_extra,
521+
rpm_package_signing_service,
522+
rpm_package_api,
523+
rpm_repository_api,
524+
rpm_repository_factory,
525+
rpm_publication_factory,
526+
rpm_distribution_factory,
527+
delete_orphans_pre,
528+
get_content,
529+
):
530+
"""
531+
Ensure that a third sync where the second sync is completely different does successfully sign
532+
all packages again. This is primarily to test that the artifact downloading in
533+
_sign_rpm_content is working correctly.
534+
"""
535+
from pulp_rpm.app.shared_utils import RpmTool
536+
537+
# Setup GPG and RPM tool
538+
gpg_a, _ = signing_gpg_extra
539+
540+
rpm_tool = RpmTool(tmp_path)
541+
rpm_tool.import_pubkey_string(gpg_a.pubkey)
542+
543+
# Create repository with package signing service configured
544+
repository = rpm_repository_factory(
545+
package_signing_service=rpm_package_signing_service.pulp_href,
546+
package_signing_fingerprint=gpg_a.fingerprint,
547+
)
548+
init_and_sync(
549+
repository=repository,
550+
sync_policy="mirror_content_only",
551+
)
552+
553+
# Get synced packages - refresh repository to get latest version
554+
updated_repository = rpm_repository_api.read(repository.pulp_href)
555+
packages = rpm_package_api.list(repository_version=updated_repository.latest_version_href)
556+
assert packages.count > 0, "No packages were synced"
557+
558+
# Test the first package to verify it was signed during sync
559+
test_package = packages.results[0]
560+
561+
# Verify that the final served package is signed
562+
publication = rpm_publication_factory(repository=repository.pulp_href)
563+
distribution = rpm_distribution_factory(publication=publication.pulp_href)
564+
downloaded_package = tmp_path / "package.rpm"
565+
downloaded_package.write_bytes(
566+
download_content_unit(
567+
distribution.base_path, get_package_repo_path(test_package.location_href)
568+
)
569+
)
570+
assert rpm_tool.verify_signature(downloaded_package)
571+
572+
# Save the content information of the packages from the original sync
573+
original_packages = {
574+
content["name"]: content
575+
for content in get_content(updated_repository)["present"][RPM_PACKAGE_CONTENT_NAME]
576+
}
577+
578+
# Second sync with completely different content
579+
init_and_sync(
580+
repository=repository,
581+
url=RPM_COMPLEX_FIXTURE_URL,
582+
sync_policy="mirror_content_only",
583+
)
584+
# Get synced packages - refresh repository to get latest version
585+
updated_repository = rpm_repository_api.read(repository.pulp_href)
586+
packages = rpm_package_api.list(repository_version=updated_repository.latest_version_href)
587+
assert packages.count > 0, "No packages were synced"
588+
589+
# Test the first package to verify it was signed during sync
590+
test_package = packages.results[0]
591+
592+
# Verify that the final served package is signed
593+
publication = rpm_publication_factory(repository=repository.pulp_href)
594+
distribution = rpm_distribution_factory(publication=publication.pulp_href)
595+
downloaded_package = tmp_path / "package.rpm"
596+
downloaded_package.write_bytes(
597+
download_content_unit(
598+
distribution.base_path, get_package_repo_path(test_package.location_href)
599+
)
600+
)
601+
assert rpm_tool.verify_signature(downloaded_package)
602+
603+
# Third sync with the same content as the first sync
604+
init_and_sync(repository=repository, sync_policy="mirror_content_only")
605+
# Get synced packages - refresh repository to get latest version
606+
updated_repository = rpm_repository_api.read(repository.pulp_href)
607+
packages = rpm_package_api.list(repository_version=updated_repository.latest_version_href)
608+
assert packages.count > 0, "No packages were synced"
609+
610+
# Test the first package to verify it was signed during sync
611+
test_package = packages.results[0]
612+
613+
# Verify that the final served package is signed
614+
publication = rpm_publication_factory(repository=repository.pulp_href)
615+
distribution = rpm_distribution_factory(publication=publication.pulp_href)
616+
downloaded_package = tmp_path / "package.rpm"
617+
downloaded_package.write_bytes(
618+
download_content_unit(
619+
distribution.base_path, get_package_repo_path(test_package.location_href)
620+
)
621+
)
622+
assert rpm_tool.verify_signature(downloaded_package)
623+
624+
# Test that the zebra package was re-synced this time
625+
mutated_packages = {
626+
content["name"]: content
627+
for content in get_content(updated_repository)["present"][RPM_PACKAGE_CONTENT_NAME]
628+
}
629+
630+
assert original_packages["zebra"] != mutated_packages["zebra"]

0 commit comments

Comments
 (0)