-
Notifications
You must be signed in to change notification settings - Fork 32
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 integratord test_integratord_read_json_file_deleted
#3540
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c236371
refactor(#3298): refactor integratord tests to use slack
fedepacher 0696b33
refactor(#3298): refactor test variables and add callback function
fedepacher adb6a69
refactor(#3298): refactor test timeout
fedepacher 70ea041
refactor(#3298): add new line to changelog file
fedepacher 5d7b1d0
refactor(#3298): refactor code style
fedepacher 825fbe9
refactor(#3298): create event_monitor function for each log to find.
fedepacher 3d8a6a8
refactor: make some improvements to integratord tests
jmv74211 fdee9e2
refactor(#3298): remove json_file_deleted test.
mauromalara 96aa5aa
refactor(#3298): add a daemons_handler function-scoped.
mauromalara 1202581
refactor(#3298): apply multiple changes to integratord monitor.
mauromalara b00e663
refactor(#3298): refactor, fix, and unified several tests.
mauromalara 020d61e
fix(#3298): apply linter corrections.
mauromalara 13d40bc
fix(#3298): fix identation error in config file.
mauromalara 5e86677
merge(#3298): merge 4.4 into 3298-refactor-integratord-test-4-4
mauromalara e80ff77
docs(#3298): update change in changelog.
mauromalara aa1356d
merge(#3928): 4.4
Rebits File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,11 +122,39 @@ def restart_wazuh_daemon_function(daemon=None): | |
|
||
|
||
@pytest.fixture(scope='function') | ||
def restart_wazuh_function(daemon=None): | ||
"""Restart all Wazuh daemons""" | ||
control_service("restart", daemon=daemon) | ||
def restart_wazuh_function(request): | ||
"""Restart before starting a test, and stop it after finishing. | ||
|
||
Args: | ||
request (fixture): Provide information on the executing test function. | ||
""" | ||
# If there is a list of required daemons defined in the test module, restart daemons, else restart all daemons. | ||
try: | ||
daemons = request.module.REQUIRED_DAEMONS | ||
except AttributeError: | ||
daemons = [] | ||
|
||
if len(daemons) == 0: | ||
logger.debug(f"Restarting all daemon") | ||
control_service('restart') | ||
else: | ||
for daemon in daemons: | ||
logger.debug(f"Restarting {daemon}") | ||
# Restart daemon instead of starting due to legacy used fixture in the test suite. | ||
control_service('restart', daemon=daemon) | ||
|
||
yield | ||
control_service('stop', daemon=daemon) | ||
|
||
# Stop all daemons by default (daemons = None) | ||
if len(daemons) == 0: | ||
logger.debug(f"Stopping all daemons") | ||
control_service('stop') | ||
else: | ||
# Stop a list daemons in order (as Wazuh does) | ||
daemons.reverse() | ||
for daemon in daemons: | ||
logger.debug(f"Stopping {daemon}") | ||
control_service('stop', daemon=daemon) | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
|
@@ -300,12 +328,12 @@ def pytest_addoption(parser): | |
help="run tests using a specific WPK package path" | ||
) | ||
parser.addoption( | ||
"--integration-api-key", | ||
"--slack-webhook-url", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this change imply new modifications in jenkins ITs repository? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
action="store", | ||
metavar="integration_api_key", | ||
metavar="slack_webhook_url", | ||
default=None, | ||
type=str, | ||
help="pass api key required for integratord tests." | ||
help="pass webhook url required for integratord tests." | ||
) | ||
|
||
|
||
|
@@ -364,10 +392,10 @@ def pytest_configure(config): | |
# Set WPK package version | ||
global_parameters.wpk_version = config.getoption("--wpk_version") | ||
|
||
# Set integration_api_key if it is passed through command line args | ||
integration_api_key = config.getoption("--integration-api-key") | ||
if integration_api_key: | ||
global_parameters.integration_api_key = integration_api_key | ||
# Set slack_webhook_url if it is passed through command line args | ||
slack_webhook_url = config.getoption("--slack-webhook-url") | ||
if slack_webhook_url: | ||
global_parameters.slack_webhook_url = slack_webhook_url | ||
|
||
# Set files to add to the HTML report | ||
set_report_files(config.getoption("--save-file")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 13 additions & 17 deletions
30
.../config_integratord_read_json_alerts.yaml β ...uration/configuration_alerts_reading.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,35 @@ | ||
- tags: | ||
- all | ||
apply_to_modules: | ||
- test_integratord_read_json_alerts | ||
- test_integratord_change_inode_alert | ||
- test_integratord_read_json_file_deleted | ||
sections: | ||
- sections: | ||
- section: integration | ||
elements: | ||
- name: | ||
value: virustotal | ||
- api_key: | ||
value: API_KEY | ||
value: slack | ||
- hook_url: | ||
value: WEBHOOK_URL | ||
- rule_id: | ||
value: '554' | ||
value: 5712 | ||
- level: | ||
value: 10 | ||
- alert_format: | ||
value: json | ||
|
||
- section: sca | ||
elements: | ||
- enabled: | ||
value: 'no' | ||
- section: rootcheck | ||
elements: | ||
- disabled: | ||
value: 'yes' | ||
|
||
- section: syscheck | ||
elements: | ||
- disabled: | ||
value: 'yes' | ||
|
||
- section: wodle | ||
attributes: | ||
- name: syscollector | ||
- name: vulnerability-detector | ||
elements: | ||
- disabled: | ||
value: 'yes' | ||
- section: auth | ||
|
||
- section: rootcheck | ||
elements: | ||
- disabled: | ||
value: 'yes' |
33 changes: 19 additions & 14 deletions
33
tests/integration/test_integratord/data/test_cases/cases_integratord_change_inode_alert.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
- name: Cannot read alerts - Inode changed | ||
- name: cannot_read_alerts_file_inode_changed | ||
description: The alerts.json file inode has changed and it cannot read alerts from it until it reloads. | ||
configuration_parameters: | ||
API_KEY: Insert using --integration-api-key parameter | ||
WEBHOOK_URL: Insert using --slack-webhook-url parameter | ||
metadata: | ||
alert_sample: '{"timestamp":"2022-07-20T14:53:16.482+0000","rule":{"level":5,"description": | ||
"File added to the system.", "id":"554","firedtimes":1,"mail":false,"groups":["ossec","syscheck", | ||
"syscheck_entry_added","syscheck_file"],"pci_dss":["11.5"],"gpg13":["4.11"],"gdpr":["II_5.1.f"], | ||
"hipaa":["164.312.c.1","164.312.c.2"],"nist_800_53":["SI.7"],"tsc":["PI1.4","PI1.5","CC6.1","CC6.8", | ||
"CC7.2","CC7.3"]},"agent":{"id":"000","name":"padding_input"},"manager":{"name":"c3"},"id": | ||
"1657551196.2754","full_log":"File /test_folder/TEST_CHANGED_INODE_ALERT.txt added\nMode: | ||
scheduled\n","syscheck":{"path":"/test_folder/TEST_CHANGED_INODE_ALERT.txt","mode":"scheduled", | ||
"size_after":"16","perm_after":"rw-r--r--","uid_after":"0","gid_after":"0","md5_after": | ||
"2982666f29e2736e7ca0e12dd638d433","sha1_after":"49999430cc5652dedd26352b0342097e8fa3affe", | ||
"sha256_after":"32bc19c9406a98ab21e5ec79fbd5bba2cb79755607a9f382c662d37b5bf5d8ea","uname_after": | ||
"root","gname_after":"root","mtime_after":"2022-07-11T14:53:07","inode_after":9793,"event":"added"}, | ||
"decoder":{"name":"syscheck_new_entry"},"location":"syscheck"}' | ||
alert_sample: '{"timestamp":"2022-05-11T12:29:19.905+0000","rule":{"level":10,"description": | ||
"sshd: brute force trying to get access to the system. Non existent user.","id":"5712", | ||
"mitre":{"id":["T1110"],"tactic":["Credential Access"],"technique":["Brute Force"]},"frequency":8, | ||
"firedtimes":1,"mail":false,"groups":["syslog","sshd","authentication_failures"],"gdpr": | ||
["IV_35.7.d","IV_32.2"],"hipaa":["164.312.b"],"nist_800_53":["SI.4","AU.14","AC.7"],"pci_dss": | ||
["11.4","10.2.4","10.2.5"],"tsc":["CC6.1","CC6.8","CC7.2","CC7.3"]},"agent":{"id":"000","name": | ||
"localhost.localdomain"},"manager":{"name":"localhost.localdomain"},"id":"1652272159.1549653", | ||
"previous_output":"May 11 12:29:16 localhost sshd[17582]: Invalid user paco from 172.17.1.1 port | ||
56402\nMay 11 12:29:14 localhost sshd[17580]: Invalid user paco from 172.17.1.1 port 56400\nMay | ||
11 12:29:11 localhost sshd[17578]: Invalid user paco from 172.17.1.1 port 56398\nMay 11 12:29:09 | ||
localhost sshd[17576]: Invalid user paco from 172.17.1.1 port 56396\nMay 11 12:29:07 localhost | ||
sshd[17574]: Invalid user paco from 172.17.1.1 port 56394\nMay 11 12:29:04 localhost sshd[17572]: | ||
Invalid user paco from 172.17.1.1 port 56392\nMay 11 12:29:00 localhost sshd[17570]: Invalid user | ||
paco from 172.17.1.1 port 56390","full_log":"May 11 12:29:18 localhost sshd[17584]: Invalid user | ||
paco from 172.17.1.1 port 56404","predecoder":{"program_name":"sshd","timestamp":"May 11 12:29:18", | ||
"hostname":"localhost"},"decoder":{"parent":"sshd","name":"sshd"},"data":{"srcip":"172.17.1.1", | ||
"srcport":"56404","srcuser":"paco"},"location":"/var/log/secure"}' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are modifying a global fixture, so you have to guarantee that this change does not break anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IT Executions: #3540 (comment)