Skip to content

Commit

Permalink
fix: evaluate Trusted Publisher events correctly (pypi#14852)
Browse files Browse the repository at this point in the history
  • Loading branch information
miketheman authored Nov 3, 2023
1 parent 520fe43 commit a5cdcde
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
1 change: 1 addition & 0 deletions tests/common/db/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class Meta:
model = File.Event

source = factory.SubFactory(FileFactory)
additional = {"publisher_url": None}


class RoleFactory(WarehouseFactory):
Expand Down
5 changes: 1 addition & 4 deletions tests/unit/packaging/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,9 @@ def test_trusted_published_all(self, db_session):
DBFileEventFactory.create(
source=release_file,
tag="fake:event",
additional={},
)

# Without the `publisher_url` key, not considered trusted published
# Without a `publisher_url` value, not considered trusted published
assert not release.trusted_published

DBFileEventFactory.create(
Expand All @@ -560,7 +559,6 @@ def test_trusted_published_mixed(self, db_session):
DBFileEventFactory.create(
source=rfile_1,
tag="fake:event",
additional={},
)
DBFileEventFactory.create(
source=rfile_2,
Expand Down Expand Up @@ -656,7 +654,6 @@ def test_published_via_trusted_publisher(self, db_session):
DBFileEventFactory.create(
source=rfile,
tag="fake:event",
additional={},
)

# Without the `publisher_url` key, not considered trusted published
Expand Down
2 changes: 1 addition & 1 deletion warehouse/packaging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def uploaded_via_trusted_publisher(self) -> bool:
"""Return True if the file was uploaded via a trusted publisher."""
return (
self.events.where(
self.Event.additional.has_key("publisher_url") # type: ignore[attr-defined] # noqa E501
self.Event.additional.op("->>")("publisher_url").is_not(None) # type: ignore[attr-defined] # noqa E501
).count()
> 0
)
Expand Down

0 comments on commit a5cdcde

Please sign in to comment.