Esempio n. 1
0
def test_get_decoders_file_pagination(offset, limit, func, open_mock):
    """Test getting decoders files using offset and limit."""
    if limit > 0:
        with patch('builtins.open', open_mock):
            d_files = func(offset=offset, limit=limit)
            limit = d_files['totalItems'] if limit > d_files['totalItems'] else limit
            assert d_files['totalItems'] == 2
            assert len(d_files['items']) == (limit - offset if limit > offset else 0)
    else:
        with pytest.raises(WazuhException, match='.* 1406 .*'):
            Decoder.get_decoders_files(offset=offset, limit=limit)
Esempio n. 2
0
def test_private_get_files_list_conf(mock_conf):
    """
    Tests with decoder_dir as a list and as a string, also with decoder_include
    """
    with patch('wazuh.configuration.get_ossec_conf', return_value=mock_conf):
        result = Decoder.get_decoders_files(file='mock.xml')
        assert isinstance(result, dict)
Esempio n. 3
0
def test_get_decoders_file_search(search, open_mock):
    """Test getting decoders files and searching results."""
    with patch('builtins.open', open_mock):
        d_files = Decoder.get_decoders_files(search=search)
        if isinstance(d_files['items'][0], Decoder):
            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"decoders{'0' if search['negation'] else '1'}.xml"
Esempio n. 4
0
def test_private_get_files_empty_conf(*mocked_args):
    """Tests empty ossec.conf section exception."""
    with pytest.raises(WazuhException, match='.* 1500 .*'):
        Decoder.get_decoders_files()