Skip to content

Commit 259fea2

Browse files
committed
add tests
Signed-off-by: Bennati, Stefano <stefano.bennati@here.com>
1 parent 6f99a91 commit 259fea2

File tree

4 files changed

+164
-0
lines changed

4 files changed

+164
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
Copyright 2018 Matthew Aynalem
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
"""
16+
from distutils.core import setup
17+
18+
from setuptools import find_packages
19+
20+
setup(
21+
name="packer.py",
22+
version="0.3.0",
23+
author="Matthew Aynalem",
24+
author_email="maynalem@gmail.com",
25+
packages=["packerpy"],
26+
url="https://github.com/mayn/packer.py",
27+
license="Apache License 2.0",
28+
description="packer.py - python library to run hashicorp packer CLI commands",
29+
keywords="hashicorp packer",
30+
long_description=open("README.rst").read(),
31+
install_requires=[],
32+
classifiers=[
33+
"License :: OSI Approved :: Apache Software License",
34+
"Programming Language :: Python :: 2",
35+
"Programming Language :: Python :: 2.7",
36+
"Programming Language :: Python :: 3",
37+
"Programming Language :: Python :: 3.4",
38+
"Programming Language :: Python :: 3.5",
39+
"Programming Language :: Python :: 3.6",
40+
],
41+
)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Copyright 2018 Matthew Aynalem
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
"""
16+
from distutils.core import setup
17+
18+
from setuptools import find_packages
19+
20+
setup(
21+
name="packer.py",
22+
version="0.3.0",
23+
author="Matthew Aynalem",
24+
author_email="maynalem@gmail.com",
25+
packages=["packerpy"],
26+
url="https://github.com/mayn/packer.py",
27+
license="Apache License 2.0",
28+
description="packer.py - python library to run hashicorp packer CLI commands",
29+
keywords="hashicorp packer",
30+
long_description=open("README.rst").read(),
31+
classifiers=[
32+
"License :: OSI Approved :: Apache Software License",
33+
"Programming Language :: Python :: 2",
34+
"Programming Language :: Python :: 2.7",
35+
"Programming Language :: Python :: 3",
36+
"Programming Language :: Python :: 3.4",
37+
"Programming Language :: Python :: 3.5",
38+
"Programming Language :: Python :: 3.6",
39+
],
40+
)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
Copyright 2018 Matthew Aynalem
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
"""
16+
from distutils.core import setup
17+
18+
from setuptools import find_packages
19+
20+
setup(
21+
name="packer.py",
22+
version="0.3.0",
23+
author="Matthew Aynalem",
24+
author_email="maynalem@gmail.com",
25+
packages=["packerpy"],
26+
url="https://github.com/mayn/packer.py",
27+
license="Apache License 2.0",
28+
description="packer.py - python library to run hashicorp packer CLI commands",
29+
keywords="hashicorp packer",
30+
long_description=open("README.rst").read(),
31+
install_requires=["requirement1", "requirement2"],
32+
classifiers=[
33+
"License :: OSI Approved :: Apache Software License",
34+
"Programming Language :: Python :: 2",
35+
"Programming Language :: Python :: 2.7",
36+
"Programming Language :: Python :: 3",
37+
"Programming Language :: Python :: 3.4",
38+
"Programming Language :: Python :: 3.5",
39+
"Programming Language :: Python :: 3.6",
40+
],
41+
)

tests/test_resolution.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from python_inspector.error import NoVersionsFound
2222
from python_inspector.resolution import PythonInputProvider
2323
from python_inspector.resolution import get_requirements_from_dependencies
24+
from python_inspector.resolution import get_requirements_from_python_manifest
2425
from python_inspector.resolution import is_valid_version
2526
from python_inspector.resolution import parse_reqs_from_setup_py_insecurely
2627
from python_inspector.utils_pypi import PYPI_PUBLIC_REPO
@@ -241,6 +242,47 @@ def test_get_requirements_from_dependencies_with_editable_requirements():
241242
assert requirements == []
242243

243244

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+
244286
def test_setup_py_parsing_insecure():
245287
setup_py_file = setup_test_env.get_test_loc("insecure-setup/setup.py")
246288
reqs = [str(req) for req in list(parse_reqs_from_setup_py_insecurely(setup_py=setup_py_file))]

0 commit comments

Comments
 (0)