Skip to content

Commit

Permalink
feat: include logger for VD E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebits committed Nov 21, 2023
1 parent a1a76b5 commit 0219de0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
5 changes: 5 additions & 0 deletions tests/end_to_end/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[pytest]
log_cli = 1
log_cli_level = ERROR
log_cli_format = %(asctime)s %(message)s (%(filename)s:%(lineno)s)
log_cli_date_format=%Y-%m-%d %H:%M:%S
30 changes: 26 additions & 4 deletions tests/end_to_end/test_vulnerability_detector/test_scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"""
import os
import pytest
import logging

from typing import Generator, Dict, List

Expand All @@ -56,7 +57,9 @@
from wazuh_testing.tools.system import HostManager


TIMEOUT_SYSCOLLECTOR_SCAN = 120
TIMEOUT_SYSCOLLECTOR_SCAN = 200
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

local_path = os.path.dirname(os.path.abspath(__file__))
current_dir = os.path.dirname(__file__)
Expand Down Expand Up @@ -86,25 +89,35 @@ def setup_vulnerability_tests(host_manager: HostManager) -> Generator:
Args:
host_manager (HostManager): An instance of the HostManager class.
"""
logger.error("Init setup of environment")

# Configure managers and agents
logger.error("Getting backup of current configurations")
hosts_configuration_backup = backup_configurations(host_manager)
logger.error("Configuring environment")
configure_environment(host_manager, load_vulnerability_detector_configurations())

# Restart managers and stop agents
logger.error("Stopping agents")
host_manager.control_environment('stop', ['agent'])
logger.error("Restarting managers")
host_manager.control_environment('restart', ['manager'])

# Wait until VD is updated
logger.error("Wait until Vulnerability Detector has update all the feeds")
wait_until_vd_is_updated(host_manager)

# Truncate alerts and logs of managers and agents
logger.error("Truncate managers and agents logs")
truncate_logs(host_manager)

# Start agents
logger.error("Starting agents")
host_manager.control_environment('start', ['agent'])

yield

logger.error("Restoring original configuration")
restore_backup(host_manager, hosts_configuration_backup)


Expand All @@ -130,6 +143,7 @@ def check_vuln_state_index(host_manager: HostManager, agents_vulnerabilities_api


@pytest.mark.dependency()
@pytest.mark.filterwarnings('ignore::urllib3.exceptions.InsecureRequestWarning')
def test_syscollector_initial_scans(host_manager, setup_vulnerability_tests):
"""
description: Validates the initiation of Syscollector scans across all agents in the environment.
Expand Down Expand Up @@ -162,6 +176,7 @@ def test_syscollector_initial_scans(host_manager, setup_vulnerability_tests):
- vulnerability_detector
"""
# Monitor for the first Syscollector scan in all the agents
logger.critical("Monitoring Syscollector First Scan")
monitoring_data = generate_monitoring_logs_all_agent(host_manager,
[get_event_regex({'event': 'syscollector_scan_start'}),
get_event_regex({'event': 'syscollector_scan_end'})],
Expand All @@ -170,25 +185,28 @@ def test_syscollector_initial_scans(host_manager, setup_vulnerability_tests):
monitoring_events_multihost(host_manager, monitoring_data)

# Truncate agents logs to detect second scan
logger.critical("Truncating agent's logs")
truncate_agents_logs(host_manager)

# Wait until all agents has been scanned
logger.critical("Waiting until agent's VD scan is over")
wait_until_vuln_scan_agents_finished(host_manager)

# Check vulnerabilities for agent
logger.critical("Check agent's vulnerabilities")
agents_vuln_before_second_scan = get_agents_vulnerabilities(host_manager)
for agent, vuln in agents_vuln_before_second_scan.items():
assert vuln, f"No vulnerabilities were detected for agent {agent}"

# Get agent's vulnerabilities
agents_vuln_before_second_scan = get_agents_vulnerabilities(host_manager)

# Compare agents_vuln_before_second_scan with state_index_content
logger.critical("Comparing state and API vulnerabilities for each agent")
check_vuln_state_index(host_manager, agents_vuln_before_second_scan)

# Truncate manager_logs to prevent trigger wait_until_vuln_scan_agents_finished wrongly
logger.critical("Truncating manager logs")
truncate_managers_logs(host_manager)

logger.critical("Monitoring Second Syscollector scan")
# The Agent's syscollector second scan is run
monitoring_data = generate_monitoring_logs_all_agent(host_manager,
[get_event_regex({'event': 'syscollector_scan_start'}),
Expand All @@ -200,12 +218,16 @@ def test_syscollector_initial_scans(host_manager, setup_vulnerability_tests):
# WARNING
# Is possible that second scan will not produce expected Finished Scan in the agent.
# In that case search for another event or include a hardcoded timeout
logger.critical("Waiting until agent's VD scan is over")
wait_until_vuln_scan_agents_finished(host_manager)

logger.critical("Getting agents's vulnerabilities")
agents_vuln_after_second_scan = get_agents_vulnerabilities(host_manager)

assert agents_vuln_before_second_scan == agents_vuln_after_second_scan

# Compare agents_vuln_after_second_scan with state_index_content
logger.critical("Comparing state and API vulnerabilities for each agent")
check_vuln_state_index(host_manager, agents_vuln_after_second_scan)


0 comments on commit 0219de0

Please sign in to comment.