Skip to content

Commit 538ffc0

Browse files
authored
test: add invalid package to test language scanner (#4918)
1 parent d93bc2d commit 538ffc0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

test/language_data/invalid-package-lock.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test_language_scanner.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,26 @@ def test_javascript_package_none_found(self, filename: str) -> None:
199199
scanner = VersionScanner()
200200
scanner.file_stack.append(filename)
201201
product = None
202+
202203
# Not expecting any product to match with a vendor in the database
203204
for product in scanner.scan_file(filename):
204205
pass
205206
assert product is not None
206207

208+
@pytest.mark.parametrize(
209+
"filename", ((str(TEST_FILE_PATH / "invalid-package-lock.json")),)
210+
)
211+
def test_invalid_javascript_package(self, filename: str) -> None:
212+
"""Test an invalid package-lock.json file
213+
214+
The parser should gracefully handle invalid package-lock.json files.
215+
"""
216+
scanner = VersionScanner()
217+
scanner_output = scanner.scan_file(filename)
218+
219+
for product in scanner_output:
220+
assert product is None
221+
207222
@pytest.mark.parametrize(
208223
"filename",
209224
[

0 commit comments

Comments
 (0)