Skip to content

Commit

Permalink
fix(#5219): Port tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-akim committed May 2, 2024
1 parent 9b15424 commit abccdea
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 36 deletions.
7 changes: 2 additions & 5 deletions deployability/modules/testing/tests/helpers/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2

import requests
import socket
import json
import time

from .constants import CLUSTER_CONTROL, AGENT_CONTROL, WAZUH_CONF, WAZUH_ROOT
from .executor import ConnectionManager, WazuhAPI
from .generic import HostInformation, CheckFiles
from modules.testing.utils import logger
from .utils import Utils


class WazuhDashboard:
Expand Down Expand Up @@ -96,7 +92,8 @@ def is_dashboard_port_open(inventory_path, wait=10, cycles=50):
"""
wait_cycles = 0
while wait_cycles < cycles:
ports = ConnectionManager.execute_commands(inventory_path, 'ss -t -a -n | grep ":443"').get('output').strip().split('\n')
ports = ConnectionManager.execute_commands(inventory_path, 'ss -t -a -n | grep ":443"').get('output') or ""
ports = ports.strip().split('\n')
for port in ports:
if any(state in port for state in ['ESTAB', 'LISTEN']):
continue
Expand Down
2 changes: 1 addition & 1 deletion deployability/modules/testing/tests/helpers/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def __init__(self, inventory_path, component=None):
def _extract_password(self, file_path, keyword):
if not 'true' in ConnectionManager.execute_commands(self.inventory_path, f'test -f {file_path} && echo "true" || echo "false"').get('output'):
ConnectionManager.execute_commands(self.inventory_path, 'tar -xvf wazuh-install-files.tar')
return ConnectionManager.execute_command(self.inventory_path, f"grep {keyword} {file_path} | head -n 1 | awk '{{print $NF}}'").get('output').replace("'", "").replace("\n", "")
return ConnectionManager.execute_commands(self.inventory_path, f"grep {keyword} {file_path} | head -n 1 | awk '{{print $NF}}'").get('output').replace("'", "").replace("\n", "")

def _authenticate(self):
with open(self.inventory_path, 'r') as yaml_file:
Expand Down
3 changes: 2 additions & 1 deletion deployability/modules/testing/tests/helpers/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def is_indexer_port_open(inventory_path, wait=10, cycles=50) -> bool:
"""
wait_cycles = 0
while wait_cycles < cycles:
ports = ConnectionManager.execute_commands(inventory_path, 'ss -t -a -n | grep ":9200"').get('output').strip().split('\n')
ports = ConnectionManager.execute_commands(inventory_path, 'ss -t -a -n | grep ":9200"').get('output') or ""
ports = ports.strip().split('\n')
for port in ports:
if any(state in port for state in ['ESTAB', 'LISTEN']):
continue
Expand Down
9 changes: 6 additions & 3 deletions deployability/modules/testing/tests/helpers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ def is_wazuh_api_port_open(inventory_path, wait=10, cycles=50) -> bool:
"""
wait_cycles = 0
while wait_cycles < cycles:
ports = ConnectionManager.execute_commands(inventory_path, 'ss -t -a -n | grep ":55000"').get('output').strip().split('\n')
ports = ConnectionManager.execute_commands(inventory_path, 'ss -t -a -n | grep ":443"').get('output') or ""
ports = ports.strip().split('\n')
for port in ports:
if any(state in port for state in ['ESTAB', 'LISTEN']):
continue
Expand All @@ -259,7 +260,8 @@ def is_wazuh_agent_port_open(inventory_path, wait=10, cycles=50) -> bool:
"""
wait_cycles = 0
while wait_cycles < cycles:
ports = ConnectionManager.execute_commands(inventory_path, 'ss -t -a -n | grep ":1514"').get('output').strip().split('\n')
ports = ConnectionManager.execute_commands(inventory_path, 'ss -t -a -n | grep ":1514"').get('output') or ""
ports = ports.strip().split('\n')
for port in ports:
if any(state in port for state in ['ESTAB', 'LISTEN']):
continue
Expand All @@ -283,7 +285,8 @@ def is_wazuh_agent_enrollment_port_open(inventory_path, wait=10, cycles=50) -> b
"""
wait_cycles = 0
while wait_cycles < cycles:
ports = ConnectionManager.execute_commands(inventory_path, 'ss -t -a -n | grep ":443"').get('output').strip().split('\n')
ports = ConnectionManager.execute_commands(inventory_path, 'ss -t -a -n | grep ":443"').get('output') or ""
ports = ports.strip().split('\n')
for port in ports:
if any(state in port for state in ['ESTAB', 'LISTEN']):
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def test_installation(wazuh_params):

# Agent installation
for agent_name, agent_params in wazuh_params['agents'].items():
WazuhAgent.perform_install_and_scan_for_agent(agent_params, agent_name, wazuh_params)
#WazuhAgent.perform_install_and_scan_for_agent(agent_params, agent_name, wazuh_params)
WazuhAgent.install_agent(agent_params, agent_name, wazuh_params['wazuh_version'], wazuh_params['wazuh_revision'], wazuh_params['live'])

# Testing installation directory
for agent in wazuh_params['agents'].values():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def test_uninstall(wazuh_params):

# Agent uninstallation
for agent_names, agent_params in wazuh_params['agents'].items():
WazuhAgent.perform_uninstall_and_scan_for_agent(agent_params,wazuh_params)

#WazuhAgent.perform_uninstall_and_scan_for_agent(agent_params,wazuh_params)
WazuhAgent.uninstall_agent(agent_params, wazuh_params['wazuh_version'], wazuh_params['wazuh_revision'])

# Manager uninstallation status check
for agent_names, agent_params in wazuh_params['agents'].items():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ def setup_test_environment(wazuh_params):

def test_installation(wazuh_params):
# Disabling firewall for all managers
for manager_name, manager_params in wazuh_params['managers'].items():
for _, manager_params in wazuh_params['managers'].items():
Utils.check_inventory_connection(manager_params)
HostConfiguration.disable_firewall(manager_params)

# Certs create and scp from master to worker
HostConfiguration.certs_create(wazuh_params['wazuh_version'], wazuh_params['master'], wazuh_params['dashboard'], wazuh_params['indexers'], wazuh_params['workers'])

# Install central components and perform checkfile testing
for manager_name, manager_params in wazuh_params['managers'].items():
WazuhCentralComponents.perform_install_and_scan_for_aio(manager_params, wazuh_params)
for _, manager_params in wazuh_params['managers'].items():
#WazuhCentralComponents.perform_install_and_scan_for_aio(manager_params, wazuh_params)
WazuhCentralComponents.install_aio(manager_params, wazuh_params['wazuh_version'])

# Validation of directory of the components
for manager in wazuh_params['managers'].values():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ def test_manager_api_port(wazuh_params):


def test_manager_agent_port(wazuh_params):
assert not WazuhManager.is_wazuh_agent_port_open(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The Wazuh manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active")
assert not WazuhManager.is_wazuh_agent_port_open(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The Wazuh manager port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active")


def test_manager_agent_enrollment_port(wazuh_params):
assert not WazuhManager.is_wazuh_agent_enrollment_port_open(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The Wazuh manager API port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active")
assert not WazuhManager.is_wazuh_agent_enrollment_port_open(wazuh_params['master'], cycles=1, wait=1), logger.error(f"The Wazuh manager agent enrollment port in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} is still active")


def test_dashboard_port(wazuh_params):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def test_uninstall(wazuh_params):
assert 'active' in GeneralComponentActions.get_component_status(indexer_params, 'wazuh-indexer'), logger.error(f'The indexer in {HostInformation.get_os_name_and_version_from_inventory(indexer_params)} is not active')
assert 'active' in GeneralComponentActions.get_component_status(wazuh_params['master'], 'filebeat'), logger.error(f'The filebeat in {HostInformation.get_os_name_and_version_from_inventory(wazuh_params["master"])} is not active')

WazuhCentralComponents.perform_uninstall_and_scan_for_aio(wazuh_params['master'])

#WazuhCentralComponents.perform_uninstall_and_scan_for_aio(wazuh_params['master'])
WazuhCentralComponents.uninstall_aio(wazuh_params['master'])

def test_component_uninstalled_directory(wazuh_params):
assert not HostInformation.dir_exists(wazuh_params['master'], WAZUH_ROOT), logger.error(f"In {HostInformation.get_os_name_and_version_from_inventory(wazuh_params['master'])} {WAZUH_ROOT} is still present")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def test_installation(wazuh_params):

# Install managers and perform checkfile testing
for manager_name, manager_params in wazuh_params['managers'].items():
WazuhManager.perform_install_and_scan_for_manager(manager_params, manager_name, wazuh_params)
#WazuhManager.perform_install_and_scan_for_manager(manager_params, manager_name, wazuh_params)
WazuhManager.install_manager(manager_params, manager_name, wazuh_params['wazuh_version'])

# Validation of activity and directory of the managers
for manager in wazuh_params['managers'].values():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def test_uninstall(wazuh_params):
manager_status = GeneralComponentActions.get_component_status(manager, 'wazuh-manager')
assert 'active' in manager_status, logger.error(f'The {HostInformation.get_os_name_and_version_from_inventory(manager)} is not active')
for _, manager_params in wazuh_params['managers'].items():
WazuhManager.perform_uninstall_and_scan_for_manager(manager_params)

#WazuhManager.perform_uninstall_and_scan_for_manager(manager_params)
WazuhManager.uninstall_manager(manager_params)

def test_manager_uninstalled_directory(wazuh_params):
for manager in wazuh_params['managers'].values():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ version: 0.1
description: This workflow is used to test the Wazuh manager deployment for DDT1 PoC
variables:
central_components-os:
#- linux-ubuntu-22.04-amd64
#- linux-ubuntu-22.04-amd64
#- linux-oracle-9-amd64
#- linux-amazon-2-amd64
#- linux-redhat-7-amd64
#- linux-redhat-8-amd64
#- linux-redhat-9-amd64
- linux-ubuntu-22.04-amd64
- linux-ubuntu-22.04-amd64
- linux-oracle-9-amd64
- linux-amazon-2-amd64
- linux-redhat-7-amd64
- linux-redhat-8-amd64
- linux-redhat-9-amd64
- linux-centos-7-amd64
#- linux-centos-8-amd64
#- linux-debian-10-amd64
#- linux-debian-11-amd64
#- linux-debian-12-amd64
- linux-centos-8-amd64
- linux-debian-10-amd64
- linux-debian-11-amd64
- linux-debian-12-amd64
infra-provider: vagrant
working-dir: /tmp/dtt1-poc

Expand Down Expand Up @@ -51,8 +51,8 @@ tasks:
- wazuh-1: "{working-dir}/central_components-{central_components}/inventory.yaml"
- tests: "install,restart,stop,uninstall"
- component: "central_components"
- wazuh-version: "4.7.3"
- wazuh-revision: "40714"
- wazuh-version: "4.7.4"
- wazuh-revision: "40717"
- live: "True"
on-error: "abort-all"
foreach:
Expand Down

0 comments on commit abccdea

Please sign in to comment.