def test_nagios_no_cves_all():
    opt = MockOpt()
    opt.priority = "all"

    nof = NagiosOutputFormatter(opt, None)
    (results_msg, return_code) = nof.format_output(list(), None)

    assert "priority" not in results_msg
    assert return_code == const.NAGIOS_OK_RETURN_CODE
def test_nagios_no_cves_medium():
    opt = MockOpt()
    opt.priority = "medium"

    nof = NagiosOutputFormatter(opt, None)
    (results_msg, return_code) = nof.format_output(list(), None)

    assert '"medium" or higher priority' in results_msg
    assert return_code == const.NAGIOS_OK_RETURN_CODE
def test_nagios_warning_medium():
    opt = MockOpt()
    opt.priority = "medium"

    sr = [ScanResult("CVE-2020-1000", "medium", "pkg1", None, None)]

    nof = NagiosOutputFormatter(opt, None)
    (results_msg, return_code) = nof.format_output(sr, None)

    assert '"medium" or higher priority' in results_msg
    assert return_code == const.NAGIOS_WARNING_RETURN_CODE
def test_nagios_cves_sorted(shuffled_scan_results):
    opt = MockOpt()
    opt.unresolved = True
    opt.priority = "all"

    cve_list = ("CVE-2020-1000\nCVE-2020-1002\nCVE-2020-1005\nCVE-2020-2000\n"
                "CVE-2020-10000")

    nof = NagiosOutputFormatter(opt, None, CVEScanResultSorter())
    (results_msg, return_code) = nof.format_output(shuffled_scan_results, None)

    assert cve_list in results_msg
    assert return_code == const.NAGIOS_CRITICAL_RETURN_CODE
def test_nagios_critical_medium():
    opt = MockOpt()
    opt.priority = "medium"

    sr = [
        ScanResult("CVE-2020-1000", "medium", "pkg1", "1.2.3-2",
                   const.UBUNTU_ARCHIVE)
    ]

    nof = NagiosOutputFormatter(opt, None)
    (results_msg, return_code) = nof.format_output(sr, None)

    assert '"medium" or higher priority' in results_msg
    assert return_code == const.NAGIOS_CRITICAL_RETURN_CODE