Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/pypi_attestations/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ def verify(
except ValueError as e:
raise VerificationError(f"invalid subject: {str(e)}")

normalized = _ultranormalize_dist_filename(dist.name)
try:
normalized = _ultranormalize_dist_filename(dist.name)
except ValueError as e:
raise VerificationError(f"invalid distribution name: {str(e)}")

if subject_name != normalized:
raise VerificationError(
f"subject does not match distribution name: {subject_name} != {normalized}"
Expand Down
35 changes: 35 additions & 0 deletions test/test_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,41 @@ def test_verify_subject_invalid_name(self) -> None:
with pytest.raises(impl.VerificationError, match="invalid subject: Invalid wheel filename"):
attestation.verify(verifier, pol, artifact_path)

def test_verify_distribution_invalid_name(self, tmp_path: Path) -> None:
statement = (
_StatementBuilder() # noqa: SLF001
.subjects(
[
_Subject(
name=artifact_path.name,
digest=_DigestSet(root={"sha256": "abcd"}),
),
]
)
.predicate_type("foo")
.build()
._inner.model_dump_json()
)

verifier = pretend.stub(
verify_dsse=pretend.call_recorder(
lambda bundle, policy: (
"application/vnd.in-toto+json",
statement.encode(),
)
)
)
pol = pretend.stub()

attestation = impl.Attestation.model_validate_json(attestation_path.read_text())
bad_artifact = tmp_path / "bad.whl"
bad_artifact.write_bytes(artifact_path.read_bytes())

with pytest.raises(
impl.VerificationError, match="invalid distribution name: Invalid wheel filename"
):
attestation.verify(verifier, pol, bad_artifact)

def test_verify_unknown_attestation_type(self) -> None:
statement = (
_StatementBuilder() # noqa: SLF001
Expand Down