Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unexpected warnings in E2E vulnerability detection tests #5711

Merged
merged 16 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file.

### Fixed

- Fix unexpected warnings in E2E vulnerability detection tests ([#5711](https://github.com/wazuh/wazuh-qa/pull/5711)) \- (Framework + Tests)
- Grafana package used for `upgrade_package_nonvulnerable_to_vulnerable` case is vulnerable ([#5719](https://github.com/wazuh/wazuh-qa/pull/5719)) \- (Tests)
- Increase results windows in E2E Vulnerability detection ([#5712](https://github.com/wazuh/wazuh-qa/pull/5712/)) \- (Framework + Tests)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,6 @@ def equals_but_not_empty(x, y):
empty = lambda x: len(x) == 0

no_errors = lambda x: all(
not any(x[host][level] for level in ["ERROR", "CRITICAL", "WARNING"])
not any(x[host][level] for level in ['ERROR', 'CRITICAL'])
for host in x
)
16 changes: 10 additions & 6 deletions deps/wazuh_testing/wazuh_testing/end_to_end/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,31 @@ def get_hosts_logs(host_manager: HostManager, host_group: str = 'all') -> Dict[s


def check_errors_in_environment(host_manager: HostManager, greater_than_timestamp: str = '',
expected_errors: List[str] = None) -> dict:
"""Check if there are errors in the environment
expected_errors: List[str] = None,
error_levels=None) -> dict:
"""Check if there are errors in the environment.

Args:
host_manager (HostManager): An instance of the HostManager class.
greater_than_timestamp (str): Timestamp to filter the logs
expected_errors (List): List of expected errors. Default None
error_levels (List): List of the error levels to check. Default None.

Returns:
dict: Errors found in the environment
"""

error_level_to_search = ['ERROR', 'CRITICAL', 'WARNING']
expected_errors = expected_errors or []
default_error_levels = ['ERROR', 'WARNING', 'CRITICAL']
if not expected_errors:
expected_errors = []
if not error_levels:
error_levels = default_error_levels

environment_logs = get_hosts_logs(host_manager)
environment_level_logs = {}

for host, environment_log in environment_logs.items():
environment_level_logs[host] = {}
for level in error_level_to_search:
for level in error_levels:
environment_level_logs[host][level] = []
regex = re.compile(fr'((\d{{4}}\/\d{{2}}\/\d{{2}} \d{{2}}:\d{{2}}:\d{{2}}) (.+): ({level}):(.*))')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,39 @@
state: present
when:
- wazuh_custom_packages_installation_manager_enabled
register: wazuh_manager_installation
retries: 4
delay: 30
until: wazuh_manager_installation is succeeded
when:
- ansible_os_family|lower == "debian"

- block:
- name: Install Wazuh Manager from .rpm packages | yum
yum:
name: "{{ wazuh_custom_packages_installation_manager_rpm_url }}"
state: present
when:
- wazuh_custom_packages_installation_manager_enabled
- not (ansible_distribution|lower == "centos" and ansible_distribution_major_version >= "8")
- not (ansible_distribution|lower == "redhat" and ansible_distribution_major_version >= "8")
- name: Install Wazuh Manager from .rpm packages | yum
yum:
name: "{{ wazuh_custom_packages_installation_manager_rpm_url }}"
state: present
when:
- wazuh_custom_packages_installation_manager_enabled
- not (ansible_distribution|lower == "centos" and ansible_distribution_major_version >= "8")
- not (ansible_distribution|lower == "redhat" and ansible_distribution_major_version >= "8")
register: wazuh_manager_installation_yum
retries: 4
delay: 30
until: wazuh_manager_installation_yum is succeeded

- name: Install Wazuh Manager from .rpm packages | dnf
dnf:
name: "{{ wazuh_custom_packages_installation_manager_rpm_url }}"
state: present
disable_gpg_check: True
when:
- wazuh_custom_packages_installation_manager_enabled
- (ansible_distribution|lower == "centos" and ansible_distribution_major_version >= "8") or
(ansible_distribution|lower == "redhat" and ansible_distribution_major_version >= "8")
- name: Install Wazuh Manager from .rpm packages | dnf
dnf:
name: "{{ wazuh_custom_packages_installation_manager_rpm_url }}"
state: present
disable_gpg_check: True
when:
- wazuh_custom_packages_installation_manager_enabled
- (ansible_distribution|lower == "centos" and ansible_distribution_major_version >= "8") or
(ansible_distribution|lower == "redhat" and ansible_distribution_major_version >= "8")
register: wazuh_manager_installation_dnf
retries: 4
delay: 30
until: wazuh_manager_installation_dnf is succeeded
when:
- ansible_os_family|lower == "redhat"
- ansible_os_family|lower == "redhat"
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
FIRST_SCAN_TIME = None
FIRST_SCAN_VULNERABILITIES_INDEX = {}
AGENT_REGISTRATION_TIMEOUT = 15
TIMEOUT_START_MANAGER = 60
TESTS_UNEXPECTED_ERRORS_LEVELS = ['ERROR', 'CRITICAL']

VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS = [
r"Invalid ID \d{3} for the source",
Expand Down Expand Up @@ -184,6 +186,9 @@ def configure_vulnerability_detection_test_environment(
host_manager, vulnerability_detection_previously_enabled
)

# Wait for 1 minute to ensure all managers have fully started
time.sleep(TIMEOUT_START_MANAGER)

start_agent_and_wait_until_connected(host_manager)

if not vulnerability_detection_previously_enabled:
Expand Down Expand Up @@ -380,7 +385,7 @@ def test_first_syscollector_scan(

logging.critical("Checking for errors in the environment")
unexpected_errors = check_errors_in_environment(
host_manager, expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS
host_manager, expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS, error_levels=TESTS_UNEXPECTED_ERRORS_LEVELS
)

test_result.validate_check(
Expand Down Expand Up @@ -533,7 +538,7 @@ def test_syscollector_second_scan(
unexpected_errors = check_errors_in_environment(
host_manager,
expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS,
greater_than_timestamp=get_timestamp
greater_than_timestamp=get_timestamp, error_levels=TESTS_UNEXPECTED_ERRORS_LEVELS
)

test_result.validate_check(
Expand Down Expand Up @@ -760,7 +765,7 @@ def test_install_vulnerable_package_when_agent_down(self, host_manager, request,
errors_environment = check_errors_in_environment(
host_manager,
expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS,
greater_than_timestamp=test_timestamp
greater_than_timestamp=test_timestamp, error_levels=TESTS_UNEXPECTED_ERRORS_LEVELS
)
test_result.validate_check("no_errors", [Evidence("error_level_messages", errors_environment)])

Expand Down Expand Up @@ -887,7 +892,7 @@ def test_change_agent_manager(self, permutate_agents_managers, request, precondi
errors_environment = check_errors_in_environment(
host_manager,
expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS,
greater_than_timestamp=test_timestamp
greater_than_timestamp=test_timestamp, error_levels=TESTS_UNEXPECTED_ERRORS_LEVELS
)

test_result.validate_check("no_errors", [Evidence("error_level_messages", errors_environment)])
Expand Down Expand Up @@ -1018,7 +1023,7 @@ def test_vulnerability_detector_scans_cases(self, request, preconditions, body,
errors_environment = check_errors_in_environment(
host_manager,
expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS,
greater_than_timestamp=test_timestamp
greater_than_timestamp=test_timestamp, error_levels=TESTS_UNEXPECTED_ERRORS_LEVELS
)

test_result.validate_check("no_errors", [Evidence("error_level_messages", errors_environment)])
Expand Down