def test_invalid_repository_disabled_color(monkeypatch, table_only_cli_output_formatter): table_only_cli_output_formatter.opt.unresolved = True sysinfo = MockSysInfo() sysinfo.esm_infra_enabled = True run_repository_color_test(monkeypatch, table_only_cli_output_formatter, sysinfo, "CVE-2020-1011", False)
def test_ua_infra_unknown_text(monkeypatch, table_only_cli_output_formatter): sysinfo = MockSysInfo() sysinfo.esm_infra_enabled = None sr = filter_scan_results_by_cve_ids("CVE-2020-1010") (results_msg, return_code) = table_only_cli_output_formatter.format_output(sr, sysinfo) assert "(disabled)" not in results_msg
def test_ua_apps_disabled_text(monkeypatch, table_only_cli_output_formatter): sysinfo = MockSysInfo() sysinfo.esm_apps_enabled = False sysinfo.esm_infra_enabled = True sr = filter_scan_results_by_cve_ids("CVE-2020-1009") (results_msg, return_code) = table_only_cli_output_formatter.format_output(sr, sysinfo) assert "(disabled)" in results_msg
def test_critical_color(monkeypatch, table_only_cli_output_formatter): sysinfo = MockSysInfo() sysinfo.esm_apps_enabled = True sysinfo.esm_infra_enabled = True run_priority_color_test( monkeypatch, table_only_cli_output_formatter, sysinfo, "CVE-2020-1007", const.CRITICAL, )
def test_summary_fixes_applied_color(monkeypatch, summary_only_cli_output_formatter): sysinfo = MockSysInfo() sysinfo.esm_apps_enabled = True sysinfo.esm_infra_enabled = True run_fixes_not_applied_color_code_test( monkeypatch, summary_only_cli_output_formatter, sysinfo, const.REPOSITORY_ENABLED_COLOR_CODE, 0, )
def test_summary_manifest_esm_unknown_color(monkeypatch, summary_only_cli_output_formatter): sysinfo = MockSysInfo() sysinfo.esm_apps_enabled = None sysinfo.esm_infra_enabled = None run_esm_color_code_test( monkeypatch, summary_only_cli_output_formatter, sysinfo, const.REPOSITORY_UNKNOWN_COLOR_CODE, "Unknown", )
def test_summary_esm_disabled_color(monkeypatch, summary_only_cli_output_formatter): sysinfo = MockSysInfo() sysinfo.esm_apps_enabled = False sysinfo.esm_infra_enabled = False run_esm_color_code_test( monkeypatch, summary_only_cli_output_formatter, sysinfo, const.REPOSITORY_DISABLED_COLOR_CODE, "No", )
def test_summary_fixes_unknown_color(monkeypatch, summary_only_cli_output_formatter): sysinfo = MockSysInfo() sysinfo.esm_apps_enabled = None sysinfo.esm_infra_enabled = None run_fixes_not_applied_color_code_test( monkeypatch, summary_only_cli_output_formatter, sysinfo, const.REPOSITORY_UNKNOWN_COLOR_CODE, 3, unknown=True, )
def test_suggestions_empty_no_experimental_infra_enabled( monkeypatch, suggestions_only_cli_output_formatter): cof = suggestions_only_cli_output_formatter cof.opt.priority = const.LOW cof.opt.experimental_mode = False sysinfo = MockSysInfo() sysinfo.esm_apps_enabled = False sysinfo.esm_infra_enabled = True sr = filter_scan_results_by_cve_ids(["CVE-2020-1001", "CVE-2020-1010"]) (results_msg, return_code) = cof.format_output(sr, sysinfo) assert ( "additional security patch(es) are available if ESM for Infrastructure is enabled with\nUbuntu Advantage." not in results_msg)
def test_summary_experimental_filter(monkeypatch, summary_only_cli_output_formatter): monkeypatch.setattr(sys.stdout, "isatty", lambda: False) cof = summary_only_cli_output_formatter sysinfo = MockSysInfo() sysinfo.esm_apps_enabled = False sysinfo.esm_infra_enabled = True cof.opt.experimental_mode = False sr = filter_scan_results_by_cve_ids(["CVE-2020-1001"]) (results_msg, return_code) = cof.format_output(sr, sysinfo) assert "Vulnerabilities Fixable by ESM" not in results_msg # Disable this test for now # assert "UA Apps Enabled" not in results_msg # assert "UA Infra Enabled" not in results_msg assert "Available Fixes Not Applied" not in results_msg
def test_summary_nounresolved(monkeypatch, summary_only_cli_output_formatter): monkeypatch.setattr(sys.stdout, "isatty", lambda: False) cof = summary_only_cli_output_formatter cof.opt.priority = const.LOW cof.opt.unresolved = False sysinfo = MockSysInfo() sysinfo.esm_apps_enabled = False sysinfo.esm_infra_enabled = False sr = filter_scan_results_by_cve_ids([ "CVE-2020-1001", "CVE-2020-1002", "CVE-2020-1003", "CVE-2020-1005", "CVE-2020-1009", "CVE-2020-1010", ]) (results_msg, return_code) = cof.format_output(sr, sysinfo) assert re.search(r"Ubuntu Release\s+bionic", results_msg) assert re.search(r"Installed Packages\s+100", results_msg) assert re.search(r"CVE Priority\s+low or higher", results_msg) assert re.search(r"Unique Packages Fixable by Patching\s+6", results_msg) assert re.search(r"Unique CVEs Fixable by Patching\s+5", results_msg) assert re.search(r"Vulnerabilities Fixable by Patching\s+10", results_msg) assert re.search(r"Vulnerabilities Fixable by %s\s+6" % const.UA_APPS, results_msg) assert re.search(r"Vulnerabilities Fixable by %s\s+2" % const.UA_INFRA, results_msg) # Disabling for now # assert re.search(r"UA Apps Enabled\s+No", results_msg) # assert re.search(r"UA Infra Enabled\s+No", results_msg) assert re.search(r"Fixes Available by `apt-get upgrade`\s+2", results_msg) assert re.search(r"Available Fixes Not Applied by `apt-get upgrade`\s+8", results_msg)
def test_ua_infra_unknown_color(monkeypatch, table_only_cli_output_formatter): sysinfo = MockSysInfo() sysinfo.esm_infra_enabled = None run_repository_color_test(monkeypatch, table_only_cli_output_formatter, sysinfo, "CVE-2020-1010", None)
def test_ua_infra_disabled_color(monkeypatch, table_only_cli_output_formatter): sysinfo = MockSysInfo() sysinfo.esm_apps_enabled = True sysinfo.esm_infra_enabled = False run_repository_color_test(monkeypatch, table_only_cli_output_formatter, sysinfo, "CVE-2020-1010", False)