Skip to content

Commit

Permalink
test: regression test for 0 cve pdf report (intel#4371)
Browse files Browse the repository at this point in the history
Adds a regression test for 0-cve pdf report behaviour.  This should help
us avoid bugs that cause the report to fail in the case where 0 cves
were found.

This is the last piece needed to close intel#4326.  Other pieces:

* intel#4329 fixed the check that was causing report generaiton to fail.
* intel#4354 changed the UI so it's more obvious when reportlab is needed.

* fixes intel#4326

Signed-off-by: Terri Oda <terri.oda@intel.com>
  • Loading branch information
terriko authored Aug 21, 2024
1 parent 475c86e commit eb8da07
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
CVE-bin-tool CLI tests
"""
import importlib
import logging
import os
import re
Expand Down Expand Up @@ -730,6 +731,42 @@ def test_console_output_depending_reportlab_existence(self, caplog):
not_installed_msg,
) not in caplog.record_tuples

@pytest.mark.skipif(
not importlib.util.find_spec("reportlab"),
reason="Reportlab needed for pdf test",
)
def test_0_cve_pdf_report(self, caplog):
"""Tests to make sure --report behaves as expected when 0 cves are found.
We expect a short pdf file saying 0 cves were found."""

with tempfile.TemporaryDirectory() as emptytemp:
# Set a filename for report in tempdir, make sure it doesn't exist.
report_0 = Path(self.tempdir) / "0_cve_report.pdf"
if report_0.exists():
report_0.unlink()

# Call cve-bin-tool to scan empty dir and product pdf report.
cbt_command = [
"cve-bin-tool",
"--offline",
"--format",
"pdf",
"-o",
str(report_0),
"--report",
str(emptytemp),
]
main(cbt_command)

# Make sure the report was created and has something in it.
# Testing what's in the report would increase test execution time
# so we're leaving that out for now
assert report_0.exists()
assert report_0.stat().st_size > 0

# get rid of generated file
report_0.unlink()

yamls = [
[
"cve-bin-tool",
Expand Down

0 comments on commit eb8da07

Please sign in to comment.