summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorStéphane Bidoul <stephane.bidoul@gmail.com>2023-03-25 14:18:44 +0100
committerStéphane Bidoul <stephane.bidoul@gmail.com>2023-04-14 08:03:48 +0200
commit40cd79d6e54d53bccfcad0b855cd87116de896b9 (patch)
tree585aabdf24e238a91bbc295aea1f977dd00ecabf /tests
parent8e2205d8495474df088d773b4658aa4a40aefcac (diff)
downloadpip-40cd79d6e54d53bccfcad0b855cd87116de896b9.tar.gz
Check hashes of cached built wheels agains origin source archive
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/test_install.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py
index e50779688..bc974d1a8 100644
--- a/tests/functional/test_install.py
+++ b/tests/functional/test_install.py
@@ -729,6 +729,44 @@ def test_bad_link_hash_in_dep_install_failure(
assert "THESE PACKAGES DO NOT MATCH THE HASHES" in result.stderr, result.stderr
+def test_hashed_install_from_cache(
+ script: PipTestEnvironment, data: TestData, tmpdir: Path
+) -> None:
+ """
+ Test that installing from a cached built wheel works and that the hash is verified
+ against the hash of the original source archived stored in the cache entry.
+ """
+ with requirements_file(
+ "simple2==1.0 --hash=sha256:"
+ "9336af72ca661e6336eb87bc7de3e8844d853e3848c2b9bbd2e8bf01db88c2c7\n",
+ tmpdir,
+ ) as reqs_file:
+ result = script.pip_install_local(
+ "--use-pep517", "--no-build-isolation", "-r", reqs_file.resolve()
+ )
+ assert "Created wheel for simple2" in result.stdout
+ script.pip("uninstall", "simple2", "-y")
+ result = script.pip_install_local(
+ "--use-pep517", "--no-build-isolation", "-r", reqs_file.resolve()
+ )
+ assert "Using cached simple2" in result.stdout
+ # now try with an invalid hash
+ with requirements_file(
+ "simple2==1.0 --hash=sha256:invalid\n",
+ tmpdir,
+ ) as reqs_file:
+ script.pip("uninstall", "simple2", "-y")
+ result = script.pip_install_local(
+ "--use-pep517",
+ "--no-build-isolation",
+ "-r",
+ reqs_file.resolve(),
+ expect_error=True,
+ )
+ assert "Using cached simple2" in result.stdout
+ assert "ERROR: THESE PACKAGES DO NOT MATCH THE HASHES" in result.stderr
+
+
def assert_re_match(pattern: str, text: str) -> None:
assert re.search(pattern, text), f"Could not find {pattern!r} in {text!r}"