Skip to content

Commit

Permalink
fix(#5229): Fixing validations after uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-akim committed Apr 29, 2024
1 parent 9e07b4d commit 7490c95
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
20 changes: 13 additions & 7 deletions deployability/modules/testing/tests/helpers/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import yaml

from typing import List, Optional
from .constants import WAZUH_CONF, WAZUH_ROOT, WAZUH_WINDOWS_CONF
from .constants import WAZUH_CONF, WAZUH_ROOT, WAZUH_WINDOWS_CONF, WAZUH_MACOS_CONF
from .executor import WazuhAPI, ConnectionManager
from .generic import HostInformation, CheckFiles
from modules.testing.utils import logger
Expand All @@ -23,11 +23,11 @@ def install_agent(inventory_path, agent_name, wazuh_version, wazuh_revision, liv
release = 'pre-release'

os_type = HostInformation.get_os_type(inventory_path)
architecture = HostInformation.get_architecture(inventory_path)
commands = []

if os_type == 'linux':
distribution = HostInformation.get_linux_distribution(inventory_path)
architecture = HostInformation.get_architecture(inventory_path)

if distribution == 'rpm' and 'amd64' in architecture:
commands.extend([
Expand Down Expand Up @@ -66,11 +66,11 @@ def install_agent(inventory_path, agent_name, wazuh_version, wazuh_revision, liv
])
commands.extend(["NET START WazuhSvc"])
elif os_type == 'macos':
if 'amd64' in architecture:
if architecture == 'amd64':
commands.extend([
f'curl -so wazuh-agent.pkg https://{s3_url}.wazuh.com/{release}/macos/wazuh-agent-{wazuh_version}-1.intel64.pkg && echo "WAZUH_MANAGER=\'MANAGER_IP\' && WAZUH_AGENT_NAME=\'{agent_name}\'" > /tmp/wazuh_envs && sudo installer -pkg ./wazuh-agent.pkg -target /'
])
elif 'arm64' in architecture:
elif architecture == 'arm64':
commands.extend([
f'curl -so wazuh-agent.pkg https://{s3_url}.wazuh.com/{release}/macos/wazuh-agent-{wazuh_version}-1.arm64.pkg && echo "WAZUH_MANAGER=\'MANAGER_IP\' && WAZUH_AGENT_NAME=\'{agent_name}\'" > /tmp/wazuh_envs && sudo installer -pkg ./wazuh-agent.pkg -target /'
])
Expand Down Expand Up @@ -125,7 +125,7 @@ def register_agent(inventory_path, manager_path):
else:
host_ip = HostInformation.get_public_ip_from_aws_dns(manager_host)
commands = [
f"sed -i '.bak' 's/<address>MANAGER_IP<\/address>/<address>{host_ip}<\/address>/g' /Library/Ossec/etc/ossec.conf",
f"sed -i '.bak' 's/<address>MANAGER_IP<\/address>/<address>{host_ip}<\/address>/g' {WAZUH_MACOS_CONF}",
"/Library/Ossec/bin/wazuh-control restart"
]
ConnectionManager.execute_commands(inventory_path, commands)
Expand Down Expand Up @@ -393,13 +393,19 @@ def areAgent_processes_active(agent_params):
"""
os_type = HostInformation.get_os_type(agent_params)

if 'linux' in os_type:
if os_type == 'linux':
result = ConnectionManager.execute_commands(agent_params, 'pgrep wazuh')
if result.get('success'):
return bool([int(numero) for numero in result.get('output').splitlines()])
else:
return False
elif 'windows' in os_type:

if os_type == 'macos':
result = ConnectionManager.execute_commands(agent_params, 'pgrep wazuh')
return bool([int(numero) for numero in result.splitlines()])


elif os_type == 'windows':
result = ConnectionManager.execute_commands(agent_params, 'Get-Process -Name "wazuh-agent" | Format-Table -HideTableHeaders ProcessName')
if result.get('success'):
return 'wazuh-agent' in result.get('output')
Expand Down
3 changes: 2 additions & 1 deletion deployability/modules/testing/tests/helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
WINDOWS_VERSION = Path(WINDOWS_ROOT_DIR, "VERSION")
WINDOWS_REVISION = Path(WINDOWS_ROOT_DIR, "REVISION")


MACOS_ROOT_DIR = Path("/Library", "Ossec")
MACOS_CONFIGURATIONS_DIR = Path(MACOS_ROOT_DIR, "etc")
WAZUH_MACOS_CONF = Path(MACOS_CONFIGURATIONS_DIR, "ossec.conf")
MACOS_CLIENT_KEYS = Path(MACOS_CONFIGURATIONS_DIR, "client.keys")
MACOS_VERSION = Path(MACOS_ROOT_DIR, "VERSION")
MACOS_REVISION = Path(MACOS_ROOT_DIR, "REVISION")

# Binaries paths
BINARIES_DIR = Path(WAZUH_ROOT, "bin")
Expand Down
1 change: 1 addition & 0 deletions deployability/modules/testing/tests/helpers/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def dir_exists(inventory_path, dir_path) -> str:
return result.get('output')
elif os_type == 'windows':
return ConnectionManager.execute_commands(inventory_path, f'Test-Path -Path "{dir_path}"').get('success')

elif os_type == 'macos':
return 'true' in ConnectionManager.execute_commands(inventory_path, f'stat {dir_path} >/dev/null 2>&1 && echo "true" || echo "false"')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re

from ..helpers.agent import WazuhAgent
from ..helpers.constants import WAZUH_ROOT, WINDOWS_CONFIGURATIONS_DIR, WINDOWS_ROOT_DIR, MACOS_ROOT_DIR
from ..helpers.constants import WAZUH_ROOT, WINDOWS_CONFIGURATIONS_DIR, WINDOWS_ROOT_DIR, MACOS_ROOT_DIR, MACOS_CONFIGURATIONS_DIR
from ..helpers.generic import HostInformation, GeneralComponentActions, Waits
from ..helpers.manager import WazuhManager, WazuhAPI
from modules.testing.utils import logger
Expand Down Expand Up @@ -93,7 +93,10 @@ def test_agent_uninstalled_directory(wazuh_params):
path_to_check = WAZUH_ROOT
elif os_type == 'windows':
path_to_check = WINDOWS_CONFIGURATIONS_DIR
assert HostInformation.dir_exists(agent_params, path_to_check), logger.error(f'The {path_to_check} is still present in the agent {agent_names}')
elif os_type == 'macos':
path_to_check = MACOS_CONFIGURATIONS_DIR

assert not HostInformation.dir_exists(agent_params, path_to_check), logger.error(f'The {path_to_check} is still present in the agent {agent_names}')


def test_service(wazuh_params):
Expand Down

0 comments on commit 7490c95

Please sign in to comment.