-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add basic filter * Change CLI entry points * Add prototype for issue creation
- Loading branch information
Showing
3 changed files
with
207 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,66 @@ | ||
import json | ||
import os | ||
import subprocess | ||
from contextlib import contextmanager | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from exasol.toolbox.tools import security | ||
|
||
|
||
@contextmanager | ||
def empty_path(): | ||
"""Make sure the PATH environment variable is empty.""" | ||
old_path = os.environ["PATH"] | ||
os.environ["PATH"] = "" | ||
yield | ||
os.environ["PATH"] = old_path | ||
|
||
|
||
class TestGhSecurityIssues: | ||
def test_gh_cli_is_not_available(self): | ||
with empty_path(): | ||
with pytest.raises(FileNotFoundError) as exec_info: | ||
set(security.gh_security_issues()) | ||
|
||
actual = f"{exec_info.value}" | ||
expected = "Command 'gh' not found. Please make sure you have installed the github cli." | ||
|
||
assert actual == expected | ||
|
||
@mock.patch( | ||
"subprocess.run", | ||
side_effect=subprocess.CalledProcessError( | ||
returncode=1, cmd=["command", "-l", "-v"] | ||
), | ||
) | ||
def test_gh_cli_failed(self, run_mock): | ||
with pytest.raises(subprocess.CalledProcessError) as exec_info: | ||
set(security.gh_security_issues()) | ||
|
||
actual = f"{exec_info.value}" | ||
expected = f"{subprocess.CalledProcessError(returncode=1, cmd=['command', '-l', '-v'])}" | ||
assert actual == expected | ||
|
||
@mock.patch("subprocess.run") | ||
def test_query_gh_security_issues(self, run_mock): | ||
result = mock.MagicMock(subprocess.CompletedProcess) | ||
result.returncode = 0 | ||
result.stdout = ( | ||
b'[{"id":"I_kwDOIRnUks5zutba","title":"\xf0\x9f\x90\x9e CVE-2023-41105: Fix build scripts "},' | ||
b'{"id":"I_kwDOIRnUks5clFdR","title":"\xf0\x9f\x90\x9e CVE-2023-40217: Version check issues"}]\n' | ||
) | ||
run_mock.return_value = result | ||
|
||
expected = { | ||
("I_kwDOIRnUks5zutba", "CVE-2023-41105"), | ||
("I_kwDOIRnUks5clFdR", "CVE-2023-40217"), | ||
} | ||
actual = set(security.gh_security_issues()) | ||
assert actual == expected | ||
|
||
|
||
@pytest.fixture() | ||
def maven_report(): | ||
yield json.dumps( | ||
|
@@ -98,13 +154,13 @@ def test_convert_maven_input(maven_report): | |
cve="CVE-2023-39410", | ||
cwe="CWE-502", | ||
description="When deserializing untrusted or corrupted data, it is " | ||
"possible for a reader to consume memory beyond the allowed " | ||
"constraints and thus lead to out of memory on the system.\n" | ||
"\n" | ||
"This issue affects Java applications using Apache Avro " | ||
"Java SDK up to and including 1.11.2. Users should update " | ||
"to apache-avro version 1.11.3 which addresses this issue.\n" | ||
"\n", | ||
"possible for a reader to consume memory beyond the allowed " | ||
"constraints and thus lead to out of memory on the system.\n" | ||
"\n" | ||
"This issue affects Java applications using Apache Avro " | ||
"Java SDK up to and including 1.11.2. Users should update " | ||
"to apache-avro version 1.11.3 which addresses this issue.\n" | ||
"\n", | ||
coordinates="pkg:maven/org.apache.avro/[email protected]", | ||
references=( | ||
"https://ossindex.sonatype.org/vulnerability/CVE-2023-39410?component-type=maven&component-name=org.apache.avro%2Favro&utm_source=ossindex-client&utm_medium=integration&utm_content=1.8.1", | ||
|
@@ -118,20 +174,20 @@ def test_convert_maven_input(maven_report): | |
cve="CVE-2020-36641", | ||
cwe="CWE-611", | ||
description="A vulnerability classified as problematic was found in " | ||
"gturri aXMLRPC up to 1.12.0. This vulnerability affects " | ||
"the function ResponseParser of the file " | ||
"src/main/java/de/timroes/axmlrpc/ResponseParser.java. The " | ||
"manipulation leads to xml external entity reference. " | ||
"Upgrading to version 1.12.1 is able to address this issue. " | ||
"The patch is identified as " | ||
"ad6615b3ec41353e614f6ea5fdd5b046442a832b. It is " | ||
"recommended to upgrade the affected component. VDB-217450 " | ||
"is the identifier assigned to this vulnerability.\n" | ||
"\n" | ||
"Sonatype's research suggests that this CVE's details " | ||
"differ from those defined at NVD. See " | ||
"https://ossindex.sonatype.org/vulnerability/CVE-2020-36641 " | ||
"for details", | ||
"gturri aXMLRPC up to 1.12.0. This vulnerability affects " | ||
"the function ResponseParser of the file " | ||
"src/main/java/de/timroes/axmlrpc/ResponseParser.java. The " | ||
"manipulation leads to xml external entity reference. " | ||
"Upgrading to version 1.12.1 is able to address this issue. " | ||
"The patch is identified as " | ||
"ad6615b3ec41353e614f6ea5fdd5b046442a832b. It is " | ||
"recommended to upgrade the affected component. VDB-217450 " | ||
"is the identifier assigned to this vulnerability.\n" | ||
"\n" | ||
"Sonatype's research suggests that this CVE's details " | ||
"differ from those defined at NVD. See " | ||
"https://ossindex.sonatype.org/vulnerability/CVE-2020-36641 " | ||
"for details", | ||
coordinates="pkg:maven/fr.turri/[email protected]", | ||
references=( | ||
"https://ossindex.sonatype.org/vulnerability/CVE-2020-36641?component-type=maven&component-name=fr.turri%2FaXMLRPC&utm_source=ossindex-client&utm_medium=integration&utm_content=1.8.1", | ||
|