Skip to content

Commit eb8da07

Browse files
authored
test: regression test for 0 cve pdf report (#4371)
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 #4326. Other pieces: * #4329 fixed the check that was causing report generaiton to fail. * #4354 changed the UI so it's more obvious when reportlab is needed. * fixes #4326 Signed-off-by: Terri Oda <[email protected]>
1 parent 475c86e commit eb8da07

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/test_cli.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
CVE-bin-tool CLI tests
66
"""
7+
import importlib
78
import logging
89
import os
910
import re
@@ -730,6 +731,42 @@ def test_console_output_depending_reportlab_existence(self, caplog):
730731
not_installed_msg,
731732
) not in caplog.record_tuples
732733

734+
@pytest.mark.skipif(
735+
not importlib.util.find_spec("reportlab"),
736+
reason="Reportlab needed for pdf test",
737+
)
738+
def test_0_cve_pdf_report(self, caplog):
739+
"""Tests to make sure --report behaves as expected when 0 cves are found.
740+
We expect a short pdf file saying 0 cves were found."""
741+
742+
with tempfile.TemporaryDirectory() as emptytemp:
743+
# Set a filename for report in tempdir, make sure it doesn't exist.
744+
report_0 = Path(self.tempdir) / "0_cve_report.pdf"
745+
if report_0.exists():
746+
report_0.unlink()
747+
748+
# Call cve-bin-tool to scan empty dir and product pdf report.
749+
cbt_command = [
750+
"cve-bin-tool",
751+
"--offline",
752+
"--format",
753+
"pdf",
754+
"-o",
755+
str(report_0),
756+
"--report",
757+
str(emptytemp),
758+
]
759+
main(cbt_command)
760+
761+
# Make sure the report was created and has something in it.
762+
# Testing what's in the report would increase test execution time
763+
# so we're leaving that out for now
764+
assert report_0.exists()
765+
assert report_0.stat().st_size > 0
766+
767+
# get rid of generated file
768+
report_0.unlink()
769+
733770
yamls = [
734771
[
735772
"cve-bin-tool",

0 commit comments

Comments
 (0)