Skip to content

Commit 931d09d

Browse files
add test for security.py from_json
1 parent 1433674 commit 931d09d

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

test/unit/security_test.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
import pathlib
34
import subprocess
45
from contextlib import contextmanager
56
from inspect import cleandoc
@@ -403,3 +404,60 @@ def test_format_jsonl_removes_newline():
403404
)
404405
actual = security.format_jsonl("my_issue_url\n", issue)
405406
assert actual == expected
407+
408+
409+
@pytest.mark.parametrize(
410+
"json_file,expected",
411+
[
412+
(
413+
'''{
414+
"results": [
415+
{
416+
"code": "1 import subprocess\n2 from typing import Iterable\n3 \n",
417+
"col_offset": 0,
418+
"end_col_offset": 17,
419+
"filename": "/home/test/Git/python-toolbox/exasol/toolbox/git.py",
420+
"issue_confidence": "HIGH",
421+
"issue_cwe": {
422+
"id": 78,
423+
"link": "https://cwe.mitre.org/data/definitions/78.html"
424+
},
425+
"issue_severity": "LOW",
426+
"issue_text": "Consider possible security implications associated with the subprocess module.",
427+
"line_number": 1,
428+
"line_range": [
429+
1
430+
],
431+
"more_info": "https://bandit.readthedocs.io/en/1.7.10/blacklists/blacklist_imports.html#b404-import-subprocess",
432+
"test_id": "B404",
433+
"test_name": "blacklist"
434+
}
435+
]
436+
}
437+
''',
438+
{
439+
"cve": "",
440+
"cwe": "78",
441+
"description": "Consider possible security implications associated with the subprocess module.",
442+
"coordinates": "exasol/toolbox/git.py:1:0:",
443+
"references": (
444+
"https://bandit.readthedocs.io/en/1.7.10/blacklists/blacklist_imports.html#b404-import-subprocess",
445+
"https://cwe.mitre.org/data/definitions/78.html"
446+
)
447+
}
448+
)
449+
]
450+
)
451+
def test_from_json(json_file, expected):
452+
issues = security.from_json(json_file, pathlib.Path("/home/test/Git/python-toolbox"))
453+
expected_issue = security.Issue(
454+
cve=expected["cve"],
455+
cwe=expected["cwe"],
456+
description=expected["description"],
457+
coordinates=expected["coordinates"],
458+
references=expected["references"]
459+
)
460+
actual = []
461+
for issue in issues:
462+
actual.append(issue)
463+
assert actual == [expected_issue]

0 commit comments

Comments
 (0)