Skip to content

Commit

Permalink
add test for --exclude
Browse files Browse the repository at this point in the history
  • Loading branch information
imsahil007 committed Aug 20, 2020
1 parent 440c122 commit 8475f2b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ def test_no_extraction(self):
""" Test scanner against curl-7.20.0 rpm with extraction turned off """
assert main(["cve-bin-tool", os.path.join(self.tempdir, CURL_7_20_0_RPM)]) == 0

def test_exclude(self, caplog):
""" Test that the exclude paths are not scanned """
test_path = os.path.abspath(os.path.dirname(__file__))
exclude_path = os.path.join(
os.path.abspath(os.path.dirname(__file__)), "assets"
)
checkers = ["curl", "libcurl", "kerberos", "kerberos_5"]
with caplog.at_level(logging.INFO):
main(["cve-bin-tool", test_path, "-e", ",".join(exclude_path)])
self.check_exclude_log(caplog, exclude_path, checkers)

def test_usage(self):
""" Test that the usage returns 0 """
with pytest.raises(SystemExit) as e:
Expand Down Expand Up @@ -101,6 +112,21 @@ def test_update_flags(self):
main(["cve-bin-tool", "-u", "whatever", self.tempdir])
assert e.value.args[0] == -2

@staticmethod
def check_exclude_log(caplog, exclude_path, checkers):
# The final log has all the checkers detected
final_log = [
record for record in caplog.records if "Checkers:" in record.message
]
assert len(final_log) == 0, "Checkers excluded from exclude path"
final_log = final_log[0].message
for checker in checkers:
assert (
checker not in final_log
), f"found a checker {checker} in {exclude_path}"

caplog.clear()

@staticmethod
def check_checkers_log(caplog, skip_checkers, include_checkers):
# The final log has all the checkers detected
Expand Down
1 change: 1 addition & 0 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class TestConfig:
"cvss": 0,
"directory": "test/assets",
"disable_version_check": False,
"exclude": [],
"extract": False,
"format": "console",
"input_file": "test/csv/triage.csv",
Expand Down

0 comments on commit 8475f2b

Please sign in to comment.