Esempio n. 1
0
def test_add_detail(detail, value, details):
    dec = Decoder()
    dec.details = dict(frozenset(details.items()))
    dec.add_detail(detail, value)
    if not details:
        assert isinstance(dec.details[detail], str)
    else:
        assert isinstance(dec.details[detail], list)
Esempio n. 2
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. 3
0
def test_get_decoders_parents(open_mock):
    """
    Tests getting parent decoders
    """
    with patch('builtins.open', open_mock):
        result = Decoder.get_decoders(parents=True)
        assert isinstance(result, dict)
Esempio n. 4
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. 5
0
def test_decoder__init__():
    dec = Decoder()
    assert dec.file is None
    assert dec.path is None
    assert dec.name is None
    assert dec.position is None
    assert dec.status is None
    assert isinstance(dec.details, dict)
Esempio n. 6
0
def test_private_load_decoders_from_file(open_mock):
    """
    Tests_load_decoders_from_file
    """
    with patch('builtins.open', open_mock):
        result = Decoder.get_decoders()

        assert isinstance(result, dict)
Esempio n. 7
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. 8
0
def test_get_decoders_name(name, file_, open_mock):
    """Tests getting decoders by name and file filtering."""
    with patch('builtins.open', open_mock):
        filters = {'name': name, 'file': file_}
        result = Decoder.get_decoders(filters=filters, search=mock_search)
        if name == 'agent-buffer' and file_ == 'decoders1.xml':
            assert result['items'][0].name == 'agent-buffer'
        else:
            assert isinstance(result, dict)
Esempio n. 9
0
def test_get_decoders_name(name, file, open_mock):
    """
    Tests getting decoders by name and file filtering
    """
    with patch('builtins.open', open_mock):
        result = Decoder.get_decoders(name=name, search=mock_search, file=file)
        if name == 'agent-buffer' and file == 'decoders1.xml':
            assert result['items'][0].name == 'agent-buffer'
        else:
            assert isinstance(result, dict)
Esempio n. 10
0
def test_decoder_to_dict():
    result = Decoder().to_dict()
    assert isinstance(result, dict)
Esempio n. 11
0
def test_decoder__str__():
    result = Decoder().__str__()
    assert isinstance(result, str)
Esempio n. 12
0
def test_private_load_decoders_from_file_exceptions(mock_load):
    """Test exceptions for load wazuh xml."""
    with pytest.raises(WazuhException, match='.* 1501 .*'):
        Decoder.get_decoders()
Esempio n. 13
0
def test_get_decoders_parents(open_mock):
    """Test getting parent decoders."""
    with patch('builtins.open', open_mock):
        filters = {'parents': True}
        result = Decoder.get_decoders(filters=filters)
        assert isinstance(result, dict)
Esempio n. 14
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()