Esempio n. 1
0
def test_failed_get_rules_file(mock_config):
    """
    Test failed get_rules_file function when ossec.conf don't have ruleset section
    """
    m = mock_open(read_data=rule_contents)
    with patch('builtins.open', m):
        with pytest.raises(WazuhException, match=".* 1200 .*"):
            Rule.get_rules_files()
Esempio n. 2
0
def test_get_rules_file_pagination(mock_config, mock_glob, offset, limit, func):
    """
    Tests getting rules files using offset and limit
    """
    if limit > 0:
        m = mock_open(read_data=rule_contents)
        with patch('builtins.open', m):
            d_files = func(offset=offset, limit=limit)
            limit = d_files['totalItems'] if limit > d_files['totalItems'] else limit
            assert d_files['totalItems'] == 3
            assert len(d_files['items']) == (limit - offset if limit > offset else 0)
    else:
        with pytest.raises(WazuhException, match='.* 1406 .*'):
            Rule.get_rules_files(offset=offset, limit=limit)
Esempio n. 3
0
def test_get_rules_file_search(mock_config, mock_glob, search, func):
    """
    Tests getting rules files and searching results
    """
    m = mock_open(read_data=rule_contents)
    with patch('builtins.open', m):
        d_files = Rule.get_rules_files(search=search)
        if isinstance(d_files['items'][0], Rule):
            d_files['items'] = list(
                map(lambda x: x.to_dict(), d_files['items']))
        if search is not None:
            assert d_files['items'][0][
                'file'] == f"rules{'0' if search['negation'] else '1'}.xml"