|
| 1 | +# Copyright (C) 2022 Intel Corporation |
| 2 | +# SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | + |
| 4 | +import logging |
| 5 | +from os.path import dirname, join |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 9 | +import cve_bin_tool.csv2cve as csv2cve |
| 10 | +from cve_bin_tool.error_handler import ERROR_CODES, InsufficientArgs |
| 11 | + |
| 12 | + |
| 13 | +class TestCSV2CVE: |
| 14 | + @pytest.mark.asyncio |
| 15 | + async def test_csv2cve_valid_file(self, caplog): |
| 16 | + |
| 17 | + file_path = join(dirname(__file__), "csv", "triage.csv") |
| 18 | + |
| 19 | + csv2cve.main(["csv2cve", file_path]) |
| 20 | + |
| 21 | + assert ( |
| 22 | + "cve_bin_tool", |
| 23 | + logging.INFO, |
| 24 | + "There are 3 products with known CVEs detected", |
| 25 | + ) in caplog.record_tuples |
| 26 | + |
| 27 | + assert ( |
| 28 | + "cve_bin_tool", |
| 29 | + logging.INFO, |
| 30 | + "Known CVEs in ('curl', '7.34.0'), ('kerberos', '1.15.1'), ('kerberos_5', '1.15.1'):", |
| 31 | + ) in caplog.record_tuples |
| 32 | + |
| 33 | + for cve in [ |
| 34 | + "3 CVE(s) in mit.kerberos v1.15.1", |
| 35 | + "55 CVE(s) in haxx.curl v7.34.0", |
| 36 | + "9 CVE(s) in mit.kerberos_5 v1.15.1", |
| 37 | + ]: |
| 38 | + assert ( |
| 39 | + "cve_bin_tool.CVEScanner", |
| 40 | + logging.INFO, |
| 41 | + cve, |
| 42 | + ) in caplog.record_tuples |
| 43 | + |
| 44 | + @pytest.mark.asyncio |
| 45 | + @pytest.mark.parametrize( |
| 46 | + "args", (["csv2cve"], ["csv2cve", f"{dirname(__file__)}/txt/empty.txt"]) |
| 47 | + ) |
| 48 | + async def test_csv2cve_invalid_arguments(self, args): |
| 49 | + with pytest.raises(SystemExit) as e: |
| 50 | + csv2cve.main(args) |
| 51 | + assert e.value.args[0] == ERROR_CODES[InsufficientArgs] |
0 commit comments