Exemple #1
0
def test_upload_group_file(mock_safe_move, mock_open):
    with pytest.raises(WazuhError, match=".* 1710 .*"):
        configuration.upload_group_file('noexists', 'given', 'noexists')

    with patch('wazuh.core.configuration.os_path.exists', return_value=True):
        with pytest.raises(WazuhError, match=".* 1112 .*"):
            configuration.upload_group_file('default', [], 'agent.conf')

    with patch('wazuh.core.common.shared_path',
               new=os.path.join(parent_directory, tmp_path, 'configuration')):
        with patch('wazuh.core.configuration.tempfile.mkstemp',
                   return_value=['mock_handle', 'mock_tmp_file']):
            with patch('wazuh.core.configuration.subprocess.check_output',
                       return_value=True):
                with patch('wazuh.core.utils.chown', side_effect=None):
                    with patch('wazuh.core.utils.chmod', side_effect=None):
                        assert configuration.upload_group_file('default',
                                                               "<agent_config>new_config</agent_config>",
                                                               'agent.conf') == \
                               'Agent configuration was successfully updated'

    with patch('wazuh.core.common.shared_path',
               new=os.path.join(parent_directory, tmp_path, 'configuration')):
        with pytest.raises(WazuhError, match=".* 1111 .*"):
            configuration.upload_group_file('default', [], 'a.conf')
Exemple #2
0
def upload_group_file(group_list=None, file_data=None, file_name='agent.conf'):
    """Updates a group file.

    :param group_list: List of Group names.
    :param file_data: Relative path of temporary file to upload.
    :param file_name: File name to update.
    :return: Confirmation message.
    """
    # We access unique group_id from list, this may change if and when we decide to add option to update files for
    # a list of groups
    group_id = group_list[0]

    return WazuhResult({'message': configuration.upload_group_file(group_id, file_data, file_name=file_name)})