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 10 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ All notable changes to this project will be documented in this file.

- Added support for macOS 14.6 to the Allocation module (Vagrant) ([#5671](https://github.com/wazuh/wazuh-qa/pull/5671)) \- (Framework)

### Fixed
- Fix unexpected warnings in E2E vulnerability detection tests ([#5711](https://github.com/wazuh/wazuh-qa/pull/5711/)) \- (Tests)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Fix unexpected warnings in E2E vulnerability detection tests ([#5711](https://github.com/wazuh/wazuh-qa/pull/5711/)) \- (Tests)
- Fix unexpected warnings in E2E vulnerability detection tests ([#5711](https://github.com/wazuh/wazuh-qa/pull/5711)) \- (Framework + Tests)

Copy link
Member Author

@Rebits Rebits Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 916d903 and b37d69d


## [4.9.0] - TBD

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ 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 @@ -81,6 +81,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 @@ -182,6 +184,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 @@ -371,7 +376,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 @@ -522,7 +527,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 @@ -747,7 +752,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 @@ -872,7 +877,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 @@ -1001,7 +1006,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