Skip to content

Commit bab78b7

Browse files
gerrod3cursoragent
andcommitted
Fix provenance sync to use Pulp's extended Provenance model
Sync was validating provenance with pypi_attestations.Provenance, which rejects Pulp User publishers created during upload. Use the extended model from pulp_python.app.provenance instead. Add a cross-domain functional test that uploads attestations in one domain and syncs provenance into a repository in another. Assisted-by: Cursor Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f168ae8 commit bab78b7

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed provenance sync failing when syncing Pulp-created attestations that use a `Pulp User` publisher.

‎pulp_python/app/tasks/sync.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from bandersnatch.mirror import Mirror
1010
from lxml.etree import LxmlError
1111
from packaging.requirements import Requirement
12-
from pypi_attestations import Provenance
1312
from pypi_simple import IndexPage
1413

1514
from pulpcore.plugin.download import HttpDownloader
@@ -28,6 +27,7 @@
2827
PythonPackageContent,
2928
PythonRemote,
3029
)
30+
from pulp_python.app.provenance import Provenance
3131
from pulp_python.app.utils import PYPI_LAST_SERIAL, aget_remote_simple_page, parse_metadata
3232

3333
logger = logging.getLogger(__name__)

‎pulp_python/tests/functional/api/test_attestations.py‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import requests
99
from pypi_simple import PyPISimple
1010

11+
from pulpcore.app import settings # noqa: TID251
1112
from pulpcore.tests.functional.utils import PulpTaskError
1213

1314

@@ -154,6 +155,55 @@ def test_attestation_sync_upload(python_bindings, twine_package, download_python
154155
assert att_bundle["publisher"]["kind"] == "Pulp User"
155156

156157

158+
@pytest.mark.skipif(not settings.DOMAIN_ENABLED, reason="Domain not enabled")
159+
@pytest.mark.parallel
160+
def test_sync_pulp_created_provenance(
161+
domain_factory,
162+
python_bindings,
163+
twine_package,
164+
python_repo_factory,
165+
python_distribution_factory,
166+
python_remote_factory,
167+
python_repo_with_sync,
168+
python_content_summary,
169+
monitor_task,
170+
):
171+
"""Test syncing provenance across domains from a Pulp upload."""
172+
source_domain = domain_factory()
173+
attestations = get_attestations(twine_package.provenance_url)
174+
source_repo = python_repo_factory(pulp_domain=source_domain.name)
175+
body = {
176+
"relative_path": twine_package.filename,
177+
"file_url": twine_package.url,
178+
"attestations": json.dumps(attestations),
179+
"repository": source_repo.pulp_href,
180+
}
181+
task = python_bindings.ContentPackagesApi.create(pulp_domain=source_domain.name, **body).task
182+
monitor_task(task)
183+
184+
source_distro = python_distribution_factory(
185+
repository=source_repo, pulp_domain=source_domain.name
186+
)
187+
dest_domain = domain_factory()
188+
remote = python_remote_factory(
189+
url=source_distro.base_url,
190+
provenance=True,
191+
includes=[f"twine=={twine_package.version}"],
192+
pulp_domain=dest_domain.name,
193+
)
194+
dest_repo = python_repo_with_sync(remote=remote, pulp_domain=dest_domain.name)
195+
196+
summary = python_content_summary(repository_version=dest_repo.latest_version_href)
197+
assert summary.present["python.provenance"]["count"] == 1
198+
199+
provs = python_bindings.ContentProvenanceApi.list(
200+
repository_version=dest_repo.latest_version_href,
201+
pulp_domain=dest_domain.name,
202+
)
203+
assert provs.count == 1
204+
assert provs.results[0].provenance["attestation_bundles"][0]["publisher"]["kind"] == "Pulp User"
205+
206+
157207
def test_attestation_twine_upload(
158208
pulpcore_bindings,
159209
python_content_summary,

0 commit comments

Comments
 (0)