Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Refactor initial scan Vulnerability E2E Tests #5081

Merged
merged 9 commits into from
Mar 8, 2024
4 changes: 3 additions & 1 deletion deps/wazuh_testing/wazuh_testing/end_to_end/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from wazuh_testing.tools.system import HostManager


def backup_configurations(host_manager: HostManager) -> Dict[str, str]:
def backup_configurations(host_manager: HostManager) -> Dict[str, List]:
"""
Backup configurations for all hosts in the specified host manager.

Expand All @@ -45,13 +45,15 @@ def backup_configurations(host_manager: HostManager) -> Dict[str, str]:
"""
logging.info("Backing up configurations")
backup_configurations = {}

for host in host_manager.get_group_hosts('all'):
host_os_name = host_manager.get_host_variables(host)['os_name']
configuration_filepath = configuration_filepath_os[host_os_name]

backup_configurations[host] = host_manager.get_file_content(str(host),
configuration_filepath)
logging.info("Configurations backed up")

return backup_configurations


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
from wazuh_testing.tools.system import HostManager
from wazuh_testing.end_to_end.indexer_api import get_indexer_values
from wazuh_testing.end_to_end.regex import REGEX_PATTERNS
from collections import namedtuple


Vulnerability = namedtuple('Vulnerability', ['cve', 'package_name', 'package_version', 'type', 'architecture'])


def load_packages_metadata() -> Dict:
Expand Down Expand Up @@ -284,3 +288,32 @@ def check_vuln_state_consistency(vulnerabilities_alerts, vulnerabilities_states)
'alerts_not_in_states': alerts_not_in_states,
'states_not_in_alerts': states_not_in_alerts
}


def get_vulnerabilities_from_states(vulnerabilities_states: List) -> List:
"""Parse vulnerabilities from the vulnerability state index.

Args:
vulnerabilities_states (list): List of vulnerabilities from the vulnerability state index.

Returns:
list: List of vulnerabilities sorted by cve, package_name, package_version, and architecture.
"""
vulnerabilities = []

for state_vulnerability in vulnerabilities_states:
try:
vulnerability = Vulnerability(
cve=state_vulnerability['_source']['vulnerability']['id'],
package_name=state_vulnerability['_source']['package']['name'],
package_version=state_vulnerability['_source']['package']['version'],
type=state_vulnerability['_source']['pacakge']['type'] if 'type' in state_vulnerability['_source']['vulnerability'] else None,
architecture=state_vulnerability['_source']['package']['architecture'] if 'architecture' in state_vulnerability['_source']['vulnerability'] else None
)
vulnerabilities.append(vulnerability)
except KeyError:
logging.error(f"Error parsing vulnerability: {state_vulnerability}")

vulnerabilities = sorted(vulnerabilities, key=lambda x: (x.cve, x.package_name, x.package_version, x.architecture))

return vulnerabilities
2 changes: 1 addition & 1 deletion deps/wazuh_testing/wazuh_testing/end_to_end/waiters.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from wazuh_testing.modules.syscollector import TIMEOUT_SYSCOLLECTOR_SHORT_SCAN


VD_FEED_UPDATE_TIMEOUT = 300
VD_FEED_UPDATE_TIMEOUT = 600
VD_INITIAL_SCAN_PER_AGENT_TIMEOUT = 15


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TIMEOUT_SYSCOLLECTOR_SCAN = 360
TIMEOUT_SYSCOLLECTOR_SCAN = 130
TIMEOUT_SYSCOLLECTOR_SHORT_SCAN = 90

SYSCOLLECTOR_DELTA_EVENT_TYPES = ['packages', 'hotfix', 'hwinfo', 'ports', 'osinfo', 'network', 'process']
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
- disabled:
value: 'no'
- interval:
value: 1m
value: 2m

1 change: 1 addition & 0 deletions tests/end_to_end/test_vulnerability_detector/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def collect_evidences(test_name, evidences) -> None:
if evidences:
logging.info(f"Collecting custom evidences for {test_name}")
for evidence, content in evidences.items():
logging.info(f"Collecting {evidence} for {test_name}")
if content is not None and content != [] and content != {}:
evidence_file = os.path.join(tests_evidences_directory, evidence + ".log")
with open(evidence_file, 'w') as evidence_file:
Expand Down
Loading
Loading