Exemple #1
0
def test_match_len_one(single_host):
    results = single_host.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(
                path="$.type", assertion="is_equal_to", value="DeviceConfiguration"
            )
        ],
    )

    for result in results.values():
        assert result[0].tests[0].passed
        assert len(result[0].tests[0].matches) == 1
def test_fail_task(single_host):
    results = single_host.run(
        task=wrap_task(get_xml_etree),
        tests=[
            t_lxml(xpath="alarm-rate",
                   assertion="is_equal_to",
                   value="-1",
                   fail_task=True)
        ],
    )

    for result in results.values():
        assert not result[0].tests[0].passed
        assert result[0].failed
Exemple #3
0
def test_with_function(two_hosts):
    results = two_hosts.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(path="$.dns_servers",
                       assertion="contains",
                       host_data="$.dns_primary")
        ],
    )
    assert results["test"][0].tests[0].passed
    assert not results["test2"][0].tests[0].passed

    for result in results.values():
        assert len(result[0].tests) == 1
def test_path_not_found(single_host):
    results = single_host.run(
        task=wrap_task(get_xml_etree),
        tests=[
            t_lxml(xpath=".//invalid/invalid",
                   assertion="contains",
                   host_data="$.domain")
        ],
    )

    for result in results.values():
        assert not result[0].tests[0].passed
        assert (str(result[0].tests[0].exception) ==
                "no match found from path .//invalid/invalid")
def t_regexp_failed(single_host, fail):
    results = single_host.run(
        task=wrap_task(echo_data),
        z="zzzsuperpassword!dkfj",
        tests=[
            t_regexp(result_attr="result", regexp=r".*upexyzrpas*word", fail_task=fail)
        ],
    )

    for host, result in results.items():
        assert hasattr(result[0], "tests")
        assert result[0].failed == fail
        assert len(result[0].tests) > 0
        assert str(result[0].tests[0].exception).find("no match found for regex") != -1
Exemple #6
0
def test_without_one_of_single_match(single_host):
    results = single_host.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(
                path="$.interfaces..address",
                assertion="is_equal_to",
                value="192.168.1.1",
            )
        ],
    )

    for result in results.values():
        assert not result[0].tests[0].passed
        assert str(result[0].tests[0].exception).find("Expected") != -1
Exemple #7
0
def test_found_duplicate_host_data(single_host):
    results = single_host.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(
                path="$.dns_search", assertion="contains", host_data="$..duplicate"
            )
        ],
    )

    for result in results.values():
        assert not result[0].tests[0].passed
        assert (
            str(result[0].tests[0].exception) == "host_data can only return one match"
        )
def test_string_input(single_host):
    results = single_host.run(
        task=wrap_task(get_xml_str),
        tests=[
            t_lxml(
                xpath=".//minimum-length",
                assertion="is_equal_to",
                value="12",
                text=True,
            )
        ],
    )

    for result in results.values():
        assert result[0].tests[0].passed
def test_without_one_of_single_match(single_host):
    results = single_host.run(
        task=wrap_task(get_xml_etree),
        tests=[
            t_lxml(
                xpath=".//entry/encryption/member",
                assertion="is_equal_to",
                value="aes-128-cbc",
            )
        ],
    )

    for result in results.values():
        assert not result[0].tests[0].passed
        assert str(result[0].tests[0].exception).find("Expected") != -1
Exemple #10
0
def test_with_one_of_multi_match_task(single_host):
    results = single_host.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(
                path="$.interfaces..mask",
                assertion="is_equal_to",
                value=24,
                one_of=True,
            )
        ],
    )

    for result in results.values():
        assert result[0].tests[0].passed
        assert len(result[0].tests[0].matches) > 1
def test_found_no_host_data(single_host):
    results = single_host.run(
        task=wrap_task(get_xml_etree),
        tests=[
            t_lxml(
                xpath='.//monitor-profile/entry[@name="default"]/interval',
                assertion="is_equal_to",
                text=True,
                host_data="$.invalid",
            )
        ],
    )

    for result in results.values():
        assert not result[0].tests[0].passed
        assert str(result[0].tests[0].exception) == "host_data not found"
def test_contains_failed(single_host):
    results = single_host.run(
        task=wrap_task(get_xml_etree),
        tests=[
            t_lxml(
                xpath='.//monitor-profile/entry[@name="default"]/interval',
                assertion="is_equal_to",
                text=True,
                value="4",
            )
        ],
    )

    for result in results.values():
        assert not result[0].tests[0].passed
        assert str(result[0].tests[0].exception).find("Expected") != -1
def test_is_equal_passed_and_len_one(single_host):
    results = single_host.run(
        task=wrap_task(get_xml_etree),
        tests=[
            t_lxml(
                xpath='.//monitor-profile/entry[@name="default"]/interval',
                assertion="is_equal_to",
                text=True,
                value="3",
            )
        ],
    )

    for result in results.values():
        assert result[0].tests[0].passed
        assert len(result[0].tests[0].matches) == 1
Exemple #14
0
def test_fail_task(single_host):
    results = single_host.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(
                path="$.dns_servers",
                assertion="contains",
                value="8.8.8.8",
                fail_task=True,
            )
        ],
    )

    for result in results.values():
        assert not result[0].tests[0].passed
        assert result[0].failed
Exemple #15
0
def test_with_one_of_single_match(single_host):
    results = single_host.run(
        task=wrap_task(get_json_dict),
        tests=[
            t_jsonpath(
                path="$.interfaces..address",
                assertion="is_equal_to",
                value="192.168.1.1",
                one_of=True,
            )
        ],
    )

    for result in results.values():
        assert result[0].tests[0].passed
        assert len(result[0].tests[0].matches) == 1
def test_with_one_of_multi_match(single_host):
    results = single_host.run(
        task=wrap_task(get_xml_etree),
        tests=[
            t_lxml(
                xpath=".//wildfire-action",
                assertion="is_equal_to",
                value="reset-both",
                text=True,
                one_of=True,
            )
        ],
    )

    for result in results.values():
        assert result[0].tests[0].passed
        assert len(result[0].tests[0].matches) > 1
def test_too_many_match_groups(single_host):
    results = single_host.run(
        task=wrap_task(get_regexp),
        tests=[
            t_regexp(
                regexp=r"(.*?) is (.*)",
                assertion="is_equal_to",
                one_of=True,
                value="Ethernet1",
            )
        ],
    )
    assert not results["test"][0].tests[0].passed

    for result in results.values():
        assert len(result[0].tests) == 1
        assert len(result[0].tests[0].matches) == 0
def test_is_equal_passed_attribute(single_host):
    results = single_host.run(
        task=wrap_task(get_xml_etree),
        tests=[
            t_lxml(
                xpath=".//system/match-list/entry",
                assertion="is_equal_to",
                value="System_Log_Forwarding",
                attrib="name",
                one_of=True,
            )
        ],
    )

    for result in results.values():
        assert result[0].tests[0].passed
        assert len(result[0].tests[0].matches) == 1
def test_with_one_of_single_match(single_host):
    results = single_host.run(
        task=wrap_task(get_xml_etree),
        tests=[
            t_lxml(
                xpath=
                ".//ike-crypto-profiles/entry[@name='default']/encryption/member",
                assertion="is_equal_to",
                value="aes-128-cbc",
                one_of=True,
                text=True,
            )
        ],
    )

    for result in results.values():
        assert result[0].tests[0].passed
        assert len(result[0].tests[0].matches) == 1