report.html

Report generated on 07-May-2024 at 14:00:29 by pytest-html v3.1.1

Summary

16 tests ran in 5998.25 seconds.

7 passed, 0 skipped, 9 failed, 0 errors, 0 expected failures, 0 unexpected passes
Tests Failed Success XFail Error
test_vulnerability_detector/test_vulnerability_detector.py 9 7 0 0

Results

Result Test Description Duration Links
Failed test_vulnerability_detector/test_vulnerability_detector.py::TestInitialScans::test_consistency_initial_scans description: Ensure the consistency of the agent's vulnerabilities neither the agent was registered nor. 0.00

Test function details

Extended Summary

This test ensures that the agent's vulnerabilities are consistent with the initial scan.
tier: 0
parameters:
- request: pytest request object
- host_manager:
type: fixture
brief: Get the host manager of the environment
assertions:
- Verify that the number of vulnerabilities is the same between scans

Parameters

self = <test_vulnerability_detector.TestInitialScans object at 0x7dd0c4217b20>, request = <FixtureRequest for <Function test_consistency_initial_scans>>
record_property = <function record_property.<locals>.append_property at 0x7dd0c36c7eb0>

def test_consistency_initial_scans(self, request, record_property):
"""
description: Ensure the consistency of the agent's vulnerabilities neither the agent was registered nor.

This test ensures that the agent's vulnerabilities are consistent with the initial scan.

tier: 0

parameters:
- request: pytest request object
- host_manager:
type: fixture
brief: Get the host manager of the environment

assertions:
- Verify that the number of vulnerabilities is the same between scans
"""
test_result = TestResult(request.node.name)
test_result.add_check(self.initial_vulnerabilities_consistent)

record_property("test_result", test_result)
test_result.validate_check(
"initial_vulnerabilities_consistent",
[
Evidence(
"vd_disabled_when_agents_registration",
INITIAL_VULNERABILITIES["vd_disabled_when_agents_registration"],
),
Evidence(
"vd_enabled_when_agents_registration",
INITIAL_VULNERABILITIES["vd_enabled_when_agents_registration"],
),
],
)

> assert test_result.get_test_result(), test_result.report()
E AssertionError:
E Test test_consistency_initial_scans failed
E
E Check initial_vulnerabilities_consistent failed. Evidences (['vd_disabled_when_agents_registration', 'vd_enabled_when_agents_registration']) can be found in the report.
E -----
E
E assert False
E + where False = <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c367bd30>>()
E + where <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c367bd30>> = <wazuh_testing.end_to_end.TestResult object at 0x7dd0c367bd30>.get_test_result

end_to_end/test_vulnerability_detector/test_vulnerability_detector.py:411: AssertionError
-------------------------------Captured log call--------------------------------
ERROR root:__init__.py:237 Marked check initial_vulnerabilities_consistent result to False with evidences ['vd_disabled_when_agents_registration', 'vd_enabled_when_agents_registration']
Failed test_vulnerability_detector/test_vulnerability_detector.py::TestScanSyscollectorCases::test_change_agent_manager[install_package] 323.89

Test function details

Extended Summary

Parameters

self = <test_vulnerability_detector.TestScanSyscollectorCases object at 0x7dd0c4216ad0>, permutate_agents_managers = None
request = <FixtureRequest for <Function test_change_agent_manager[install_package]>>, preconditions = None
body = {'operation': 'install_package', 'package': {'centos': {'amd64': 'grafana-8.5.5-1', 'arm64v8': 'grafana-8.5.5-1'}, 'ma...proxy-0.5.9'}, 'ubuntu': {'amd64': 'grafana-8.5.5', 'arm64v8': 'grafana-8.5.5'}, 'windows': {'amd64': 'node-v17.0.1'}}}
teardown = {'operation': 'remove_package', 'package': {'centos': {'amd64': 'grafana-8.5.5-1', 'arm64v8': 'grafana-8.5.5-1'}, 'mac...proxy-0.5.9'}, 'ubuntu': {'amd64': 'grafana-8.5.5', 'arm64v8': 'grafana-8.5.5'}, 'windows': {'amd64': 'node-v17.0.1'}}}
setup = [], host_manager = <wazuh_testing.tools.system.HostManager object at 0x7dd0c425f850>, record_property = <function record_property.<locals>.append_property at 0x7dd0c3743d90>
clean_environment_logs = None, delete_states_vulnerability_index = None, clean_environment_logs_function = None

@pytest.mark.parametrize("preconditions, body, teardown", test_cases_change_manager,
ids=list_ids_change_manager,)
def test_change_agent_manager(self, permutate_agents_managers, request, preconditions, body,
teardown, setup, host_manager, record_property, clean_environment_logs,
delete_states_vulnerability_index, clean_environment_logs_function):
# Is mandatory to launch this test along with the first scan test'
global AGENTS_SCANNED_FIRST_SCAN
if len(AGENTS_SCANNED_FIRST_SCAN) == 0:
pytest.skip("No agent was scanned in the first scan. Skipping test.")

target_to_ignore = list(
set(host_manager.get_group_hosts("agent")) - set(AGENTS_SCANNED_FIRST_SCAN)
)

utc_now_timestamp = datetime.datetime.now(datetime.timezone.utc)
test_timestamp = utc_now_timestamp.strftime("%Y-%m-%dT%H:%M:%S")

test_result = TestResult(request.node.name)
test_result.add_check(self.no_errors_check)
test_result.add_check(self.operation_successfull_for_all_agents_check)
test_result.add_check(self.expected_vulnerabilities_found_in_index_check)
test_result.add_check(self.no_unexpected_vulnerabilities_found_in_index_check)
test_result.add_check(self.expected_vulnerability_affected_alert_check)
test_result.add_check(self.expected_vulnerability_mitigated_alert_check)
test_result.add_check(self.no_duplicated_vulnerabilities_check)

record_property("test_result", test_result)

# Install Vulnerable package
operations_result = launch_parallel_operations(
body, host_manager, target_to_ignore
)

logging.critical(f"Remote operation results: {operations_result}")
test_result.validate_check(
"operation_successfull_for_all_agents",
[Evidence("operation_results", operations_result)],
)

# Wait for Syscollector and VD Scan
time.sleep(VD_E2E_TIMEOUT_SYSCOLLECTOR_SCAN + PACKAGE_VULNERABILITY_SCAN_TIME)

package_data = [body["package"]]

vulnerabilities = get_vulnerabilities_index(host_manager, AGENTS_SCANNED_FIRST_SCAN, package_data)
expected_vulnerabilities = get_expected_index(host_manager, AGENTS_SCANNED_FIRST_SCAN, body["operation"],
body["package"])

result = compare_expected_found_vulnerabilities(vulnerabilities, expected_vulnerabilities)

vulnerabilities_not_found = result["vulnerabilities_not_found"]
vulnerabilities_unexpected = result["vulnerabilities_unexpected"]
duplicated_vulnerabilities = get_duplicated_vulnerabilities(vulnerabilities)

logging.critical("Validating found vulnerabilities")
test_result.validate_check('no_duplicated_vulnerabilities',
[Evidence('duplicated_vulnerabilities', duplicated_vulnerabilities),
Evidence('vulnerabilities', vulnerabilities)
])

test_result.validate_check(
"expected_vulnerabilities_found_in_index",
[
Evidence("missing_vulnerabilities", vulnerabilities_not_found),
Evidence("vulnerabilities_found_in_index", vulnerabilities),
Evidence("expected_vulnerabilities", expected_vulnerabilities),
],
)

logging.critical("Validating unexpected vulnerabilities")
test_result.validate_check(
"no_unexpected_vulnerabilities_found_in_index",
[
Evidence("unexpected_vulnerabilities", vulnerabilities_unexpected),
Evidence("vulnerabilities_found_in_index", vulnerabilities),
Evidence("expected_vulnerabilities", expected_vulnerabilities),
],
)

alerts = get_vulnerability_alerts(
host_manager, AGENTS_SCANNED_FIRST_SCAN, package_data, test_timestamp
)
expected_alerts = get_expected_alerts(
host_manager, AGENTS_SCANNED_FIRST_SCAN, body["operation"], body["package"]
)

result_alert = compare_expected_found_vulnerabilities_alerts(
alerts, expected_alerts
)

logging.critical("Validating found alerts")
test_result.validate_check(
"expected_vulnerability_affected_alert",
[
Evidence(
"missing_affected_alerts",
result_alert["vulnerabilities_affected_not_found"],
),
Evidence("alerts_found_in_index", alerts),
Evidence("expected_alerts", expected_alerts),
],
)

logging.critical("Validating unexpected alerts")
test_result.validate_check(
"expected_vulnerability_mitigated_alert",
[
Evidence(
"missing_mitigated_alerts",
result_alert["vulnerabilities_mitigated_not_found"],
),
Evidence("alerts_found_in_index", alerts),
Evidence("expected_alerts", expected_alerts),
],
)

errors_environment = check_errors_in_environment(
host_manager,
expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS,
greater_than_timestamp=test_timestamp,
)

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

> assert test_result.get_test_result(), test_result.report()
E AssertionError:
E Test test_change_agent_manager[install_package] failed
E
E Check no_errors succeeded
E Check operation_successfull_for_all_agents succeeded
E Check expected_vulnerabilities_found_in_index succeeded
E Check no_unexpected_vulnerabilities_found_in_index succeeded
E Check expected_vulnerability_affected_alert failed. Evidences (['missing_affected_alerts']) can be found in the report.
E Check expected_vulnerability_mitigated_alert succeeded
E Check no_duplicated_vulnerabilities succeeded
E -----
E
E assert False
E + where False = <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c36bf7c0>>()
E + where <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c36bf7c0>> = <wazuh_testing.end_to_end.TestResult object at 0x7dd0c36bf7c0>.get_test_result

end_to_end/test_vulnerability_detector/test_vulnerability_detector.py:864: AssertionError
-------------------------------Captured log setup-------------------------------
ERROR root:test_vulnerability_detector.py:620 Changing manager for agent agent1 to manager1 (44.220.87.99)
-------------------------------Captured log call--------------------------------
CRITICAL root:test_vulnerability_detector.py:773 Remote operation results: {'agent1': True} ERROR root:__init__.py:237 Marked check operation_successfull_for_all_agents result to True with evidences ['operation_results'] CRITICAL root:test_vulnerability_detector.py:794 Validating found vulnerabilities ERROR root:__init__.py:237 Marked check no_duplicated_vulnerabilities result to True with evidences ['duplicated_vulnerabilities', 'vulnerabilities'] ERROR root:__init__.py:237 Marked check expected_vulnerabilities_found_in_index result to True with evidences ['missing_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:809 Validating unexpected vulnerabilities ERROR root:__init__.py:237 Marked check no_unexpected_vulnerabilities_found_in_index result to True with evidences ['unexpected_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:check_validators.py:123 Vulnerabilities affected not found: {'agent1': [Vulnerability(cve='CVE-2017-16014', package_name='http-proxy', package_version='0.5.9', architecture='')]} CRITICAL root:check_validators.py:124 Vulnerabilities mitigated not found: {} CRITICAL root:test_vulnerability_detector.py:830 Validating found alerts CRITICAL root:check_validators.py:145 agent1 is not empty: [Vulnerability(cve='CVE-2017-16014', package_name='http-proxy', package_version='0.5.9', architecture='')] ERROR root:__init__.py:237 Marked check expected_vulnerability_affected_alert result to False with evidences ['missing_affected_alerts', 'alerts_found_in_index', 'expected_alerts'] CRITICAL root:test_vulnerability_detector.py:843 Validating unexpected alerts ERROR root:__init__.py:237 Marked check expected_vulnerability_mitigated_alert result to True with evidences ['missing_mitigated_alerts', 'alerts_found_in_index', 'expected_alerts'] ERROR root:__init__.py:237 Marked check no_errors result to True with evidences ['error_level_messages']
-----------------------------Captured log teardown------------------------------
ERROR root:conftest.py:152 Truncate managers and agents logs
Failed test_vulnerability_detector/test_vulnerability_detector.py::TestScanSyscollectorCases::test_vulnerability_detector_scans_cases[install_package] 285.29

Test function details

Extended Summary

Parameters

self = <test_vulnerability_detector.TestScanSyscollectorCases object at 0x7dd0c42165f0>, request = <FixtureRequest for <Function test_vulnerability_detector_scans_cases[install_package]>>
preconditions = None
body = {'operation': 'install_package', 'package': {'centos': {'amd64': 'grafana-8.5.5-1', 'arm64v8': 'grafana-8.5.5-1'}, 'ma...proxy-0.5.9'}, 'ubuntu': {'amd64': 'grafana-8.5.5', 'arm64v8': 'grafana-8.5.5'}, 'windows': {'amd64': 'node-v17.0.1'}}}
teardown = None, setup = [], host_manager = <wazuh_testing.tools.system.HostManager object at 0x7dd0c425f850>, record_property = <function record_property.<locals>.append_property at 0x7dd0c37415a0>
clean_environment_logs = None, delete_states_vulnerability_index = None, clean_environment_logs_function = None

@pytest.mark.parametrize("preconditions, body, teardown", complete_list, ids=list_ids)
def test_vulnerability_detector_scans_cases(self, request, preconditions, body, teardown, setup, host_manager,
record_property, clean_environment_logs,
delete_states_vulnerability_index,
clean_environment_logs_function):
# Is mandatory to launch this test along with the first scan test'
global AGENTS_SCANNED_FIRST_SCAN
if len(AGENTS_SCANNED_FIRST_SCAN) == 0:
pytest.skip("No agent was scanned in the first scan. Skipping test.")

target_to_ignore = list(
set(host_manager.get_group_hosts("agent")) - set(AGENTS_SCANNED_FIRST_SCAN)
)

utc_now_timestamp = datetime.datetime.now(datetime.timezone.utc)
test_timestamp = utc_now_timestamp.strftime("%Y-%m-%dT%H:%M:%S")

test_result = TestResult(request.node.name)
test_result.add_check(self.no_errors_check)
test_result.add_check(self.operation_successfull_for_all_agents_check)
test_result.add_check(self.expected_vulnerabilities_found_in_index_check)
test_result.add_check(self.no_unexpected_vulnerabilities_found_in_index_check)
test_result.add_check(self.expected_vulnerability_affected_alert_check)
test_result.add_check(self.expected_vulnerability_mitigated_alert_check)
test_result.add_check(self.setup_successfull_for_all_agents_check)
test_result.add_check(self.no_duplicated_vulnerabilities_check)

record_property("test_result", test_result)

agents_failed_setup = setup
test_result.validate_check("setup_operation_results", [Evidence("setup_failed_agents", agents_failed_setup)])

# Install Vulnerable package
operations_result = launch_parallel_operations(
body, host_manager, target_to_ignore
)

logging.critical(f"Remote operation results: {operations_result}")
test_result.validate_check(
"operation_successfull_for_all_agents",
[Evidence("operation_results", operations_result)],
)
# Wait for syscollector and VD scan
time.sleep(VD_E2E_TIMEOUT_SYSCOLLECTOR_SCAN + PACKAGE_VULNERABILITY_SCAN_TIME)

if "to" in body["package"]:
package_data = [body["package"]["to"], body["package"]["from"]]
else:
package_data = [body["package"]]

vulnerabilities = get_vulnerabilities_index(host_manager, AGENTS_SCANNED_FIRST_SCAN, package_data)
expected_vulnerabilities = get_expected_index(host_manager, AGENTS_SCANNED_FIRST_SCAN,
body["operation"], body["package"])
duplicated_vulnerabilities = get_duplicated_vulnerabilities(vulnerabilities)

result = compare_expected_found_vulnerabilities(vulnerabilities, expected_vulnerabilities)
vulnerabilities_not_found = result["vulnerabilities_not_found"]
vulnerabilities_unexpected = result["vulnerabilities_unexpected"]

test_result.validate_check('no_duplicated_vulnerabilities',
[Evidence('duplicated_vulnerabilities', duplicated_vulnerabilities),
Evidence('vulnerabilities', vulnerabilities)
])

logging.critical("Validating found vulnerabilities")
test_result.validate_check(
"expected_vulnerabilities_found_in_index",
[
Evidence("missing_vulnerabilities", vulnerabilities_not_found),
Evidence("vulnerabilities_found_in_index", vulnerabilities),
Evidence("expected_vulnerabilities", expected_vulnerabilities),
],
)

logging.critical("Validating unexpected vulnerabilities")
test_result.validate_check(
"no_unexpected_vulnerabilities_found_in_index",
[
Evidence("unexpected_vulnerabilities", vulnerabilities_unexpected),
Evidence("vulnerabilities_found_in_index", vulnerabilities),
Evidence("expected_vulnerabilities", expected_vulnerabilities),
],
)

alerts = get_vulnerability_alerts(host_manager, AGENTS_SCANNED_FIRST_SCAN, package_data, test_timestamp)
expected_alerts = get_expected_alerts(
host_manager, AGENTS_SCANNED_FIRST_SCAN, body["operation"], body["package"]
)

result_alert = compare_expected_found_vulnerabilities_alerts(
alerts, expected_alerts
)

logging.critical("Validating found alerts")
test_result.validate_check(
"expected_vulnerability_affected_alert",
[
Evidence(
"missing_affected_alerts",
result_alert["vulnerabilities_affected_not_found"],
),
Evidence("alerts_found_in_index", alerts),
Evidence("expected_alerts", expected_alerts),
],
)

logging.critical("Validating unexpected alerts")
test_result.validate_check(
"expected_vulnerability_mitigated_alert",
[
Evidence(
"missing_mitigated_alerts",
result_alert["vulnerabilities_mitigated_not_found"],
),
Evidence("alerts_found_in_index", alerts),
Evidence("expected_alerts", expected_alerts),
],
)

errors_environment = check_errors_in_environment(
host_manager,
expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS,
greater_than_timestamp=test_timestamp,
)

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

> assert test_result.get_test_result(), test_result.report()
E AssertionError:
E Test test_vulnerability_detector_scans_cases[install_package] failed
E
E Check no_errors succeeded
E Check operation_successfull_for_all_agents succeeded
E Check expected_vulnerabilities_found_in_index succeeded
E Check no_unexpected_vulnerabilities_found_in_index succeeded
E Check expected_vulnerability_affected_alert failed. Evidences (['missing_affected_alerts']) can be found in the report.
E Check expected_vulnerability_mitigated_alert succeeded
E Check setup_operation_results succeeded
E Check no_duplicated_vulnerabilities succeeded
E -----
E
E assert False
E + where False = <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c40038b0>>()
E + where <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c40038b0>> = <wazuh_testing.end_to_end.TestResult object at 0x7dd0c40038b0>.get_test_result

end_to_end/test_vulnerability_detector/test_vulnerability_detector.py:993: AssertionError
-------------------------------Captured log call--------------------------------
ERROR root:__init__.py:237 Marked check setup_operation_results result to True with evidences ['setup_failed_agents'] CRITICAL root:test_vulnerability_detector.py:903 Remote operation results: {'agent1': True} ERROR root:__init__.py:237 Marked check operation_successfull_for_all_agents result to True with evidences ['operation_results'] ERROR root:__init__.py:237 Marked check no_duplicated_vulnerabilities result to True with evidences ['duplicated_vulnerabilities', 'vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:930 Validating found vulnerabilities ERROR root:__init__.py:237 Marked check expected_vulnerabilities_found_in_index result to True with evidences ['missing_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:940 Validating unexpected vulnerabilities ERROR root:__init__.py:237 Marked check no_unexpected_vulnerabilities_found_in_index result to True with evidences ['unexpected_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:check_validators.py:123 Vulnerabilities affected not found: {'agent1': [Vulnerability(cve='CVE-2017-16014', package_name='http-proxy', package_version='0.5.9', architecture='')]} CRITICAL root:check_validators.py:124 Vulnerabilities mitigated not found: {} CRITICAL root:test_vulnerability_detector.py:959 Validating found alerts CRITICAL root:check_validators.py:145 agent1 is not empty: [Vulnerability(cve='CVE-2017-16014', package_name='http-proxy', package_version='0.5.9', architecture='')] ERROR root:__init__.py:237 Marked check expected_vulnerability_affected_alert result to False with evidences ['missing_affected_alerts', 'alerts_found_in_index', 'expected_alerts'] CRITICAL root:test_vulnerability_detector.py:972 Validating unexpected alerts ERROR root:__init__.py:237 Marked check expected_vulnerability_mitigated_alert result to True with evidences ['missing_mitigated_alerts', 'alerts_found_in_index', 'expected_alerts'] ERROR root:__init__.py:237 Marked check no_errors result to True with evidences ['error_level_messages']
-----------------------------Captured log teardown------------------------------
ERROR root:conftest.py:152 Truncate managers and agents logs
Failed test_vulnerability_detector/test_vulnerability_detector.py::TestScanSyscollectorCases::test_vulnerability_detector_scans_cases[remove_package] 282.14

Test function details

Extended Summary

Parameters

self = <test_vulnerability_detector.TestScanSyscollectorCases object at 0x7dd0c42166e0>, request = <FixtureRequest for <Function test_vulnerability_detector_scans_cases[remove_package]>>
preconditions = None
body = {'operation': 'remove_package', 'package': {'centos': {'amd64': 'grafana-8.5.5-1', 'arm64v8': 'grafana-8.5.5-1'}, 'mac...proxy-0.5.9'}, 'ubuntu': {'amd64': 'grafana-8.5.5', 'arm64v8': 'grafana-8.5.5'}, 'windows': {'amd64': 'node-v17.0.1'}}}
teardown = None, setup = [], host_manager = <wazuh_testing.tools.system.HostManager object at 0x7dd0c425f850>, record_property = <function record_property.<locals>.append_property at 0x7dd0c3711ea0>
clean_environment_logs = None, delete_states_vulnerability_index = None, clean_environment_logs_function = None

@pytest.mark.parametrize("preconditions, body, teardown", complete_list, ids=list_ids)
def test_vulnerability_detector_scans_cases(self, request, preconditions, body, teardown, setup, host_manager,
record_property, clean_environment_logs,
delete_states_vulnerability_index,
clean_environment_logs_function):
# Is mandatory to launch this test along with the first scan test'
global AGENTS_SCANNED_FIRST_SCAN
if len(AGENTS_SCANNED_FIRST_SCAN) == 0:
pytest.skip("No agent was scanned in the first scan. Skipping test.")

target_to_ignore = list(
set(host_manager.get_group_hosts("agent")) - set(AGENTS_SCANNED_FIRST_SCAN)
)

utc_now_timestamp = datetime.datetime.now(datetime.timezone.utc)
test_timestamp = utc_now_timestamp.strftime("%Y-%m-%dT%H:%M:%S")

test_result = TestResult(request.node.name)
test_result.add_check(self.no_errors_check)
test_result.add_check(self.operation_successfull_for_all_agents_check)
test_result.add_check(self.expected_vulnerabilities_found_in_index_check)
test_result.add_check(self.no_unexpected_vulnerabilities_found_in_index_check)
test_result.add_check(self.expected_vulnerability_affected_alert_check)
test_result.add_check(self.expected_vulnerability_mitigated_alert_check)
test_result.add_check(self.setup_successfull_for_all_agents_check)
test_result.add_check(self.no_duplicated_vulnerabilities_check)

record_property("test_result", test_result)

agents_failed_setup = setup
test_result.validate_check("setup_operation_results", [Evidence("setup_failed_agents", agents_failed_setup)])

# Install Vulnerable package
operations_result = launch_parallel_operations(
body, host_manager, target_to_ignore
)

logging.critical(f"Remote operation results: {operations_result}")
test_result.validate_check(
"operation_successfull_for_all_agents",
[Evidence("operation_results", operations_result)],
)
# Wait for syscollector and VD scan
time.sleep(VD_E2E_TIMEOUT_SYSCOLLECTOR_SCAN + PACKAGE_VULNERABILITY_SCAN_TIME)

if "to" in body["package"]:
package_data = [body["package"]["to"], body["package"]["from"]]
else:
package_data = [body["package"]]

vulnerabilities = get_vulnerabilities_index(host_manager, AGENTS_SCANNED_FIRST_SCAN, package_data)
expected_vulnerabilities = get_expected_index(host_manager, AGENTS_SCANNED_FIRST_SCAN,
body["operation"], body["package"])
duplicated_vulnerabilities = get_duplicated_vulnerabilities(vulnerabilities)

result = compare_expected_found_vulnerabilities(vulnerabilities, expected_vulnerabilities)
vulnerabilities_not_found = result["vulnerabilities_not_found"]
vulnerabilities_unexpected = result["vulnerabilities_unexpected"]

test_result.validate_check('no_duplicated_vulnerabilities',
[Evidence('duplicated_vulnerabilities', duplicated_vulnerabilities),
Evidence('vulnerabilities', vulnerabilities)
])

logging.critical("Validating found vulnerabilities")
test_result.validate_check(
"expected_vulnerabilities_found_in_index",
[
Evidence("missing_vulnerabilities", vulnerabilities_not_found),
Evidence("vulnerabilities_found_in_index", vulnerabilities),
Evidence("expected_vulnerabilities", expected_vulnerabilities),
],
)

logging.critical("Validating unexpected vulnerabilities")
test_result.validate_check(
"no_unexpected_vulnerabilities_found_in_index",
[
Evidence("unexpected_vulnerabilities", vulnerabilities_unexpected),
Evidence("vulnerabilities_found_in_index", vulnerabilities),
Evidence("expected_vulnerabilities", expected_vulnerabilities),
],
)

alerts = get_vulnerability_alerts(host_manager, AGENTS_SCANNED_FIRST_SCAN, package_data, test_timestamp)
expected_alerts = get_expected_alerts(
host_manager, AGENTS_SCANNED_FIRST_SCAN, body["operation"], body["package"]
)

result_alert = compare_expected_found_vulnerabilities_alerts(
alerts, expected_alerts
)

logging.critical("Validating found alerts")
test_result.validate_check(
"expected_vulnerability_affected_alert",
[
Evidence(
"missing_affected_alerts",
result_alert["vulnerabilities_affected_not_found"],
),
Evidence("alerts_found_in_index", alerts),
Evidence("expected_alerts", expected_alerts),
],
)

logging.critical("Validating unexpected alerts")
test_result.validate_check(
"expected_vulnerability_mitigated_alert",
[
Evidence(
"missing_mitigated_alerts",
result_alert["vulnerabilities_mitigated_not_found"],
),
Evidence("alerts_found_in_index", alerts),
Evidence("expected_alerts", expected_alerts),
],
)

errors_environment = check_errors_in_environment(
host_manager,
expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS,
greater_than_timestamp=test_timestamp,
)

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

> assert test_result.get_test_result(), test_result.report()
E AssertionError:
E Test test_vulnerability_detector_scans_cases[remove_package] failed
E
E Check no_errors succeeded
E Check operation_successfull_for_all_agents succeeded
E Check expected_vulnerabilities_found_in_index succeeded
E Check no_unexpected_vulnerabilities_found_in_index succeeded
E Check expected_vulnerability_affected_alert succeeded
E Check expected_vulnerability_mitigated_alert failed. Evidences (['missing_mitigated_alerts']) can be found in the report.
E Check setup_operation_results succeeded
E Check no_duplicated_vulnerabilities succeeded
E -----
E
E assert False
E + where False = <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c29fd630>>()
E + where <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c29fd630>> = <wazuh_testing.end_to_end.TestResult object at 0x7dd0c29fd630>.get_test_result

end_to_end/test_vulnerability_detector/test_vulnerability_detector.py:993: AssertionError
-------------------------------Captured log call--------------------------------
ERROR root:__init__.py:237 Marked check setup_operation_results result to True with evidences ['setup_failed_agents'] CRITICAL root:test_vulnerability_detector.py:903 Remote operation results: {'agent1': True} ERROR root:__init__.py:237 Marked check operation_successfull_for_all_agents result to True with evidences ['operation_results'] ERROR root:__init__.py:237 Marked check no_duplicated_vulnerabilities result to True with evidences ['duplicated_vulnerabilities', 'vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:930 Validating found vulnerabilities ERROR root:__init__.py:237 Marked check expected_vulnerabilities_found_in_index result to True with evidences ['missing_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:940 Validating unexpected vulnerabilities ERROR root:__init__.py:237 Marked check no_unexpected_vulnerabilities_found_in_index result to True with evidences ['unexpected_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:check_validators.py:123 Vulnerabilities affected not found: {} CRITICAL root:check_validators.py:124 Vulnerabilities mitigated not found: {'agent1': [Vulnerability(cve='CVE-2017-16014', package_name='http-proxy', package_version='0.5.9', architecture='')]} CRITICAL root:test_vulnerability_detector.py:959 Validating found alerts ERROR root:__init__.py:237 Marked check expected_vulnerability_affected_alert result to True with evidences ['missing_affected_alerts', 'alerts_found_in_index', 'expected_alerts'] CRITICAL root:test_vulnerability_detector.py:972 Validating unexpected alerts CRITICAL root:check_validators.py:145 agent1 is not empty: [Vulnerability(cve='CVE-2017-16014', package_name='http-proxy', package_version='0.5.9', architecture='')] ERROR root:__init__.py:237 Marked check expected_vulnerability_mitigated_alert result to False with evidences ['missing_mitigated_alerts', 'alerts_found_in_index', 'expected_alerts'] ERROR root:__init__.py:237 Marked check no_errors result to True with evidences ['error_level_messages']
-----------------------------Captured log teardown------------------------------
ERROR root:conftest.py:152 Truncate managers and agents logs
Failed test_vulnerability_detector/test_vulnerability_detector.py::TestScanSyscollectorCases::test_vulnerability_detector_scans_cases[upgrade_package_maintain_vulnerability] 483.62

Test function details

Extended Summary

Parameters

self = <test_vulnerability_detector.TestScanSyscollectorCases object at 0x7dd0c4216110>
request = <FixtureRequest for <Function test_vulnerability_detector_scans_cases[upgrade_package_maintain_vulnerability]>>
preconditions = {'operation': 'install_package', 'package': {'centos': {'amd64': 'grafana-8.5.5-1', 'arm64v8': 'grafana-8.5.5-1'}, 'ma...proxy-0.5.9'}, 'ubuntu': {'amd64': 'grafana-8.5.5', 'arm64v8': 'grafana-8.5.5'}, 'windows': {'amd64': 'node-v17.0.1'}}}
body = {'operation': 'update_package', 'package': {'from': {'centos': {'amd64': 'grafana-8.5.5-1', 'arm64v8': 'grafana-8.5.5-...oxy-0.5.10'}, 'ubuntu': {'amd64': 'grafana-8.5.6', 'arm64v8': 'grafana-8.5.6'}, 'windows': {'amd64': 'node-v17.1.0'}}}}
teardown = None, setup = ['agent1'], host_manager = <wazuh_testing.tools.system.HostManager object at 0x7dd0c425f850>
record_property = <function record_property.<locals>.append_property at 0x7dd0c37435b0>, clean_environment_logs = None, delete_states_vulnerability_index = None, clean_environment_logs_function = None

@pytest.mark.parametrize("preconditions, body, teardown", complete_list, ids=list_ids)
def test_vulnerability_detector_scans_cases(self, request, preconditions, body, teardown, setup, host_manager,
record_property, clean_environment_logs,
delete_states_vulnerability_index,
clean_environment_logs_function):
# Is mandatory to launch this test along with the first scan test'
global AGENTS_SCANNED_FIRST_SCAN
if len(AGENTS_SCANNED_FIRST_SCAN) == 0:
pytest.skip("No agent was scanned in the first scan. Skipping test.")

target_to_ignore = list(
set(host_manager.get_group_hosts("agent")) - set(AGENTS_SCANNED_FIRST_SCAN)
)

utc_now_timestamp = datetime.datetime.now(datetime.timezone.utc)
test_timestamp = utc_now_timestamp.strftime("%Y-%m-%dT%H:%M:%S")

test_result = TestResult(request.node.name)
test_result.add_check(self.no_errors_check)
test_result.add_check(self.operation_successfull_for_all_agents_check)
test_result.add_check(self.expected_vulnerabilities_found_in_index_check)
test_result.add_check(self.no_unexpected_vulnerabilities_found_in_index_check)
test_result.add_check(self.expected_vulnerability_affected_alert_check)
test_result.add_check(self.expected_vulnerability_mitigated_alert_check)
test_result.add_check(self.setup_successfull_for_all_agents_check)
test_result.add_check(self.no_duplicated_vulnerabilities_check)

record_property("test_result", test_result)

agents_failed_setup = setup
test_result.validate_check("setup_operation_results", [Evidence("setup_failed_agents", agents_failed_setup)])

# Install Vulnerable package
operations_result = launch_parallel_operations(
body, host_manager, target_to_ignore
)

logging.critical(f"Remote operation results: {operations_result}")
test_result.validate_check(
"operation_successfull_for_all_agents",
[Evidence("operation_results", operations_result)],
)
# Wait for syscollector and VD scan
time.sleep(VD_E2E_TIMEOUT_SYSCOLLECTOR_SCAN + PACKAGE_VULNERABILITY_SCAN_TIME)

if "to" in body["package"]:
package_data = [body["package"]["to"], body["package"]["from"]]
else:
package_data = [body["package"]]

vulnerabilities = get_vulnerabilities_index(host_manager, AGENTS_SCANNED_FIRST_SCAN, package_data)
expected_vulnerabilities = get_expected_index(host_manager, AGENTS_SCANNED_FIRST_SCAN,
body["operation"], body["package"])
duplicated_vulnerabilities = get_duplicated_vulnerabilities(vulnerabilities)

result = compare_expected_found_vulnerabilities(vulnerabilities, expected_vulnerabilities)
vulnerabilities_not_found = result["vulnerabilities_not_found"]
vulnerabilities_unexpected = result["vulnerabilities_unexpected"]

test_result.validate_check('no_duplicated_vulnerabilities',
[Evidence('duplicated_vulnerabilities', duplicated_vulnerabilities),
Evidence('vulnerabilities', vulnerabilities)
])

logging.critical("Validating found vulnerabilities")
test_result.validate_check(
"expected_vulnerabilities_found_in_index",
[
Evidence("missing_vulnerabilities", vulnerabilities_not_found),
Evidence("vulnerabilities_found_in_index", vulnerabilities),
Evidence("expected_vulnerabilities", expected_vulnerabilities),
],
)

logging.critical("Validating unexpected vulnerabilities")
test_result.validate_check(
"no_unexpected_vulnerabilities_found_in_index",
[
Evidence("unexpected_vulnerabilities", vulnerabilities_unexpected),
Evidence("vulnerabilities_found_in_index", vulnerabilities),
Evidence("expected_vulnerabilities", expected_vulnerabilities),
],
)

alerts = get_vulnerability_alerts(host_manager, AGENTS_SCANNED_FIRST_SCAN, package_data, test_timestamp)
expected_alerts = get_expected_alerts(
host_manager, AGENTS_SCANNED_FIRST_SCAN, body["operation"], body["package"]
)

result_alert = compare_expected_found_vulnerabilities_alerts(
alerts, expected_alerts
)

logging.critical("Validating found alerts")
test_result.validate_check(
"expected_vulnerability_affected_alert",
[
Evidence(
"missing_affected_alerts",
result_alert["vulnerabilities_affected_not_found"],
),
Evidence("alerts_found_in_index", alerts),
Evidence("expected_alerts", expected_alerts),
],
)

logging.critical("Validating unexpected alerts")
test_result.validate_check(
"expected_vulnerability_mitigated_alert",
[
Evidence(
"missing_mitigated_alerts",
result_alert["vulnerabilities_mitigated_not_found"],
),
Evidence("alerts_found_in_index", alerts),
Evidence("expected_alerts", expected_alerts),
],
)

errors_environment = check_errors_in_environment(
host_manager,
expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS,
greater_than_timestamp=test_timestamp,
)

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

> assert test_result.get_test_result(), test_result.report()
E AssertionError:
E Test test_vulnerability_detector_scans_cases[upgrade_package_maintain_vulnerability] failed
E
E Check no_errors succeeded
E Check operation_successfull_for_all_agents succeeded
E Check expected_vulnerabilities_found_in_index succeeded
E Check no_unexpected_vulnerabilities_found_in_index succeeded
E Check expected_vulnerability_affected_alert failed. Evidences (['missing_affected_alerts']) can be found in the report.
E Check expected_vulnerability_mitigated_alert failed. Evidences (['missing_mitigated_alerts']) can be found in the report.
E Check setup_operation_results failed. Evidences (['setup_failed_agents']) can be found in the report.
E Check no_duplicated_vulnerabilities failed. Evidences (['duplicated_vulnerabilities']) can be found in the report.
E -----
E
E assert False
E + where False = <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c296bf70>>()
E + where <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c296bf70>> = <wazuh_testing.end_to_end.TestResult object at 0x7dd0c296bf70>.get_test_result

end_to_end/test_vulnerability_detector/test_vulnerability_detector.py:993: AssertionError
-------------------------------Captured log setup-------------------------------
CRITICAL root:check_validators.py:123 Vulnerabilities affected not found: {'agent1': [Vulnerability(cve='CVE-2017-16014', package_name='http-proxy', package_version='0.5.9', architecture='')]} CRITICAL root:check_validators.py:124 Vulnerabilities mitigated not found: {}
-------------------------------Captured log call--------------------------------
ERROR root:__init__.py:237 Marked check setup_operation_results result to False with evidences ['setup_failed_agents'] CRITICAL root:test_vulnerability_detector.py:903 Remote operation results: {'agent1': True} ERROR root:__init__.py:237 Marked check operation_successfull_for_all_agents result to True with evidences ['operation_results'] ERROR root:__init__.py:237 Marked check no_duplicated_vulnerabilities result to False with evidences ['duplicated_vulnerabilities', 'vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:930 Validating found vulnerabilities ERROR root:__init__.py:237 Marked check expected_vulnerabilities_found_in_index result to True with evidences ['missing_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:940 Validating unexpected vulnerabilities ERROR root:__init__.py:237 Marked check no_unexpected_vulnerabilities_found_in_index result to True with evidences ['unexpected_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:check_validators.py:123 Vulnerabilities affected not found: {'agent1': [Vulnerability(cve='CVE-2017-16014', package_name='http-proxy', package_version='0.5.10', architecture='')]} CRITICAL root:check_validators.py:124 Vulnerabilities mitigated not found: {'agent1': [Vulnerability(cve='CVE-2017-16014', package_name='http-proxy', package_version='0.5.9', architecture='')]} CRITICAL root:test_vulnerability_detector.py:959 Validating found alerts CRITICAL root:check_validators.py:145 agent1 is not empty: [Vulnerability(cve='CVE-2017-16014', package_name='http-proxy', package_version='0.5.10', architecture='')] ERROR root:__init__.py:237 Marked check expected_vulnerability_affected_alert result to False with evidences ['missing_affected_alerts', 'alerts_found_in_index', 'expected_alerts'] CRITICAL root:test_vulnerability_detector.py:972 Validating unexpected alerts CRITICAL root:check_validators.py:145 agent1 is not empty: [Vulnerability(cve='CVE-2017-16014', package_name='http-proxy', package_version='0.5.9', architecture='')] ERROR root:__init__.py:237 Marked check expected_vulnerability_mitigated_alert result to False with evidences ['missing_mitigated_alerts', 'alerts_found_in_index', 'expected_alerts'] ERROR root:__init__.py:237 Marked check no_errors result to True with evidences ['error_level_messages']
-----------------------------Captured log teardown------------------------------
ERROR root:conftest.py:152 Truncate managers and agents logs
Failed test_vulnerability_detector/test_vulnerability_detector.py::TestScanSyscollectorCases::test_vulnerability_detector_scans_cases[upgrade_package_add_vulnerability] 281.73

Test function details

Extended Summary

Parameters

self = <test_vulnerability_detector.TestScanSyscollectorCases object at 0x7dd0c4216560>
request = <FixtureRequest for <Function test_vulnerability_detector_scans_cases[upgrade_package_add_vulnerability]>>, preconditions = None
body = {'operation': 'update_package', 'package': {'from': {'centos': {'amd64': 'grafana-8.5.6-1', 'arm64v8': 'grafana-8.5.6-...tion-5.0.0'}, 'ubuntu': {'amd64': 'grafana-9.1.1', 'arm64v8': 'grafana-9.1.1'}, 'windows': {'amd64': 'node-v18.0.0'}}}}
teardown = None, setup = [], host_manager = <wazuh_testing.tools.system.HostManager object at 0x7dd0c425f850>, record_property = <function record_property.<locals>.append_property at 0x7dd0c37136d0>
clean_environment_logs = None, delete_states_vulnerability_index = None, clean_environment_logs_function = None

@pytest.mark.parametrize("preconditions, body, teardown", complete_list, ids=list_ids)
def test_vulnerability_detector_scans_cases(self, request, preconditions, body, teardown, setup, host_manager,
record_property, clean_environment_logs,
delete_states_vulnerability_index,
clean_environment_logs_function):
# Is mandatory to launch this test along with the first scan test'
global AGENTS_SCANNED_FIRST_SCAN
if len(AGENTS_SCANNED_FIRST_SCAN) == 0:
pytest.skip("No agent was scanned in the first scan. Skipping test.")

target_to_ignore = list(
set(host_manager.get_group_hosts("agent")) - set(AGENTS_SCANNED_FIRST_SCAN)
)

utc_now_timestamp = datetime.datetime.now(datetime.timezone.utc)
test_timestamp = utc_now_timestamp.strftime("%Y-%m-%dT%H:%M:%S")

test_result = TestResult(request.node.name)
test_result.add_check(self.no_errors_check)
test_result.add_check(self.operation_successfull_for_all_agents_check)
test_result.add_check(self.expected_vulnerabilities_found_in_index_check)
test_result.add_check(self.no_unexpected_vulnerabilities_found_in_index_check)
test_result.add_check(self.expected_vulnerability_affected_alert_check)
test_result.add_check(self.expected_vulnerability_mitigated_alert_check)
test_result.add_check(self.setup_successfull_for_all_agents_check)
test_result.add_check(self.no_duplicated_vulnerabilities_check)

record_property("test_result", test_result)

agents_failed_setup = setup
test_result.validate_check("setup_operation_results", [Evidence("setup_failed_agents", agents_failed_setup)])

# Install Vulnerable package
operations_result = launch_parallel_operations(
body, host_manager, target_to_ignore
)

logging.critical(f"Remote operation results: {operations_result}")
test_result.validate_check(
"operation_successfull_for_all_agents",
[Evidence("operation_results", operations_result)],
)
# Wait for syscollector and VD scan
time.sleep(VD_E2E_TIMEOUT_SYSCOLLECTOR_SCAN + PACKAGE_VULNERABILITY_SCAN_TIME)

if "to" in body["package"]:
package_data = [body["package"]["to"], body["package"]["from"]]
else:
package_data = [body["package"]]

vulnerabilities = get_vulnerabilities_index(host_manager, AGENTS_SCANNED_FIRST_SCAN, package_data)
expected_vulnerabilities = get_expected_index(host_manager, AGENTS_SCANNED_FIRST_SCAN,
body["operation"], body["package"])
duplicated_vulnerabilities = get_duplicated_vulnerabilities(vulnerabilities)

result = compare_expected_found_vulnerabilities(vulnerabilities, expected_vulnerabilities)
vulnerabilities_not_found = result["vulnerabilities_not_found"]
vulnerabilities_unexpected = result["vulnerabilities_unexpected"]

test_result.validate_check('no_duplicated_vulnerabilities',
[Evidence('duplicated_vulnerabilities', duplicated_vulnerabilities),
Evidence('vulnerabilities', vulnerabilities)
])

logging.critical("Validating found vulnerabilities")
test_result.validate_check(
"expected_vulnerabilities_found_in_index",
[
Evidence("missing_vulnerabilities", vulnerabilities_not_found),
Evidence("vulnerabilities_found_in_index", vulnerabilities),
Evidence("expected_vulnerabilities", expected_vulnerabilities),
],
)

logging.critical("Validating unexpected vulnerabilities")
test_result.validate_check(
"no_unexpected_vulnerabilities_found_in_index",
[
Evidence("unexpected_vulnerabilities", vulnerabilities_unexpected),
Evidence("vulnerabilities_found_in_index", vulnerabilities),
Evidence("expected_vulnerabilities", expected_vulnerabilities),
],
)

alerts = get_vulnerability_alerts(host_manager, AGENTS_SCANNED_FIRST_SCAN, package_data, test_timestamp)
expected_alerts = get_expected_alerts(
host_manager, AGENTS_SCANNED_FIRST_SCAN, body["operation"], body["package"]
)

result_alert = compare_expected_found_vulnerabilities_alerts(
alerts, expected_alerts
)

logging.critical("Validating found alerts")
test_result.validate_check(
"expected_vulnerability_affected_alert",
[
Evidence(
"missing_affected_alerts",
result_alert["vulnerabilities_affected_not_found"],
),
Evidence("alerts_found_in_index", alerts),
Evidence("expected_alerts", expected_alerts),
],
)

logging.critical("Validating unexpected alerts")
test_result.validate_check(
"expected_vulnerability_mitigated_alert",
[
Evidence(
"missing_mitigated_alerts",
result_alert["vulnerabilities_mitigated_not_found"],
),
Evidence("alerts_found_in_index", alerts),
Evidence("expected_alerts", expected_alerts),
],
)

errors_environment = check_errors_in_environment(
host_manager,
expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS,
greater_than_timestamp=test_timestamp,
)

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

> assert test_result.get_test_result(), test_result.report()
E AssertionError:
E Test test_vulnerability_detector_scans_cases[upgrade_package_add_vulnerability] failed
E
E Check no_errors succeeded
E Check operation_successfull_for_all_agents succeeded
E Check expected_vulnerabilities_found_in_index succeeded
E Check no_unexpected_vulnerabilities_found_in_index succeeded
E Check expected_vulnerability_affected_alert failed. Evidences (['missing_affected_alerts']) can be found in the report.
E Check expected_vulnerability_mitigated_alert failed. Evidences (['missing_mitigated_alerts']) can be found in the report.
E Check setup_operation_results succeeded
E Check no_duplicated_vulnerabilities failed. Evidences (['duplicated_vulnerabilities']) can be found in the report.
E -----
E
E assert False
E + where False = <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c29fc640>>()
E + where <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c29fc640>> = <wazuh_testing.end_to_end.TestResult object at 0x7dd0c29fc640>.get_test_result

end_to_end/test_vulnerability_detector/test_vulnerability_detector.py:993: AssertionError
-------------------------------Captured log call--------------------------------
ERROR root:__init__.py:237 Marked check setup_operation_results result to True with evidences ['setup_failed_agents'] CRITICAL root:test_vulnerability_detector.py:903 Remote operation results: {'agent1': True} ERROR root:__init__.py:237 Marked check operation_successfull_for_all_agents result to True with evidences ['operation_results'] ERROR root:__init__.py:237 Marked check no_duplicated_vulnerabilities result to False with evidences ['duplicated_vulnerabilities', 'vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:930 Validating found vulnerabilities ERROR root:__init__.py:237 Marked check expected_vulnerabilities_found_in_index result to True with evidences ['missing_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:940 Validating unexpected vulnerabilities ERROR root:__init__.py:237 Marked check no_unexpected_vulnerabilities_found_in_index result to True with evidences ['unexpected_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:check_validators.py:123 Vulnerabilities affected not found: {'agent1': [Vulnerability(cve='CVE-2021-21315', package_name='systeminformation', package_version='5.0.0', architecture=''), Vulnerability(cve='CVE-2021-21388', package_name='systeminformation', package_version='5.0.0', architecture=''), Vulnerability(cve='CVE-2023-42810', package_name='systeminformation', package_version='5.0.0', architecture='')]} CRITICAL root:check_validators.py:124 Vulnerabilities mitigated not found: {'agent1': [Vulnerability(cve='CVE-2021-21315', package_name='systeminformation', package_version='4.34.23', architecture=''), Vulnerability(cve='CVE-2021-21388', package_name='systeminformation', package_version='4.34.23', architecture='')]} CRITICAL root:test_vulnerability_detector.py:959 Validating found alerts CRITICAL root:check_validators.py:145 agent1 is not empty: [Vulnerability(cve='CVE-2021-21315', package_name='systeminformation', package_version='5.0.0', architecture=''), Vulnerability(cve='CVE-2021-21388', package_name='systeminformation', package_version='5.0.0', architecture=''), Vulnerability(cve='CVE-2023-42810', package_name='systeminformation', package_version='5.0.0', architecture='')] ERROR root:__init__.py:237 Marked check expected_vulnerability_affected_alert result to False with evidences ['missing_affected_alerts', 'alerts_found_in_index', 'expected_alerts'] CRITICAL root:test_vulnerability_detector.py:972 Validating unexpected alerts CRITICAL root:check_validators.py:145 agent1 is not empty: [Vulnerability(cve='CVE-2021-21315', package_name='systeminformation', package_version='4.34.23', architecture=''), Vulnerability(cve='CVE-2021-21388', package_name='systeminformation', package_version='4.34.23', architecture='')] ERROR root:__init__.py:237 Marked check expected_vulnerability_mitigated_alert result to False with evidences ['missing_mitigated_alerts', 'alerts_found_in_index', 'expected_alerts'] ERROR root:__init__.py:237 Marked check no_errors result to True with evidences ['error_level_messages']
-----------------------------Captured log teardown------------------------------
ERROR root:conftest.py:152 Truncate managers and agents logs
Failed test_vulnerability_detector/test_vulnerability_detector.py::TestScanSyscollectorCases::test_vulnerability_detector_scans_cases[upgrade_package_maintain_add_vulnerability] 281.19

Test function details

Extended Summary

Parameters

self = <test_vulnerability_detector.TestScanSyscollectorCases object at 0x7dd0c4216950>
request = <FixtureRequest for <Function test_vulnerability_detector_scans_cases[upgrade_package_maintain_add_vulnerability]>>, preconditions = None
body = {'operation': 'update_package', 'package': {'from': {'centos': {'amd64': 'grafana-9.1.1-1', 'arm64v8': 'grafana-9.1.1-...tion-5.0.0'}, 'ubuntu': {'amd64': 'grafana-9.2.0', 'arm64v8': 'grafana-9.2.0'}, 'windows': {'amd64': 'node-v18.1.0'}}}}
teardown = None, setup = [], host_manager = <wazuh_testing.tools.system.HostManager object at 0x7dd0c425f850>, record_property = <function record_property.<locals>.append_property at 0x7dd0c2a28dc0>
clean_environment_logs = None, delete_states_vulnerability_index = None, clean_environment_logs_function = None

@pytest.mark.parametrize("preconditions, body, teardown", complete_list, ids=list_ids)
def test_vulnerability_detector_scans_cases(self, request, preconditions, body, teardown, setup, host_manager,
record_property, clean_environment_logs,
delete_states_vulnerability_index,
clean_environment_logs_function):
# Is mandatory to launch this test along with the first scan test'
global AGENTS_SCANNED_FIRST_SCAN
if len(AGENTS_SCANNED_FIRST_SCAN) == 0:
pytest.skip("No agent was scanned in the first scan. Skipping test.")

target_to_ignore = list(
set(host_manager.get_group_hosts("agent")) - set(AGENTS_SCANNED_FIRST_SCAN)
)

utc_now_timestamp = datetime.datetime.now(datetime.timezone.utc)
test_timestamp = utc_now_timestamp.strftime("%Y-%m-%dT%H:%M:%S")

test_result = TestResult(request.node.name)
test_result.add_check(self.no_errors_check)
test_result.add_check(self.operation_successfull_for_all_agents_check)
test_result.add_check(self.expected_vulnerabilities_found_in_index_check)
test_result.add_check(self.no_unexpected_vulnerabilities_found_in_index_check)
test_result.add_check(self.expected_vulnerability_affected_alert_check)
test_result.add_check(self.expected_vulnerability_mitigated_alert_check)
test_result.add_check(self.setup_successfull_for_all_agents_check)
test_result.add_check(self.no_duplicated_vulnerabilities_check)

record_property("test_result", test_result)

agents_failed_setup = setup
test_result.validate_check("setup_operation_results", [Evidence("setup_failed_agents", agents_failed_setup)])

# Install Vulnerable package
operations_result = launch_parallel_operations(
body, host_manager, target_to_ignore
)

logging.critical(f"Remote operation results: {operations_result}")
test_result.validate_check(
"operation_successfull_for_all_agents",
[Evidence("operation_results", operations_result)],
)
# Wait for syscollector and VD scan
time.sleep(VD_E2E_TIMEOUT_SYSCOLLECTOR_SCAN + PACKAGE_VULNERABILITY_SCAN_TIME)

if "to" in body["package"]:
package_data = [body["package"]["to"], body["package"]["from"]]
else:
package_data = [body["package"]]

vulnerabilities = get_vulnerabilities_index(host_manager, AGENTS_SCANNED_FIRST_SCAN, package_data)
expected_vulnerabilities = get_expected_index(host_manager, AGENTS_SCANNED_FIRST_SCAN,
body["operation"], body["package"])
duplicated_vulnerabilities = get_duplicated_vulnerabilities(vulnerabilities)

result = compare_expected_found_vulnerabilities(vulnerabilities, expected_vulnerabilities)
vulnerabilities_not_found = result["vulnerabilities_not_found"]
vulnerabilities_unexpected = result["vulnerabilities_unexpected"]

test_result.validate_check('no_duplicated_vulnerabilities',
[Evidence('duplicated_vulnerabilities', duplicated_vulnerabilities),
Evidence('vulnerabilities', vulnerabilities)
])

logging.critical("Validating found vulnerabilities")
test_result.validate_check(
"expected_vulnerabilities_found_in_index",
[
Evidence("missing_vulnerabilities", vulnerabilities_not_found),
Evidence("vulnerabilities_found_in_index", vulnerabilities),
Evidence("expected_vulnerabilities", expected_vulnerabilities),
],
)

logging.critical("Validating unexpected vulnerabilities")
test_result.validate_check(
"no_unexpected_vulnerabilities_found_in_index",
[
Evidence("unexpected_vulnerabilities", vulnerabilities_unexpected),
Evidence("vulnerabilities_found_in_index", vulnerabilities),
Evidence("expected_vulnerabilities", expected_vulnerabilities),
],
)

alerts = get_vulnerability_alerts(host_manager, AGENTS_SCANNED_FIRST_SCAN, package_data, test_timestamp)
expected_alerts = get_expected_alerts(
host_manager, AGENTS_SCANNED_FIRST_SCAN, body["operation"], body["package"]
)

result_alert = compare_expected_found_vulnerabilities_alerts(
alerts, expected_alerts
)

logging.critical("Validating found alerts")
test_result.validate_check(
"expected_vulnerability_affected_alert",
[
Evidence(
"missing_affected_alerts",
result_alert["vulnerabilities_affected_not_found"],
),
Evidence("alerts_found_in_index", alerts),
Evidence("expected_alerts", expected_alerts),
],
)

logging.critical("Validating unexpected alerts")
test_result.validate_check(
"expected_vulnerability_mitigated_alert",
[
Evidence(
"missing_mitigated_alerts",
result_alert["vulnerabilities_mitigated_not_found"],
),
Evidence("alerts_found_in_index", alerts),
Evidence("expected_alerts", expected_alerts),
],
)

errors_environment = check_errors_in_environment(
host_manager,
expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS,
greater_than_timestamp=test_timestamp,
)

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

> assert test_result.get_test_result(), test_result.report()
E AssertionError:
E Test test_vulnerability_detector_scans_cases[upgrade_package_maintain_add_vulnerability] failed
E
E Check no_errors succeeded
E Check operation_successfull_for_all_agents succeeded
E Check expected_vulnerabilities_found_in_index succeeded
E Check no_unexpected_vulnerabilities_found_in_index succeeded
E Check expected_vulnerability_affected_alert failed. Evidences (['missing_affected_alerts']) can be found in the report.
E Check expected_vulnerability_mitigated_alert failed. Evidences (['missing_mitigated_alerts']) can be found in the report.
E Check setup_operation_results succeeded
E Check no_duplicated_vulnerabilities failed. Evidences (['duplicated_vulnerabilities']) can be found in the report.
E -----
E
E assert False
E + where False = <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c2a0ab00>>()
E + where <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c2a0ab00>> = <wazuh_testing.end_to_end.TestResult object at 0x7dd0c2a0ab00>.get_test_result

end_to_end/test_vulnerability_detector/test_vulnerability_detector.py:993: AssertionError
-------------------------------Captured log call--------------------------------
ERROR root:__init__.py:237 Marked check setup_operation_results result to True with evidences ['setup_failed_agents'] CRITICAL root:test_vulnerability_detector.py:903 Remote operation results: {'agent1': True} ERROR root:__init__.py:237 Marked check operation_successfull_for_all_agents result to True with evidences ['operation_results'] ERROR root:__init__.py:237 Marked check no_duplicated_vulnerabilities result to False with evidences ['duplicated_vulnerabilities', 'vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:930 Validating found vulnerabilities ERROR root:__init__.py:237 Marked check expected_vulnerabilities_found_in_index result to True with evidences ['missing_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:940 Validating unexpected vulnerabilities ERROR root:__init__.py:237 Marked check no_unexpected_vulnerabilities_found_in_index result to True with evidences ['unexpected_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:check_validators.py:123 Vulnerabilities affected not found: {'agent1': [Vulnerability(cve='CVE-2021-21315', package_name='systeminformation', package_version='5.0.0', architecture=''), Vulnerability(cve='CVE-2021-21388', package_name='systeminformation', package_version='5.0.0', architecture=''), Vulnerability(cve='CVE-2023-42810', package_name='systeminformation', package_version='5.0.0', architecture='')]} CRITICAL root:check_validators.py:124 Vulnerabilities mitigated not found: {'agent1': [Vulnerability(cve='CVE-2021-21315', package_name='systeminformation', package_version='4.34.23', architecture=''), Vulnerability(cve='CVE-2021-21388', package_name='systeminformation', package_version='4.34.23', architecture='')]} CRITICAL root:test_vulnerability_detector.py:959 Validating found alerts CRITICAL root:check_validators.py:145 agent1 is not empty: [Vulnerability(cve='CVE-2021-21315', package_name='systeminformation', package_version='5.0.0', architecture=''), Vulnerability(cve='CVE-2021-21388', package_name='systeminformation', package_version='5.0.0', architecture=''), Vulnerability(cve='CVE-2023-42810', package_name='systeminformation', package_version='5.0.0', architecture='')] ERROR root:__init__.py:237 Marked check expected_vulnerability_affected_alert result to False with evidences ['missing_affected_alerts', 'alerts_found_in_index', 'expected_alerts'] CRITICAL root:test_vulnerability_detector.py:972 Validating unexpected alerts CRITICAL root:check_validators.py:145 agent1 is not empty: [Vulnerability(cve='CVE-2021-21315', package_name='systeminformation', package_version='4.34.23', architecture=''), Vulnerability(cve='CVE-2021-21388', package_name='systeminformation', package_version='4.34.23', architecture='')] ERROR root:__init__.py:237 Marked check expected_vulnerability_mitigated_alert result to False with evidences ['missing_mitigated_alerts', 'alerts_found_in_index', 'expected_alerts'] ERROR root:__init__.py:237 Marked check no_errors result to True with evidences ['error_level_messages']
-----------------------------Captured log teardown------------------------------
ERROR root:conftest.py:152 Truncate managers and agents logs
Failed test_vulnerability_detector/test_vulnerability_detector.py::TestScanSyscollectorCases::test_vulnerability_detector_scans_cases[upgrade_package_remove_vulnerability] 282.18

Test function details

Extended Summary

Parameters

self = <test_vulnerability_detector.TestScanSyscollectorCases object at 0x7dd0c425ee90>
request = <FixtureRequest for <Function test_vulnerability_detector_scans_cases[upgrade_package_remove_vulnerability]>>, preconditions = None
body = {'operation': 'update_package', 'package': {'from': {'centos': {'amd64': 'grafana-9.2.0-1', 'arm64v8': 'grafana-9.2.0-...y-0.7.0'}, 'ubuntu': {'amd64': 'grafana-9.4.17', 'arm64v8': 'grafana-9.4.17'}, 'windows': {'amd64': 'node-v18.20.0'}}}}
teardown = None, setup = [], host_manager = <wazuh_testing.tools.system.HostManager object at 0x7dd0c425f850>, record_property = <function record_property.<locals>.append_property at 0x7dd0c2a2bac0>
clean_environment_logs = None, delete_states_vulnerability_index = None, clean_environment_logs_function = None

@pytest.mark.parametrize("preconditions, body, teardown", complete_list, ids=list_ids)
def test_vulnerability_detector_scans_cases(self, request, preconditions, body, teardown, setup, host_manager,
record_property, clean_environment_logs,
delete_states_vulnerability_index,
clean_environment_logs_function):
# Is mandatory to launch this test along with the first scan test'
global AGENTS_SCANNED_FIRST_SCAN
if len(AGENTS_SCANNED_FIRST_SCAN) == 0:
pytest.skip("No agent was scanned in the first scan. Skipping test.")

target_to_ignore = list(
set(host_manager.get_group_hosts("agent")) - set(AGENTS_SCANNED_FIRST_SCAN)
)

utc_now_timestamp = datetime.datetime.now(datetime.timezone.utc)
test_timestamp = utc_now_timestamp.strftime("%Y-%m-%dT%H:%M:%S")

test_result = TestResult(request.node.name)
test_result.add_check(self.no_errors_check)
test_result.add_check(self.operation_successfull_for_all_agents_check)
test_result.add_check(self.expected_vulnerabilities_found_in_index_check)
test_result.add_check(self.no_unexpected_vulnerabilities_found_in_index_check)
test_result.add_check(self.expected_vulnerability_affected_alert_check)
test_result.add_check(self.expected_vulnerability_mitigated_alert_check)
test_result.add_check(self.setup_successfull_for_all_agents_check)
test_result.add_check(self.no_duplicated_vulnerabilities_check)

record_property("test_result", test_result)

agents_failed_setup = setup
test_result.validate_check("setup_operation_results", [Evidence("setup_failed_agents", agents_failed_setup)])

# Install Vulnerable package
operations_result = launch_parallel_operations(
body, host_manager, target_to_ignore
)

logging.critical(f"Remote operation results: {operations_result}")
test_result.validate_check(
"operation_successfull_for_all_agents",
[Evidence("operation_results", operations_result)],
)
# Wait for syscollector and VD scan
time.sleep(VD_E2E_TIMEOUT_SYSCOLLECTOR_SCAN + PACKAGE_VULNERABILITY_SCAN_TIME)

if "to" in body["package"]:
package_data = [body["package"]["to"], body["package"]["from"]]
else:
package_data = [body["package"]]

vulnerabilities = get_vulnerabilities_index(host_manager, AGENTS_SCANNED_FIRST_SCAN, package_data)
expected_vulnerabilities = get_expected_index(host_manager, AGENTS_SCANNED_FIRST_SCAN,
body["operation"], body["package"])
duplicated_vulnerabilities = get_duplicated_vulnerabilities(vulnerabilities)

result = compare_expected_found_vulnerabilities(vulnerabilities, expected_vulnerabilities)
vulnerabilities_not_found = result["vulnerabilities_not_found"]
vulnerabilities_unexpected = result["vulnerabilities_unexpected"]

test_result.validate_check('no_duplicated_vulnerabilities',
[Evidence('duplicated_vulnerabilities', duplicated_vulnerabilities),
Evidence('vulnerabilities', vulnerabilities)
])

logging.critical("Validating found vulnerabilities")
test_result.validate_check(
"expected_vulnerabilities_found_in_index",
[
Evidence("missing_vulnerabilities", vulnerabilities_not_found),
Evidence("vulnerabilities_found_in_index", vulnerabilities),
Evidence("expected_vulnerabilities", expected_vulnerabilities),
],
)

logging.critical("Validating unexpected vulnerabilities")
test_result.validate_check(
"no_unexpected_vulnerabilities_found_in_index",
[
Evidence("unexpected_vulnerabilities", vulnerabilities_unexpected),
Evidence("vulnerabilities_found_in_index", vulnerabilities),
Evidence("expected_vulnerabilities", expected_vulnerabilities),
],
)

alerts = get_vulnerability_alerts(host_manager, AGENTS_SCANNED_FIRST_SCAN, package_data, test_timestamp)
expected_alerts = get_expected_alerts(
host_manager, AGENTS_SCANNED_FIRST_SCAN, body["operation"], body["package"]
)

result_alert = compare_expected_found_vulnerabilities_alerts(
alerts, expected_alerts
)

logging.critical("Validating found alerts")
test_result.validate_check(
"expected_vulnerability_affected_alert",
[
Evidence(
"missing_affected_alerts",
result_alert["vulnerabilities_affected_not_found"],
),
Evidence("alerts_found_in_index", alerts),
Evidence("expected_alerts", expected_alerts),
],
)

logging.critical("Validating unexpected alerts")
test_result.validate_check(
"expected_vulnerability_mitigated_alert",
[
Evidence(
"missing_mitigated_alerts",
result_alert["vulnerabilities_mitigated_not_found"],
),
Evidence("alerts_found_in_index", alerts),
Evidence("expected_alerts", expected_alerts),
],
)

errors_environment = check_errors_in_environment(
host_manager,
expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS,
greater_than_timestamp=test_timestamp,
)

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

> assert test_result.get_test_result(), test_result.report()
E AssertionError:
E Test test_vulnerability_detector_scans_cases[upgrade_package_remove_vulnerability] failed
E
E Check no_errors succeeded
E Check operation_successfull_for_all_agents succeeded
E Check expected_vulnerabilities_found_in_index succeeded
E Check no_unexpected_vulnerabilities_found_in_index succeeded
E Check expected_vulnerability_affected_alert succeeded
E Check expected_vulnerability_mitigated_alert failed. Evidences (['missing_mitigated_alerts']) can be found in the report.
E Check setup_operation_results succeeded
E Check no_duplicated_vulnerabilities succeeded
E -----
E
E assert False
E + where False = <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c296afb0>>()
E + where <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c296afb0>> = <wazuh_testing.end_to_end.TestResult object at 0x7dd0c296afb0>.get_test_result

end_to_end/test_vulnerability_detector/test_vulnerability_detector.py:993: AssertionError
-------------------------------Captured log call--------------------------------
ERROR root:__init__.py:237 Marked check setup_operation_results result to True with evidences ['setup_failed_agents'] CRITICAL root:test_vulnerability_detector.py:903 Remote operation results: {'agent1': True} ERROR root:__init__.py:237 Marked check operation_successfull_for_all_agents result to True with evidences ['operation_results'] ERROR root:__init__.py:237 Marked check no_duplicated_vulnerabilities result to True with evidences ['duplicated_vulnerabilities', 'vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:930 Validating found vulnerabilities ERROR root:__init__.py:237 Marked check expected_vulnerabilities_found_in_index result to True with evidences ['missing_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:940 Validating unexpected vulnerabilities ERROR root:__init__.py:237 Marked check no_unexpected_vulnerabilities_found_in_index result to True with evidences ['unexpected_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:check_validators.py:123 Vulnerabilities affected not found: {} CRITICAL root:check_validators.py:124 Vulnerabilities mitigated not found: {'agent1': [Vulnerability(cve='CVE-2017-16014', package_name='http-proxy', package_version='0.5.10', architecture='')]} CRITICAL root:test_vulnerability_detector.py:959 Validating found alerts ERROR root:__init__.py:237 Marked check expected_vulnerability_affected_alert result to True with evidences ['missing_affected_alerts', 'alerts_found_in_index', 'expected_alerts'] CRITICAL root:test_vulnerability_detector.py:972 Validating unexpected alerts CRITICAL root:check_validators.py:145 agent1 is not empty: [Vulnerability(cve='CVE-2017-16014', package_name='http-proxy', package_version='0.5.10', architecture='')] ERROR root:__init__.py:237 Marked check expected_vulnerability_mitigated_alert result to False with evidences ['missing_mitigated_alerts', 'alerts_found_in_index', 'expected_alerts'] ERROR root:__init__.py:237 Marked check no_errors result to True with evidences ['error_level_messages']
-----------------------------Captured log teardown------------------------------
ERROR root:conftest.py:152 Truncate managers and agents logs
Failed test_vulnerability_detector/test_vulnerability_detector.py::TestScanSyscollectorCases::test_vulnerability_detector_scans_cases[upgrade_package_nonvulnerable_to_vulnerable] 485.72

Test function details

Extended Summary

Parameters

self = <test_vulnerability_detector.TestScanSyscollectorCases object at 0x7dd0c425fb80>
request = <FixtureRequest for <Function test_vulnerability_detector_scans_cases[upgrade_package_nonvulnerable_to_vulnerable]>>
preconditions = {'operation': 'install_package', 'package': {'macos': {'amd64': 'luxon-2.5.2', 'arm64v8': 'luxon-2.5.2'}}}
body = {'operation': 'update_package', 'package': {'from': {'centos': {'amd64': 'grafana-9.5.13-1', 'arm64v8': 'grafana-9.5.1...on-3.0.0'}, 'ubuntu': {'amd64': 'grafana-10.0.0', 'arm64v8': 'grafana-10.0.0'}, 'windows': {'amd64': 'node-v20.5.1'}}}}
teardown = {'operation': 'remove_package', 'package': {'centos': {'amd64': 'grafana-10.0.0-1', 'arm64v8': 'grafana-10.0.0-1'}, 'm...xon-3.0.0'}, 'ubuntu': {'amd64': 'grafana-10.0.0', 'arm64v8': 'grafana-10.0.0'}, 'windows': {'amd64': 'node-v20.5.1'}}}
setup = [], host_manager = <wazuh_testing.tools.system.HostManager object at 0x7dd0c425f850>, record_property = <function record_property.<locals>.append_property at 0x7dd0c3713f40>
clean_environment_logs = None, delete_states_vulnerability_index = None, clean_environment_logs_function = None

@pytest.mark.parametrize("preconditions, body, teardown", complete_list, ids=list_ids)
def test_vulnerability_detector_scans_cases(self, request, preconditions, body, teardown, setup, host_manager,
record_property, clean_environment_logs,
delete_states_vulnerability_index,
clean_environment_logs_function):
# Is mandatory to launch this test along with the first scan test'
global AGENTS_SCANNED_FIRST_SCAN
if len(AGENTS_SCANNED_FIRST_SCAN) == 0:
pytest.skip("No agent was scanned in the first scan. Skipping test.")

target_to_ignore = list(
set(host_manager.get_group_hosts("agent")) - set(AGENTS_SCANNED_FIRST_SCAN)
)

utc_now_timestamp = datetime.datetime.now(datetime.timezone.utc)
test_timestamp = utc_now_timestamp.strftime("%Y-%m-%dT%H:%M:%S")

test_result = TestResult(request.node.name)
test_result.add_check(self.no_errors_check)
test_result.add_check(self.operation_successfull_for_all_agents_check)
test_result.add_check(self.expected_vulnerabilities_found_in_index_check)
test_result.add_check(self.no_unexpected_vulnerabilities_found_in_index_check)
test_result.add_check(self.expected_vulnerability_affected_alert_check)
test_result.add_check(self.expected_vulnerability_mitigated_alert_check)
test_result.add_check(self.setup_successfull_for_all_agents_check)
test_result.add_check(self.no_duplicated_vulnerabilities_check)

record_property("test_result", test_result)

agents_failed_setup = setup
test_result.validate_check("setup_operation_results", [Evidence("setup_failed_agents", agents_failed_setup)])

# Install Vulnerable package
operations_result = launch_parallel_operations(
body, host_manager, target_to_ignore
)

logging.critical(f"Remote operation results: {operations_result}")
test_result.validate_check(
"operation_successfull_for_all_agents",
[Evidence("operation_results", operations_result)],
)
# Wait for syscollector and VD scan
time.sleep(VD_E2E_TIMEOUT_SYSCOLLECTOR_SCAN + PACKAGE_VULNERABILITY_SCAN_TIME)

if "to" in body["package"]:
package_data = [body["package"]["to"], body["package"]["from"]]
else:
package_data = [body["package"]]

vulnerabilities = get_vulnerabilities_index(host_manager, AGENTS_SCANNED_FIRST_SCAN, package_data)
expected_vulnerabilities = get_expected_index(host_manager, AGENTS_SCANNED_FIRST_SCAN,
body["operation"], body["package"])
duplicated_vulnerabilities = get_duplicated_vulnerabilities(vulnerabilities)

result = compare_expected_found_vulnerabilities(vulnerabilities, expected_vulnerabilities)
vulnerabilities_not_found = result["vulnerabilities_not_found"]
vulnerabilities_unexpected = result["vulnerabilities_unexpected"]

test_result.validate_check('no_duplicated_vulnerabilities',
[Evidence('duplicated_vulnerabilities', duplicated_vulnerabilities),
Evidence('vulnerabilities', vulnerabilities)
])

logging.critical("Validating found vulnerabilities")
test_result.validate_check(
"expected_vulnerabilities_found_in_index",
[
Evidence("missing_vulnerabilities", vulnerabilities_not_found),
Evidence("vulnerabilities_found_in_index", vulnerabilities),
Evidence("expected_vulnerabilities", expected_vulnerabilities),
],
)

logging.critical("Validating unexpected vulnerabilities")
test_result.validate_check(
"no_unexpected_vulnerabilities_found_in_index",
[
Evidence("unexpected_vulnerabilities", vulnerabilities_unexpected),
Evidence("vulnerabilities_found_in_index", vulnerabilities),
Evidence("expected_vulnerabilities", expected_vulnerabilities),
],
)

alerts = get_vulnerability_alerts(host_manager, AGENTS_SCANNED_FIRST_SCAN, package_data, test_timestamp)
expected_alerts = get_expected_alerts(
host_manager, AGENTS_SCANNED_FIRST_SCAN, body["operation"], body["package"]
)

result_alert = compare_expected_found_vulnerabilities_alerts(
alerts, expected_alerts
)

logging.critical("Validating found alerts")
test_result.validate_check(
"expected_vulnerability_affected_alert",
[
Evidence(
"missing_affected_alerts",
result_alert["vulnerabilities_affected_not_found"],
),
Evidence("alerts_found_in_index", alerts),
Evidence("expected_alerts", expected_alerts),
],
)

logging.critical("Validating unexpected alerts")
test_result.validate_check(
"expected_vulnerability_mitigated_alert",
[
Evidence(
"missing_mitigated_alerts",
result_alert["vulnerabilities_mitigated_not_found"],
),
Evidence("alerts_found_in_index", alerts),
Evidence("expected_alerts", expected_alerts),
],
)

errors_environment = check_errors_in_environment(
host_manager,
expected_errors=VULNERABILITY_DETECTION_E2E_EXPECTED_ERRORS,
greater_than_timestamp=test_timestamp,
)

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

> assert test_result.get_test_result(), test_result.report()
E AssertionError:
E Test test_vulnerability_detector_scans_cases[upgrade_package_nonvulnerable_to_vulnerable] failed
E
E Check no_errors succeeded
E Check operation_successfull_for_all_agents succeeded
E Check expected_vulnerabilities_found_in_index succeeded
E Check no_unexpected_vulnerabilities_found_in_index succeeded
E Check expected_vulnerability_affected_alert failed. Evidences (['missing_affected_alerts']) can be found in the report.
E Check expected_vulnerability_mitigated_alert succeeded
E Check setup_operation_results succeeded
E Check no_duplicated_vulnerabilities failed. Evidences (['duplicated_vulnerabilities']) can be found in the report.
E -----
E
E assert False
E + where False = <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c3680dc0>>()
E + where <bound method TestResult.get_test_result of <wazuh_testing.end_to_end.TestResult object at 0x7dd0c3680dc0>> = <wazuh_testing.end_to_end.TestResult object at 0x7dd0c3680dc0>.get_test_result

end_to_end/test_vulnerability_detector/test_vulnerability_detector.py:993: AssertionError
-------------------------------Captured log call--------------------------------
ERROR root:__init__.py:237 Marked check setup_operation_results result to True with evidences ['setup_failed_agents'] CRITICAL root:test_vulnerability_detector.py:903 Remote operation results: {'agent1': True} ERROR root:__init__.py:237 Marked check operation_successfull_for_all_agents result to True with evidences ['operation_results'] ERROR root:__init__.py:237 Marked check no_duplicated_vulnerabilities result to False with evidences ['duplicated_vulnerabilities', 'vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:930 Validating found vulnerabilities ERROR root:__init__.py:237 Marked check expected_vulnerabilities_found_in_index result to True with evidences ['missing_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:940 Validating unexpected vulnerabilities ERROR root:__init__.py:237 Marked check no_unexpected_vulnerabilities_found_in_index result to True with evidences ['unexpected_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:check_validators.py:123 Vulnerabilities affected not found: {'agent1': [Vulnerability(cve='CVE-2022-31129', package_name='luxon', package_version='3.0.0', architecture='')]} CRITICAL root:check_validators.py:124 Vulnerabilities mitigated not found: {} CRITICAL root:test_vulnerability_detector.py:959 Validating found alerts CRITICAL root:check_validators.py:145 agent1 is not empty: [Vulnerability(cve='CVE-2022-31129', package_name='luxon', package_version='3.0.0', architecture='')] ERROR root:__init__.py:237 Marked check expected_vulnerability_affected_alert result to False with evidences ['missing_affected_alerts', 'alerts_found_in_index', 'expected_alerts'] CRITICAL root:test_vulnerability_detector.py:972 Validating unexpected alerts ERROR root:__init__.py:237 Marked check expected_vulnerability_mitigated_alert result to True with evidences ['missing_mitigated_alerts', 'alerts_found_in_index', 'expected_alerts'] ERROR root:__init__.py:237 Marked check no_errors result to True with evidences ['error_level_messages']
-----------------------------Captured log teardown------------------------------
ERROR root:conftest.py:152 Truncate managers and agents logs
Passed test_vulnerability_detector/test_vulnerability_detector.py::TestInitialScans::test_first_syscollector_scan[vd_disabled_when_agents_registration] description: Validates the initiation of the first Syscollector scans across all agents in the environment. 790.65

Test function details

Extended Summary

This test ensures that Syscollector first scans are started in all agents in the environment.
tier: 0
parameters:
- request: pytest request object
- host_manager:
type: fixture
brief: Get the host manager of the environment
- vulnerability_detection_previously_enabled:
type: fixture
brief: Whether the vulnerability detection was previously enabled
- configure_environment:
type: fixture
brief: Configure the environment with the given configurations
- get_results: fixture to get the results of global class tests
assertions:
- Verify that all agents has been scanned

Parameters

-------------------------------Captured log setup-------------------------------
CRITICAL root:conftest.py:376 Enabling modulesd debug mode ERROR root:conftest.py:276 Save the Wazuh indexer username and password into the Wazuh manager keystore ERROR root:test_vulnerability_detector.py:107 Configuring the environment: Vulnerability Detection Enabled: False ERROR root:test_vulnerability_detector.py:126 Restarting managers ERROR root:test_vulnerability_detector.py:140 Starting agents ERROR root:test_vulnerability_detector.py:143 Wait until agents are connected ERROR root:test_vulnerability_detector.py:107 Configuring the environment: Vulnerability Detection Enabled: True ERROR root:test_vulnerability_detector.py:126 Restarting managers ERROR root:test_vulnerability_detector.py:130 Wait until Vulnerability Detector has update all the feeds
-------------------------------Captured log call--------------------------------
ERROR root:__init__.py:237 Marked check all_agents_scanned_syscollector_first_scan result to True with evidences ['agents_not_scanned_syscollector_first_scan'] CRITICAL root:test_vulnerability_detector.py:319 Waiting until agent all agents have been scanned. CRITICAL root:test_vulnerability_detector.py:322 Checking vulnerabilities in the index CRITICAL root:test_vulnerability_detector.py:341 Checking that all agents has been scanned and generated vulnerabilities in the index ERROR root:__init__.py:237 Marked check all_agents_scanned_vulnerability_first_scan result to True with evidences ['agents_not_scanned_vulnerability_first_scan', 'vulnerabilities_index_first_scan'] CRITICAL root:test_vulnerability_detector.py:365 Checking for errors in the environment ERROR root:__init__.py:237 Marked check no_errors result to True with evidences ['error_level_messages']
Passed test_vulnerability_detector/test_vulnerability_detector.py::TestInitialScans::test_first_syscollector_scan[vd_enabled_when_agents_registration] description: Validates the initiation of the first Syscollector scans across all agents in the environment. 474.91

Test function details

Extended Summary

This test ensures that Syscollector first scans are started in all agents in the environment.
tier: 0
parameters:
- request: pytest request object
- host_manager:
type: fixture
brief: Get the host manager of the environment
- vulnerability_detection_previously_enabled:
type: fixture
brief: Whether the vulnerability detection was previously enabled
- configure_environment:
type: fixture
brief: Configure the environment with the given configurations
- get_results: fixture to get the results of global class tests
assertions:
- Verify that all agents has been scanned

Parameters

-------------------------------Captured log setup-------------------------------
ERROR root:test_vulnerability_detector.py:107 Configuring the environment: Vulnerability Detection Enabled: True ERROR root:test_vulnerability_detector.py:126 Restarting managers ERROR root:test_vulnerability_detector.py:130 Wait until Vulnerability Detector has update all the feeds ERROR root:test_vulnerability_detector.py:140 Starting agents ERROR root:test_vulnerability_detector.py:143 Wait until agents are connected
-------------------------------Captured log call--------------------------------
ERROR root:__init__.py:237 Marked check all_agents_scanned_syscollector_first_scan result to True with evidences ['agents_not_scanned_syscollector_first_scan'] CRITICAL root:test_vulnerability_detector.py:319 Waiting until agent all agents have been scanned. CRITICAL root:test_vulnerability_detector.py:322 Checking vulnerabilities in the index CRITICAL root:test_vulnerability_detector.py:341 Checking that all agents has been scanned and generated vulnerabilities in the index ERROR root:__init__.py:237 Marked check all_agents_scanned_vulnerability_first_scan result to True with evidences ['agents_not_scanned_vulnerability_first_scan', 'vulnerabilities_index_first_scan'] CRITICAL root:test_vulnerability_detector.py:365 Checking for errors in the environment ERROR root:__init__.py:237 Marked check no_errors result to True with evidences ['error_level_messages']
Passed test_vulnerability_detector/test_vulnerability_detector.py::TestInitialScans::test_syscollector_second_scan description: Validates the initiation of the second Syscollector scans across all agents in the environment. 214.84

Test function details

Extended Summary

This test ensures that Syscollector second scans are started in all agents in the environment.
tier: 0
parameters:
- request: pytest request object
- host_manager:
type: fixture
brief: Get the host manager of the environment
- setup_vulnerability_tests:
type: fixture
brief: Setup the environment to proceed with the testing
- get_results: fixture to get the results of global class tests
assertions:
- Verify that all agents has been scanned
cases: None
tags:
- syscollector
- vulnerability_detector

Parameters

-------------------------------Captured log call--------------------------------
ERROR root:__init__.py:237 Marked check all_agents_scanned_syscollector_second_scan result to True with evidences ['agents_not_scanned_syscollector_second_scan'] CRITICAL root:test_vulnerability_detector.py:492 Waiting until agent all agents have been scanned. CRITICAL root:test_vulnerability_detector.py:497 Checking vulnerabilities in the index CRITICAL root:test_vulnerability_detector.py:502 Checking that all agents has been scanned and generated vulnerabilities in the index ERROR root:__init__.py:237 Marked check vulnerabilities_consistent_first_second_scan result to True with evidences ['vulnerabilities_index_first_scan', 'vulnerabilities_index_second_scan'] ERROR root:__init__.py:237 Marked check no_errors result to True with evidences ['error_level_messages']
Passed test_vulnerability_detector/test_vulnerability_detector.py::TestScanSyscollectorCases::test_install_vulnerable_package_when_agent_down[install_package] description: Install a vulnerable package when the agent is down. 403.68

Test function details

Extended Summary

This test ensures that the Vulnerability Detector detects the vulnerability when the agent is down.
tier: 0
parameters:
- request: pytest request object
- host_manager:
type: fixture
brief: Get the host manager of the environment
- configure_environment:
type: fixture
brief: Configure the environment with the given configurations
- get_results: fixture to get the results of global class tests
assertions:

Parameters

-------------------------------Captured log call--------------------------------
CRITICAL root:test_vulnerability_detector.py:682 Remote operation results: {'agent1': True} ERROR root:__init__.py:237 Marked check operation_successfull_for_all_agents result to True with evidences ['operation_results'] CRITICAL root:test_vulnerability_detector.py:700 Validating found vulnerabilities ERROR root:__init__.py:237 Marked check no_duplicated_vulnerabilities result to True with evidences ['duplicated_vulnerabilities', 'vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:711 Validating found vulnerabilities ERROR root:__init__.py:237 Marked check expected_vulnerabilities_found_in_index result to True with evidences ['missing_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:721 Validating unexpected vulnerabilities ERROR root:__init__.py:237 Marked check no_unexpected_vulnerabilities_found_in_index result to True with evidences ['unexpected_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] ERROR root:__init__.py:237 Marked check no_errors result to True with evidences ['error_level_messages']
-----------------------------Captured log teardown------------------------------
ERROR root:conftest.py:152 Truncate managers and agents logs
Passed test_vulnerability_detector/test_vulnerability_detector.py::TestScanSyscollectorCases::test_vulnerability_detector_scans_cases[upgrade_package_nonvulnerable_to_nonvulnerable] 281.90

Test function details

Extended Summary

Parameters

-------------------------------Captured log call--------------------------------
ERROR root:__init__.py:237 Marked check setup_operation_results result to True with evidences ['setup_failed_agents'] CRITICAL root:test_vulnerability_detector.py:903 Remote operation results: {'agent1': True} ERROR root:__init__.py:237 Marked check operation_successfull_for_all_agents result to True with evidences ['operation_results'] ERROR root:__init__.py:237 Marked check no_duplicated_vulnerabilities result to True with evidences ['duplicated_vulnerabilities', 'vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:930 Validating found vulnerabilities ERROR root:__init__.py:237 Marked check expected_vulnerabilities_found_in_index result to True with evidences ['missing_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:940 Validating unexpected vulnerabilities ERROR root:__init__.py:237 Marked check no_unexpected_vulnerabilities_found_in_index result to True with evidences ['unexpected_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:959 Validating found alerts ERROR root:__init__.py:237 Marked check expected_vulnerability_affected_alert result to True with evidences ['missing_affected_alerts', 'alerts_found_in_index', 'expected_alerts'] CRITICAL root:test_vulnerability_detector.py:972 Validating unexpected alerts ERROR root:__init__.py:237 Marked check expected_vulnerability_mitigated_alert result to True with evidences ['missing_mitigated_alerts', 'alerts_found_in_index', 'expected_alerts'] ERROR root:__init__.py:237 Marked check no_errors result to True with evidences ['error_level_messages']
-----------------------------Captured log teardown------------------------------
ERROR root:conftest.py:152 Truncate managers and agents logs
Passed test_vulnerability_detector/test_vulnerability_detector.py::TestScanSyscollectorCases::test_vulnerability_detector_scans_cases[install_package_non_vulnerable] 282.64

Test function details

Extended Summary

Parameters

-------------------------------Captured log call--------------------------------
ERROR root:__init__.py:237 Marked check setup_operation_results result to True with evidences ['setup_failed_agents'] CRITICAL root:test_vulnerability_detector.py:903 Remote operation results: {'agent1': True} ERROR root:__init__.py:237 Marked check operation_successfull_for_all_agents result to True with evidences ['operation_results'] ERROR root:__init__.py:237 Marked check no_duplicated_vulnerabilities result to True with evidences ['duplicated_vulnerabilities', 'vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:930 Validating found vulnerabilities ERROR root:__init__.py:237 Marked check expected_vulnerabilities_found_in_index result to True with evidences ['missing_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:940 Validating unexpected vulnerabilities ERROR root:__init__.py:237 Marked check no_unexpected_vulnerabilities_found_in_index result to True with evidences ['unexpected_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:959 Validating found alerts ERROR root:__init__.py:237 Marked check expected_vulnerability_affected_alert result to True with evidences ['missing_affected_alerts', 'alerts_found_in_index', 'expected_alerts'] CRITICAL root:test_vulnerability_detector.py:972 Validating unexpected alerts ERROR root:__init__.py:237 Marked check expected_vulnerability_mitigated_alert result to True with evidences ['missing_mitigated_alerts', 'alerts_found_in_index', 'expected_alerts'] ERROR root:__init__.py:237 Marked check no_errors result to True with evidences ['error_level_messages']
-----------------------------Captured log teardown------------------------------
ERROR root:conftest.py:152 Truncate managers and agents logs
Passed test_vulnerability_detector/test_vulnerability_detector.py::TestScanSyscollectorCases::test_vulnerability_detector_scans_cases[remove_non_vulnerable_packge] 318.06

Test function details

Extended Summary

Parameters

-------------------------------Captured log call--------------------------------
ERROR root:__init__.py:237 Marked check setup_operation_results result to True with evidences ['setup_failed_agents'] CRITICAL root:test_vulnerability_detector.py:903 Remote operation results: {'agent1': True} ERROR root:__init__.py:237 Marked check operation_successfull_for_all_agents result to True with evidences ['operation_results'] ERROR root:__init__.py:237 Marked check no_duplicated_vulnerabilities result to True with evidences ['duplicated_vulnerabilities', 'vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:930 Validating found vulnerabilities ERROR root:__init__.py:237 Marked check expected_vulnerabilities_found_in_index result to True with evidences ['missing_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:940 Validating unexpected vulnerabilities ERROR root:__init__.py:237 Marked check no_unexpected_vulnerabilities_found_in_index result to True with evidences ['unexpected_vulnerabilities', 'vulnerabilities_found_in_index', 'expected_vulnerabilities'] CRITICAL root:test_vulnerability_detector.py:959 Validating found alerts ERROR root:__init__.py:237 Marked check expected_vulnerability_affected_alert result to True with evidences ['missing_affected_alerts', 'alerts_found_in_index', 'expected_alerts'] CRITICAL root:test_vulnerability_detector.py:972 Validating unexpected alerts ERROR root:__init__.py:237 Marked check expected_vulnerability_mitigated_alert result to True with evidences ['missing_mitigated_alerts', 'alerts_found_in_index', 'expected_alerts'] ERROR root:__init__.py:237 Marked check no_errors result to True with evidences ['error_level_messages']
-----------------------------Captured log teardown------------------------------
ERROR root:conftest.py:152 Truncate managers and agents logs ERROR root:conftest.py:164 Delete vulnerability index ERROR root:conftest.py:138 Truncate managers and agents logs CRITICAL root:conftest.py:384 Disabling modulesd debug mode