Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform case-insensitive hash comparisons #12729

Merged
merged 1 commit into from
Jul 9, 2024
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
1 change: 1 addition & 0 deletions news/12680.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Perform hash comparisons in a case-insensitive manner.
2 changes: 1 addition & 1 deletion src/pip/_internal/utils/hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, hashes: Optional[Dict[str, List[str]]] = None) -> None:
if hashes is not None:
for alg, keys in hashes.items():
# Make sure values are always sorted (to ease equality checks)
allowed[alg] = sorted(keys)
allowed[alg] = [k.lower() for k in sorted(keys)]
self._allowed = allowed

def __and__(self, other: "Hashes") -> "Hashes":
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ def test_incorrect_metadata_hash(
)
assert result.returncode != 0
expected_msg = f"""\
Expected sha256 WRONG-HASH
Expected sha256 wrong-hash
Got {real_hash}"""
assert expected_msg in result.stderr

Expand Down
12 changes: 12 additions & 0 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,18 @@ def test_hashed_install_failure(script: PipTestEnvironment, tmpdir: Path) -> Non
assert len(result.files_created) == 0


def test_case_insensitive_hashed_install_success(
script: PipTestEnvironment, tmpdir: Path
) -> None:
"""Test that hashes that differ only by case don't halt installation."""
with requirements_file(
"simple2==1.0 --hash=sha256:9336AF72CA661E6336EB87BC7DE3E8844D853E"
"3848C2B9BBD2E8BF01DB88C2C7\n",
tmpdir,
) as reqs_file:
script.pip_install_local("-r", reqs_file.resolve())


def test_link_hash_pass_require_hashes(
script: PipTestEnvironment, shared_data: TestData
) -> None:
Expand Down
Loading