Closed Rebits closed 1 year ago
This pull request addresses a bug that exists in the majority of the HostHandler class methods, specifically the incorrect handling of paths containing white spaces.
HostHandler
All the cases were tested getting these results: PR Accepted
Description
This pull request addresses a bug that exists in the majority of the
HostHandler
class methods, specifically the incorrect handling of paths containing white spaces.Evidences
Used Script
``` from wazuh_qa_framework.system.host_manager import HostManager hm = HostManager(inventory_path='inventory.yaml') print(f'Creating file in agent2: C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt') hm.create_file('agent2', 'C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt', content='First Line') print(f'Modifing file content. Adding "Testing" string to the file') hm.append_block_in_file('agent2', 'C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt', 'Testing') print(f'Showing file content') print(hm.get_file_content('agent2', 'C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt')) print(f'Getting file stats from agent2: C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt') print(hm.get_file_stats('agent2', 'C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt')) print(f'Coping file from agent2: C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt to agent2: C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt.bak') hm.copy_file('agent2', 'C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt', 'C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt.bak', remote_src=True) print(f'Showing file content') print(hm.get_file_content('agent2', 'C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt.bak')) print('Truncating file') hm.truncate_file('agent2', 'C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt.bak') print(f'Showing file content') print(hm.get_file_content('agent2', 'C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt.bak')) print("Removing file") hm.remove_file('agent2', 'C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt.bak') print(f'Getting file stats from agent2: C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt.bak') print(hm.get_file_stats('agent2', 'C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt.bak')) ```Output
``` Creating file in agent2: C:\Program Files (x86)\ossec-agent\logs\ossec.txt.txt Modifing file content. Adding "Testing" string to the file Showing file content First Line Testing Getting file stats from agent2: C:\Program Files (x86)\ossec-agent\logs\ossec.txt.txt {'changed': False, 'stat': {'attributes': 'Archive', 'checksum': '83ec70d6a5409bb8ab35e08893775e0dfc0688dd', 'creationtime': 1686125446.045948, 'exists': True, 'extension': '.txt', 'filename': 'ossec.txt.txt', 'hlnk_targets': [], 'isarchive': True, 'isdir': False, 'ishidden': False, 'isjunction': False, 'islnk': False, 'isreadonly': False, 'isreg': True, 'isshared': False, 'lastaccesstime': 1686125446.045948, 'lastwritetime': 1686127493.6964316, 'nlink': 1, 'owner': 'BUILTIN\\Administrators', 'path': 'C:\\Program Files (x86)\\ossec-agent\\logs\\ossec.txt.txt', 'size': 18}} Coping file from agent2: C:\Program Files (x86)\ossec-agent\logs\ossec.txt.txt to agent2: C:\Program Files (x86)\ossec-agent\logs\ossec.txt.txt.bak Showing file content First Line Testing Truncating file Showing file content Removing file Getting file stats from agent2: C:\Program Files (x86)\ossec-agent\logs\ossec.txt.txt.bak {'changed': False, 'stat': {'exists': False}} ```