diff --git a/scripts/tests/test_wait_for_publication.py b/scripts/tests/test_wait_for_publication.py
index 23a4c14..cd1bc7e 100644
--- a/scripts/tests/test_wait_for_publication.py
+++ b/scripts/tests/test_wait_for_publication.py
@@ -130,24 +130,31 @@ class OBSTests(unittest.TestCase):
class CoprTests(unittest.TestCase):
- def test_migrated_repository_matches_exact_build_manifest(self):
+ def test_public_repository_must_match_the_selected_builds_signed_rpm(self):
checker = publication.Copr(arguments(build_id=42))
build = {"ownername": "yuezk", "projectname": "globalprotect-openconnect",
"state": "succeeded", "source_package": {"name": "globalprotect-openconnect", "version": "3.0.1-1"},
"chroots": ["fedora-44-x86_64"], "repo_url": "https://repo"}
status = {"state": "succeeded", "result_url": "https://results/42/"}
- package = {"name": "globalprotect-openconnect", "version": "3.0.1", "release": "1.fc44", "arch": "x86_64"}
- primary = ET.fromstring('''
- globalprotect-openconnectx86_64
- ''')
- with patch.object(publication, "api", side_effect=[build, status, {"packages": [package]}]), \
- patch.object(publication, "rpm_packages", return_value=primary):
- self.assertIn("1 targets built and published", checker.check())
- package["release"] = "1.fc45"
- with patch.object(publication, "api", side_effect=[build, status, {"packages": [package]}]), \
- patch.object(publication, "rpm_packages", return_value=primary):
- with self.assertRaisesRegex(publication.Pending, "Waiting for Copr build 42"):
- checker.check()
+ digest = "a" * 64
+ artifacts = {"count": 1, "results": [{"release": "1.fc44", "sha256": digest}]}
+ for release, published_digest, matches in [
+ ("1.fc44", digest, True),
+ ("1.fc44", "b" * 64, False),
+ ("1.fc45", digest, False)]:
+ with self.subTest(release=release, published_digest=published_digest):
+ primary = ET.fromstring(f'''
+ globalprotect-openconnectx86_64
+ {published_digest}
+ ''')
+ with patch.object(publication, "api", side_effect=[build, status, artifacts]) as api, \
+ patch.object(publication, "rpm_packages", return_value=primary):
+ if matches:
+ self.assertIn("1 targets built and published", checker.check())
+ else:
+ with self.assertRaisesRegex(publication.Pending, "Waiting for Copr build 42"):
+ checker.check()
+ self.assertEqual(api.call_args.kwargs["pulp_label_select"], "build_id=42,chroot=fedora-44-x86_64")
def test_unselected_chroot_cannot_be_hidden_by_verification(self):
checker = publication.Copr(arguments(build_id=42, chroots=["fedora-44-x86_64"]))
diff --git a/scripts/wait-for-publication.py b/scripts/wait-for-publication.py
index 51ba144..cc33fc0 100644
--- a/scripts/wait-for-publication.py
+++ b/scripts/wait-for-publication.py
@@ -84,7 +84,7 @@ def rpm_packages(base_url):
return ET.fromstring(unpack(content, location))
-def rpm_present(base_url, package, version, arch, release_matches):
+def rpm_present(base_url, package, version, arch, release_matches, *, sha256=None):
namespace = {"rpm": "http://linux.duke.edu/metadata/common"}
for entry in rpm_packages(base_url).findall("rpm:package", namespace):
info = entry.find("rpm:version", namespace)
@@ -92,6 +92,10 @@ def rpm_present(base_url, package, version, arch, release_matches):
entry.findtext("rpm:arch", namespaces=namespace) != arch or
info.get("ver") != version or not release_matches(info.get("rel", ""))):
continue
+ if sha256 is not None:
+ digest = entry.find("rpm:checksum[@type='sha256']", namespace)
+ if digest is None or digest.text != sha256:
+ continue
return True
return False
@@ -251,16 +255,23 @@ class Copr:
raise Pending(f"Copr {chroot}: {status['state']}; {link}")
base = build["repo_url"].rstrip("/") + "/" + chroot
arch = chroot.rsplit("-", 1)[1]
- packages = api(urljoin(status["result_url"], "results.json"))["packages"]
- package = next((item for item in packages
- if item["name"] == args.package and item["version"] == args.version
- and item["arch"] == arch
- and (item["release"] == args.revision
- or item["release"].startswith(args.revision + "."))), None)
- if package is None:
- raise Failed(f"Copr build {args.build_id} has no requested package for {chroot}")
+ # Pulp labels the signed RPM with the producing build and chroot.
+ artifacts = api("https://packages.redhat.com/api/pulp/public-copr/api/v3/content/rpm/packages/",
+ pulp_label_select=f"build_id={args.build_id},chroot={chroot}",
+ name=args.package, version=args.version, arch=arch, fields="release,sha256")
+ if not artifacts["count"]:
+ raise Pending(f"Waiting for the signed RPM from Copr build {args.build_id} for {chroot}")
+ if artifacts["count"] != 1:
+ raise Failed(f"Ambiguous RPMs from Copr build {args.build_id} for {chroot}")
+ artifact = artifacts["results"][0]
+ release = artifact["release"]
+ if release != args.revision and not release.startswith(args.revision + "."):
+ raise Failed(f"Copr build {args.build_id} has an unexpected RPM revision for {chroot}")
+ digest = artifact["sha256"]
+ if not digest or not re.fullmatch(r"[0-9a-f]{64}", digest):
+ raise Failed(f"Missing signed RPM checksum for Copr build {args.build_id} for {chroot}")
if not rpm_present(base, args.package, args.version, arch,
- lambda release: release == package["release"]):
+ lambda value: value == release, sha256=digest):
raise Pending(f"Waiting for Copr build {args.build_id} in {base}")
return f"Copr build {args.build_id}: {len(build['chroots'])} targets built and published; {link}"