示例#1
0
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)
示例#2
0
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
示例#3
0
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
示例#4
0
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,
    )
示例#5
0
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,
    )
示例#6
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",
    )
示例#7
0
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",
    )
示例#8
0
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,
    )
示例#9
0
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)
示例#10
0
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
示例#11
0
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)
示例#12
0
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)
示例#13
0
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)