Skip to content

Commit

Permalink
🐞 Vulnerability issue creator fails when Maven report does not contai…
Browse files Browse the repository at this point in the history
…n "vulnerable" entry

Fixes #102
  • Loading branch information
kaklakariada committed Nov 13, 2023
1 parent ef2fffa commit bf8e120
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
4 changes: 4 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
Unreleased
==========

🐞 Fixed
--------
* Fix failing vulnerability issue creator when Maven report does not contain "vulnerable" entry

🔧 Changed
----------

Expand Down
23 changes: 12 additions & 11 deletions exasol/toolbox/tools/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,18 @@ def gh_security_issues() -> Generator[Tuple[str, str], None, None]:
def from_maven(report: str) -> Iterable[Issue]:
# Note: Consider adding warnings if there is the same cve with multiple coordinates
report = json.loads(report)
dependencies = report["vulnerable"] # type: ignore
for _, dependency in dependencies.items(): # type: ignore
for v in dependency["vulnerabilities"]: # type: ignore
references = [v["reference"]] + v["externalReferences"]
yield Issue(
cve=v["cve"],
cwe=v["cwe"],
description=v["description"],
coordinates=dependency["coordinates"],
references=tuple(references),
)
if "vulnerable" in report:
dependencies = report["vulnerable"] # type: ignore
for _, dependency in dependencies.items(): # type: ignore
for v in dependency["vulnerabilities"]: # type: ignore
references = [v["reference"]] + v["externalReferences"]
yield Issue(
cve=v["cve"],
cwe=v["cwe"],
description=v["description"],
coordinates=dependency["coordinates"],
references=tuple(references),
)


def security_issue_title(issue: Issue) -> str:
Expand Down
5 changes: 5 additions & 0 deletions test/unit/security_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,8 @@ def test_convert_maven_input(maven_report): # pylint: disable=redefined-outer-n
}
actual = set(security.from_maven(maven_report))
assert actual == expected


def test_convert_maven_input_no_vulnerable(): # pylint: disable=redefined-outer-name
actual = set(security.from_maven("{}"))
assert len(actual) == 0

0 comments on commit bf8e120

Please sign in to comment.