|
11 | 11 |
|
12 | 12 | from poetry.config.config import Config
|
13 | 13 | from poetry.core.packages.package import Package
|
| 14 | +from poetry.core.packages.utils.link import Link |
| 15 | +from poetry.installation.chef import Chef |
14 | 16 | from poetry.installation.executor import Executor
|
15 | 17 | from poetry.installation.operations import Install
|
16 | 18 | from poetry.installation.operations import Uninstall
|
@@ -251,3 +253,78 @@ def test_executor_should_delete_incomplete_downloads(
|
251 | 253 | executor._download(Install(Package("tomlkit", "0.5.3")))
|
252 | 254 |
|
253 | 255 | assert not destination_fixture.exists()
|
| 256 | + |
| 257 | + |
| 258 | +def test_executor_should_check_every_possible_hash_types( |
| 259 | + config, io, pool, mocker, fixture_dir, tmp_dir |
| 260 | +): |
| 261 | + mocker.patch.object( |
| 262 | + Chef, "get_cached_archive_for_link", side_effect=lambda link: link, |
| 263 | + ) |
| 264 | + mocker.patch.object( |
| 265 | + Executor, |
| 266 | + "_download_archive", |
| 267 | + return_value=fixture_dir("distributions").joinpath( |
| 268 | + "demo-0.1.0-py2.py3-none-any.whl" |
| 269 | + ), |
| 270 | + ) |
| 271 | + |
| 272 | + env = MockEnv(path=Path(tmp_dir)) |
| 273 | + executor = Executor(env, pool, config, io) |
| 274 | + |
| 275 | + package = Package("demo", "0.1.0") |
| 276 | + package.files = [ |
| 277 | + { |
| 278 | + "file": "demo-0.1.0-py2.py3-none-any.whl", |
| 279 | + "hash": "md5:15507846fd4299596661d0197bfb4f90", |
| 280 | + } |
| 281 | + ] |
| 282 | + |
| 283 | + archive = executor._download_link( |
| 284 | + Install(package), Link("https://example.com/demo-0.1.0-py2.py3-none-any.whl") |
| 285 | + ) |
| 286 | + |
| 287 | + assert archive == fixture_dir("distributions").joinpath( |
| 288 | + "demo-0.1.0-py2.py3-none-any.whl" |
| 289 | + ) |
| 290 | + |
| 291 | + |
| 292 | +def test_executor_should_check_every_possible_hash_types_before_failing( |
| 293 | + config, io, pool, mocker, fixture_dir, tmp_dir |
| 294 | +): |
| 295 | + mocker.patch.object( |
| 296 | + Chef, "get_cached_archive_for_link", side_effect=lambda link: link, |
| 297 | + ) |
| 298 | + mocker.patch.object( |
| 299 | + Executor, |
| 300 | + "_download_archive", |
| 301 | + return_value=fixture_dir("distributions").joinpath( |
| 302 | + "demo-0.1.0-py2.py3-none-any.whl" |
| 303 | + ), |
| 304 | + ) |
| 305 | + |
| 306 | + env = MockEnv(path=Path(tmp_dir)) |
| 307 | + executor = Executor(env, pool, config, io) |
| 308 | + |
| 309 | + package = Package("demo", "0.1.0") |
| 310 | + package.files = [ |
| 311 | + {"file": "demo-0.1.0-py2.py3-none-any.whl", "hash": "md5:123456"}, |
| 312 | + {"file": "demo-0.1.0-py2.py3-none-any.whl", "hash": "sha256:123456"}, |
| 313 | + ] |
| 314 | + |
| 315 | + with pytest.raises(RuntimeError) as e: |
| 316 | + executor._download_link( |
| 317 | + Install(package), |
| 318 | + Link("https://example.com/demo-0.1.0-py2.py3-none-any.whl"), |
| 319 | + ) |
| 320 | + |
| 321 | + expected_message = ( |
| 322 | + "Invalid hashes " |
| 323 | + "(" |
| 324 | + "md5:15507846fd4299596661d0197bfb4f90, " |
| 325 | + "sha256:70e704135718fffbcbf61ed1fc45933cfd86951a744b681000eaaa75da31f17a" |
| 326 | + ") " |
| 327 | + "for demo (0.1.0) using archive demo-0.1.0-py2.py3-none-any.whl. " |
| 328 | + "Expected one of md5:123456, sha256:123456." |
| 329 | + ) |
| 330 | + assert str(e.value) == expected_message |
0 commit comments