|
21 | 21 | from python_inspector.error import NoVersionsFound |
22 | 22 | from python_inspector.resolution import PythonInputProvider |
23 | 23 | from python_inspector.resolution import get_requirements_from_dependencies |
| 24 | +from python_inspector.resolution import get_requirements_from_python_manifest |
24 | 25 | from python_inspector.resolution import is_valid_version |
25 | 26 | from python_inspector.resolution import parse_reqs_from_setup_py_insecurely |
26 | 27 | from python_inspector.utils_pypi import PYPI_PUBLIC_REPO |
@@ -241,6 +242,47 @@ def test_get_requirements_from_dependencies_with_editable_requirements(): |
241 | 242 | assert requirements == [] |
242 | 243 |
|
243 | 244 |
|
| 245 | +def test_get_requirements_from_python_manifest_securely(): |
| 246 | + sdist_location = "tests/data/secure-setup" |
| 247 | + setup_py_emptyrequires = "setup-emptyrequires.py" |
| 248 | + setup_py_norequires = "setup-norequires.py" |
| 249 | + setup_py_requires = "setup-requires.py" |
| 250 | + analyze_setup_py_insecurely = False |
| 251 | + try: |
| 252 | + ret = list( |
| 253 | + get_requirements_from_python_manifest( |
| 254 | + sdist_location, |
| 255 | + sdist_location + "/" + setup_py_norequires, |
| 256 | + [sdist_location + "/" + setup_py_norequires], |
| 257 | + analyze_setup_py_insecurely, |
| 258 | + ) |
| 259 | + ) |
| 260 | + assert ret == [] |
| 261 | + except Exception: |
| 262 | + pytest.fail("Failure parsing setup.py where requirements are not provided.") |
| 263 | + try: |
| 264 | + ret = list( |
| 265 | + get_requirements_from_python_manifest( |
| 266 | + sdist_location, |
| 267 | + sdist_location + "/" + setup_py_emptyrequires, |
| 268 | + [sdist_location + "/" + setup_py_emptyrequires], |
| 269 | + analyze_setup_py_insecurely, |
| 270 | + ) |
| 271 | + ) |
| 272 | + assert ret == [] |
| 273 | + except Exception: |
| 274 | + pytest.fail("Failure getting empty requirements securely from setup.py.") |
| 275 | + with pytest.raises(Exception): |
| 276 | + ret = list( |
| 277 | + get_requirements_from_python_manifest( |
| 278 | + sdist_location, |
| 279 | + sdist_location + "/" + setup_py_requires, |
| 280 | + [sdist_location + "/" + setup_py_requires], |
| 281 | + analyze_setup_py_insecurely, |
| 282 | + ).next() |
| 283 | + ) |
| 284 | + |
| 285 | + |
244 | 286 | def test_setup_py_parsing_insecure(): |
245 | 287 | setup_py_file = setup_test_env.get_test_loc("insecure-setup/setup.py") |
246 | 288 | reqs = [str(req) for req in list(parse_reqs_from_setup_py_insecurely(setup_py=setup_py_file))] |
|
0 commit comments