|
1 | 1 | import json |
2 | 2 | import os |
| 3 | +import pathlib |
3 | 4 | import subprocess |
4 | 5 | from contextlib import contextmanager |
5 | 6 | from inspect import cleandoc |
@@ -403,3 +404,60 @@ def test_format_jsonl_removes_newline(): |
403 | 404 | ) |
404 | 405 | actual = security.format_jsonl("my_issue_url\n", issue) |
405 | 406 | 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