Esempio n. 1
0
def test_get_rules(mock_config, arg):
    """Test get_rules function."""
    result = rule.get_rules(**arg)

    assert isinstance(result, AffectedItemsWazuhResult)
    for rule_ in result.to_dict()['affected_items']:
        if list(arg.keys())[0] != 'level':
            key = list(arg.keys())[0] if list(arg.keys())[0] != 'rule_ids' else 'id'

            if key == 'id':
                for rule_id in arg[list(arg.keys())[0]]:
                    assert rule_id in [rule_[key]]
            else:
                for rule_id in [arg[list(arg.keys())[0]]]:
                    assert rule_id in rule_[key]
        else:
            try:
                found = arg[list(arg.keys())[0]] in str(rule_[list(arg.keys())[0]])
                if found:
                    assert True
                assert str(rule_[list(arg.keys())[0]]) in arg[list(arg.keys())[0]]
            except WazuhError as e:
                # Check the error raised when using an nonexistent rule_id
                assert 'rule_ids' in arg.keys()
                assert e.code == 1208
Esempio n. 2
0
def test_failed_get_rules():
    """Test error 1203 in get_rules function."""
    with pytest.raises(WazuhError, match=".* 1203 .*"):
        rule.get_rules(level='2-3-4')