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

Add EPS limit test to Wazuh-QA repository #3181

Closed
wants to merge 79 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
0097ffb
add: Add limit EPS test #2947
fedepacher Aug 17, 2022
aaf5985
add: Add message number error event #2947
fedepacher Aug 17, 2022
9490d8b
refac: Refactor agent_simulator.py to get message with number #2947
fedepacher Aug 17, 2022
a810b0c
refact: Refactor variable names #2947
fedepacher Aug 17, 2022
6c11007
refact: Refactor code style #2947
fedepacher Aug 17, 2022
9e240e2
refac: Update changelog file #2947
fedepacher Aug 17, 2022
f61b25e
refact: Refactor code style #2947
fedepacher Aug 17, 2022
c2bab2c
refac: Refactor code indentation #2947
fedepacher Aug 17, 2022
f817116
refac: Refactor variable and method names #2947
fedepacher Aug 18, 2022
e11d283
refac: Refactor code style #2947
fedepacher Aug 18, 2022
82baa10
refac: Refactor variable name #2947
fedepacher Aug 18, 2022
f47ef67
refac: Refactor fixture to load local internal configuration #2947
fedepacher Aug 18, 2022
cb8c59b
refac: Refactor fixture scope #2947
fedepacher Aug 18, 2022
0817288
add: Add new fixture to load a basic configuration #2947
fedepacher Aug 19, 2022
678f727
refac: Refactor code style and configuration files #2947
fedepacher Aug 19, 2022
50562b8
fix(#2947): fix simulate_agent.py path in fixture
fedepacher Aug 22, 2022
796e304
refactor(#2947): refacor configuration and cases files
fedepacher Aug 22, 2022
2d0b626
feat(#2947): add test for default configuration
fedepacher Aug 22, 2022
2de9f57
refactor(#2947): refactor tests
fedepacher Aug 23, 2022
d161264
feat(#2947): add new fixture to load custom rules
fedepacher Aug 23, 2022
6bb603f
refactor(#2947): refacator to use filemonitor
fedepacher Aug 23, 2022
e98b02a
docs(#2947): refactor documentation
fedepacher Aug 23, 2022
42a54a7
refactor(#2947): refactor code style
fedepacher Aug 23, 2022
324fd73
feat(#2947)!: add send event with custom messages
fedepacher Aug 24, 2022
051119e
refactor(#2947): refactor variable name
fedepacher Aug 24, 2022
0af0929
feat(#2947): add new callback to look for regex
fedepacher Aug 24, 2022
707da67
refactor(#2947): refactor test name
fedepacher Aug 24, 2022
c6196b1
refactor(#2947): refactor simulate agent fixture
fedepacher Aug 24, 2022
5f1b6cb
feat(#2947): add message for simulate agent
fedepacher Aug 24, 2022
9ae4dae
refactor(#2947): refactor code style
fedepacher Aug 24, 2022
14ffd58
feat(#2947): add new custom messages
fedepacher Aug 25, 2022
1d7050a
refactor(#2947): refactor configuration and tcase
fedepacher Aug 25, 2022
70d4e4d
refactor(#2947): refactor callback function
fedepacher Aug 25, 2022
fe5c0e2
refactor(#2947): refactor code style
fedepacher Aug 25, 2022
1bade87
refactor(#2947): refactor agent simulator config
fedepacher Aug 25, 2022
c193f97
feat(#2947): add syslog simulator
fedepacher Aug 26, 2022
8de333b
feat(#2947): add syslog configuration file
fedepacher Aug 26, 2022
c023ee8
feat(#2947): refactor test configuration
fedepacher Aug 26, 2022
f518468
refactor(#2947): refactor test case configuration
fedepacher Aug 26, 2022
8b15e43
refactor(#2947): refactor syslog simulator config
fedepacher Aug 26, 2022
e83d5d5
refactor(#2947): refactor function name
fedepacher Aug 26, 2022
c6f92b5
refactor(#2947): refactor check variables
fedepacher Aug 29, 2022
dc22556
feat(#2947): add new method and fixture
fedepacher Aug 29, 2022
fcb24c8
refactor(#2947): refactor configration and cases
fedepacher Aug 29, 2022
b6b2688
feat(#2947): add new variables for test
fedepacher Aug 29, 2022
30c99b4
refactor(#2947): refactor test to use syslog sim
fedepacher Aug 29, 2022
04a598b
style(#2947): refactor code style
fedepacher Aug 29, 2022
3284903
refactor(#2947): delete unused method
fedepacher Aug 29, 2022
9cd8242
refactor(#2947): relocation global variables
fedepacher Sep 1, 2022
c127bce
refactor(#2947): separate syslog class to the script
fedepacher Sep 1, 2022
b329620
refactor(#2947): refactor variables and fixture names
fedepacher Sep 1, 2022
6a6f800
docs(#2947): refactor documentation style
fedepacher Sep 1, 2022
e71d45b
refactor(#2947): clean code and refactor fixture names
fedepacher Sep 1, 2022
120e6c0
refactor(#2947): refactor configuration
fedepacher Sep 1, 2022
a30dcef
refactor(#2947): refactor code style
fedepacher Sep 2, 2022
064091f
Merge branch '4.4' of github.com:wazuh/wazuh-qa into 2947-test-eps
jmv74211 Sep 5, 2022
19ea2cd
refactor(2947): Improve daemon checking in EPS limit tests
jmv74211 Sep 5, 2022
5e114eb
refactor(#2947): Move simulator functions to new module
jmv74211 Sep 5, 2022
50eeb07
refactor(#2947): Move EPS event monitor to analysisd module
jmv74211 Sep 5, 2022
5ac7de7
refactor(#2947): update fixture for setting local internal options
jmv74211 Sep 8, 2022
e8d08af
refactor(#2947): Move analysisd fixtures to integration conftest
jmv74211 Sep 12, 2022
a010b78
refactor(#2947): remove old tests structure
jmv74211 Sep 21, 2022
04d7382
feat(#2947): add function to replace regex in file
jmv74211 Sep 21, 2022
e29c107
feat(#2947): add fixture for restarting wazuh
jmv74211 Sep 21, 2022
86e80b2
feat(#2947): add EPS basic tests
jmv74211 Sep 21, 2022
58ab5f8
feat(#2947): add EPS configuration tests
jmv74211 Sep 21, 2022
7923898
feat(#2947): add test limitation
jmv74211 Sep 23, 2022
43a07e9
build(#2947): add wazuh light configuration template
jmv74211 Sep 28, 2022
96449db
refactor(#2947): remove unused template files
jmv74211 Sep 28, 2022
6d3965a
feat(#2947): add numbered messages feature to syslog simulator
jmv74211 Sep 28, 2022
5092384
feat(#2947): add truncate_event_logs fixture
jmv74211 Sep 28, 2022
34e190a
refactor(#2947): add new global vars
jmv74211 Sep 28, 2022
889046f
feat(#2947): add method to get wazuh minimal configuration
jmv74211 Sep 28, 2022
421dd43
feat(#2947): add new EPS limit tests
jmv74211 Sep 28, 2022
ac4e6a1
refactor(#2947): rename limit eps suite testing
jmv74211 Sep 29, 2022
3d21556
merge: branch 4.4 into 2947-test-eps
jmv74211 Sep 29, 2022
4528aeb
style: improve the code format according to PEP-8
jmv74211 Sep 29, 2022
3a58a40
refactor(#2947): remove unused code
jmv74211 Sep 29, 2022
fdb9293
refactor(#2947): remove unused variable
jmv74211 Sep 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Wazuh commit: TBD \
Release report: TBD

### Added

- New testing suite for checking analysisd EPS limitation([#2947](https:/wazuh/wazuh-qa/pull/3181)) \- (Framework + Tests)
- Add E2E tests for demo cases ([#3293](https:/wazuh/wazuh-qa/pull/3293)) \- (Framework + Tests)
- Add configuration files for Jenkins automation of system/E2E tests ([#3221](https:/wazuh/wazuh-qa/pull/3221)) \- (Framework)
- New vulnerability Detector integration tests for Ubuntu 22.04 ([#2957](https:/wazuh/wazuh-qa/pull/2957)) \- (Framework + Tests)
Expand Down
3 changes: 2 additions & 1 deletion deps/wazuh_testing/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
'qa_ctl/deployment/dockerfiles/qa_ctl/*',
'qa_ctl/deployment/vagrantfile_template.txt',
'qa_ctl/provisioning/wazuh_deployment/templates/preloaded_vars.conf.j2',
'data/qactl_conf_validator_schema.json'
'data/qactl_conf_validator_schema.json',
'data/all_disabled_ossec.conf'
]

scripts_list = [
Expand Down
12 changes: 12 additions & 0 deletions deps/wazuh_testing/wazuh_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
else:
WAZUH_PATH = os.path.join("/var", "ossec")


WAZUH_CONF_PATH = os.path.join(WAZUH_PATH, 'etc', 'ossec.conf')
WAZUH_LOGS_PATH = os.path.join(WAZUH_PATH, 'logs')
CLIENT_KEYS_PATH = os.path.join(WAZUH_PATH, 'etc' if platform.system() == 'Linux' else '', 'client.keys')
DB_PATH = os.path.join(WAZUH_PATH, 'queue', 'db')
QUEUE_DB_PATH = os.path.join(WAZUH_PATH, 'queue', 'db')
Expand All @@ -26,12 +29,15 @@
CVE_DB_PATH = os.path.join(WAZUH_PATH, 'queue', 'vulnerabilities', 'cve.db')
LOG_FILE_PATH = os.path.join(WAZUH_PATH, 'logs', 'ossec.log')
ALERTS_JSON_PATH = os.path.join(WAZUH_PATH, 'logs', 'alerts', 'alerts.json')
ARCHIVES_LOG_PATH = os.path.join(WAZUH_PATH, 'logs', 'archives', 'archives.log')
ARCHIVES_JSON_PATH = os.path.join(WAZUH_PATH, 'logs', 'archives', 'archives.json')
CPE_HELPER_PATH = os.path.join(WAZUH_PATH, 'queue', 'vulnerabilities', 'dictionaries', 'cpe_helper.json')
WAZUH_API_CONF = os.path.join(WAZUH_PATH, 'api', 'configuration', 'api.yaml')
WAZUH_SECURITY_CONF = os.path.join(WAZUH_PATH, 'api', 'configuration', 'security', 'security.yaml')
API_LOG_FILE_PATH = os.path.join(WAZUH_PATH, 'logs', 'api.log')
API_JSON_LOG_FILE_PATH = os.path.join(WAZUH_PATH, 'logs', 'api.json')
API_LOG_FOLDER = os.path.join(WAZUH_PATH, 'logs', 'api')
WAZUH_TESTING_PATH = os.path.dirname(os.path.abspath(__file__))

# Daemons
LOGCOLLECTOR_DAEMON = 'wazuh-logcollector'
Expand All @@ -52,11 +58,17 @@

API_DAEMONS_REQUIREMENTS = [API_DAEMON, DB_DAEMON, EXEC_DAEMON, ANALYSISD_DAEMON, REMOTE_DAEMON, MODULES_DAEMON]

# Paths
SYSLOG_SIMULATOR = os.path.join(WAZUH_TESTING_PATH, 'scripts', 'syslog_simulator.py')
ANALYSISD_STATE = os.path.join(WAZUH_PATH, 'var', 'run', 'wazuh-analysisd.state')

# Timeouts
T_5 = 5
T_10 = 10
T_20 = 20
T_30 = 30
T_60 = 60


# Protocols
UDP = 'UDP'
Expand Down
87 changes: 87 additions & 0 deletions deps/wazuh_testing/wazuh_testing/data/all_disabled_ossec.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<ossec_config>
<global>
<alerts_log>yes</alerts_log>
</global>

<!-- Choose between "plain", "json", or "plain,json" for the format of internal logs -->
<logging>
<log_format>plain</log_format>
</logging>

<remote>
<connection>secure</connection>
<port>1514</port>
<protocol>tcp</protocol>
<queue_size>131072</queue_size>
</remote>

<!-- Policy monitoring -->
<rootcheck>
<disabled>yes</disabled>
</rootcheck>

<wodle name="cis-cat">
<disabled>yes</disabled>
</wodle>

<!-- Osquery integration -->
<wodle name="osquery">
<disabled>yes</disabled>
</wodle>

<!-- System inventory -->
<wodle name="syscollector">
<disabled>yes</disabled>
</wodle>

<sca>
<enabled>no</enabled>
</sca>

<vulnerability-detector>
<enabled>no</enabled>
</vulnerability-detector>

<!-- File integrity monitoring -->
<syscheck>
<disabled>yes</disabled>
</syscheck>

<ruleset>
<!-- Default ruleset -->
<decoder_dir>ruleset/decoders</decoder_dir>
<rule_dir>ruleset/rules</rule_dir>
<rule_exclude>0215-policy_rules.xml</rule_exclude>
<list>etc/lists/audit-keys</list>
<list>etc/lists/amazon/aws-eventnames</list>
<list>etc/lists/security-eventchannel</list>

<!-- User-defined ruleset -->
<decoder_dir>etc/decoders</decoder_dir>
<rule_dir>etc/rules</rule_dir>
</ruleset>

<rule_test>
<enabled>yes</enabled>
<threads>1</threads>
<max_sessions>64</max_sessions>
<session_timeout>15m</session_timeout>
</rule_test>

<!-- Configuration for wazuh-authd -->
<auth>
<disabled>no</disabled>
<port>1515</port>
<use_source_ip>no</use_source_ip>
<purge>yes</purge>
<use_password>no</use_password>
<ciphers>HIGH:!ADH:!EXP:!MD5:!RC4:!3DES:!CAMELLIA:@STRENGTH</ciphers>
<!-- <ssl_agent_ca></ssl_agent_ca> -->
<ssl_verify_host>no</ssl_verify_host>
<ssl_manager_cert>etc/sslmanager.cert</ssl_manager_cert>
<ssl_manager_key>etc/sslmanager.key</ssl_manager_key>
<ssl_auto_negotiate>no</ssl_auto_negotiate>
</auth>

</ossec_config>

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

ANALYSISD_PREFIX = r'.*wazuh-analysisd.*'
MAILD_PREFIX = r'.*wazuh-maild.*'
QUEUE_EVENTS_SIZE = 16384
ANALYSISD_ONE_THREAD_CONFIG = {'analysisd.event_threads': '1', 'analysisd.syscheck_threads': '1',
'analysisd.syscollector_threads': '1', 'analysisd.rootcheck_threads': '1',
'analysisd.sca_threads': '1', 'analysisd.hostinfo_threads': '1',
'analysisd.winevt_threads': '1', 'analysisd.rule_matching_threads': '1',
'analysisd.dbsync_threads': '1', 'remoted.worker_pool': '1'}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import re

from wazuh_testing import T_10, T_20, T_60
from wazuh_testing.modules.analysisd import ANALYSISD_PREFIX, MAILD_PREFIX
from wazuh_testing import LOG_FILE_PATH, ANALYSISD_STATE
from wazuh_testing.tools.monitoring import FileMonitor, generate_monitoring_callback_groups


def make_analysisd_callback(pattern, prefix=ANALYSISD_PREFIX):
"""Create a callback function from a text pattern.

It already contains the analsisd prefix.

Args:
pattern (str): String to match on the log.
prefix (str): regular expression used as a prefix before the pattern.

Returns:
lambda: function that returns if there's a match in the file

Examples:
>>> callback_bionic_update_started = make_vuln_callback("Starting Ubuntu Bionic database update")
"""
pattern = r'\s+'.join(pattern.split())
regex = re.compile(r'{}{}'.format(prefix, pattern))

return lambda line: regex.match(line) is not None


def check_analysisd_event(file_monitor=None, callback='', error_message=None, update_position=True,
timeout=T_60, prefix=ANALYSISD_PREFIX, accum_results=1, file_to_monitor=LOG_FILE_PATH):
"""Check if a analysisd event occurs

Args:
file_monitor (FileMonitor): FileMonitor object to monitor the file content.
callback (str): log regex to check in Wazuh log
error_message (str): error message to show in case of expected event does not occur
update_position (boolean): filter configuration parameter to search in Wazuh log
timeout (str): timeout to check the event in Wazuh log
prefix (str): log pattern regex
accum_results (int): Accumulation of matches.
"""
file_monitor = FileMonitor(file_to_monitor) if file_monitor is None else file_monitor
error_message = f"Could not find this event in {file_to_monitor}: {callback}" if error_message is None else \
error_message

file_monitor.start(timeout=timeout, update_position=update_position, accum_results=accum_results,
callback=make_analysisd_callback(callback, prefix), error_message=error_message)


def check_eps_disabled():
"""Check if the eps module is disabled"""
check_analysisd_event(callback=fr'.*INFO: EPS limit disabled.*', timeout=T_10)


def check_eps_enabled(maximum, timeframe):
"""Check if the eps module is enable"""
check_analysisd_event(callback=fr".*INFO: EPS limit enabled, EPS: '{maximum}', timeframe: '{timeframe}'",
timeout=T_10)


def check_configuration_error():
"""Check the configuration error event in ossec.log"""
check_analysisd_event(timeout=T_10, callback=r".* \(\d+\): Configuration error at.*",
error_message="Could not find the event 'Configuration error at 'etc/ossec.conf' "
'in ossec.log', prefix=MAILD_PREFIX)


def get_analysisd_state():
"""Get the states values of wazuh-analysisd.state file

Returns:
dict: Dictionary with all analysisd state
"""
data = ""
with open(ANALYSISD_STATE, 'r') as file:
for line in file.readlines():
if not line.startswith("#") and not line.startswith('\n'):
data = data + line.replace('\'', '')
data = data[:-1]
analysisd_state = dict((a.strip(), b.strip()) for a, b in (element.split('=') for element in data.split('\n')))

return analysisd_state
Loading