def get_file_conf(group_list=None, type_conf=None, return_format=None, filename=None): """ Reads configuration file for specified group. :param group_list: List of Group names. :param type_conf: Type of file. :param return_format: Format of the answer (xml or json). :param filename: Filename to read config from. :return: WazuhResult. """ # We access unique group_id from list, this may change if and when we decide to add option to get configuration # files for a list of groups group_id = group_list[0] return WazuhResult({'data': configuration.get_file_conf(filename, group_id=group_id, type_conf=type_conf, return_format=return_format)})
def test_get_file_conf(): with patch('wazuh.common.shared_path', new=os.path.join(parent_directory, tmp_path, 'noexists')): with pytest.raises(WazuhError, match=".* 1710 .*"): configuration.get_file_conf(filename='ossec.conf', group_id='default', type_conf='conf', return_format='xml') with patch('wazuh.common.shared_path', new=os.path.join(parent_directory, tmp_path, 'configuration')): with pytest.raises(WazuhError, match=".* 1006 .*"): configuration.get_file_conf(filename='noexists.conf', group_id='default', type_conf='conf', return_format='xml') with patch('wazuh.common.shared_path', new=os.path.join(parent_directory, tmp_path, 'configuration')): assert isinstance( configuration.get_file_conf(filename='agent.conf', group_id='default', type_conf='conf', return_format='xml'), str) assert isinstance( configuration.get_file_conf(filename='agent.conf', group_id='default', type_conf='rcl', return_format='xml'), dict) assert isinstance( configuration.get_file_conf(filename='agent.conf', group_id='default', return_format='xml'), str) rootkit_files = [{ 'filename': 'NEW_ELEMENT', 'name': 'FOR', 'link': 'TESTING' }] assert configuration.get_file_conf( filename='rootkit_files.txt', group_id='default', return_format='xml') == rootkit_files rootkit_trojans = [{ 'filename': 'NEW_ELEMENT', 'name': 'FOR', 'description': 'TESTING' }] assert configuration.get_file_conf( filename='rootkit_trojans.txt', group_id='default', return_format='xml') == rootkit_trojans ar_list = [ 'restart-ossec0 - restart-ossec.sh - 0', 'restart-ossec0 - restart-ossec.cmd - 0', '' ] assert configuration.get_file_conf(filename='ar.conf', group_id='default', return_format='xml') == ar_list rcl = { 'vars': {}, 'controls': [{}, { 'name': 'NEW_ELEMENT', 'cis': [], 'pci': [], 'condition': 'FOR', 'reference': 'TESTING', 'checks': [] }] } assert configuration.get_file_conf(filename='rcl.conf', group_id='default', return_format='xml') == rcl with pytest.raises(WazuhError, match=".* 1104 .*"): configuration.get_file_conf(filename='agent.conf', group_id='default', type_conf='noconf', return_format='xml')