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

Syncronization testing after group deletingv1 #4088

Closed
wants to merge 288 commits into from

Conversation

pro-akim
Copy link
Member

@pro-akim pro-akim commented Apr 13, 2023

Related issue
#3953

Description

Wazuh manager handles agent groups.
If a group is deleted from a master cluster, there will be an instance where the agents require resynchronization (syncreq).
If the group is deleted from a worker cluster, the cluster master will take care of reestablishing the group structure without the need for resynchronization.
This test suite tests the correct functioning of the mentioned use case.

Added
-test_group_synnc delete_folder_master
-test_group_synnc delete_folder_worker1
-test_group_synnc delete_folder_worker2


Testing performed

Tester Test path Jenkins Local OS Commit Notes
@pro-akim (Developer) ⚫⚫⚫ 🟢🟢🟢 Nothing to highlight
@user (Reviewer) ⚫⚫⚫ ⚫⚫⚫ Nothing to highlight

CamiRomero and others added 30 commits April 28, 2022 14:02
…x-enterprise

IT: VDT - Add test_providers cases for SUSE Linux Enterprise
IT: VDT - Add test_feeds cases for SUSE Linux Enterprise
Added the following PRs:

-  Wazuh-DB: Migration of agent-group files PR (#2815)
damarisg and others added 7 commits February 15, 2023 17:19
* fix: Changes log messages and organize variables

* fix: import variables

* add: delete conf deprecated

* fix: Order of messages

* add: spaces recommended

* rm: conf deprecated

* rm: logs deprecated

* rf: fix messages and callbacks

* rf: remove hardcoded marks

* fix: log message to Windows

* rf: add test to validate registry key limit

* rf: test_registry_limit_full for registry values

* add: new test_registry_key_limit_values

* rm: unused lines

* rf: test_registry_limit_values - update docu

* rf: test_registry_limit_capacity_alerts - fix docu

* rf: test_registr_limit_values - fix documentation

* rf: test_registry_value_limit_full - fix docu

* rf: test_registry_key_limit_full - fix docu

* rf: fix format of key_limit_full

* rf: fix syscheck_event_windows.json

* rm: Skip fixed

* rm: variables name to DB.

* add: variable error and archives.log to Windows.

* Change owner to root

* Fx:Update msg to detect that fim scan was finish

* add: Migration of methods.

* fix: Change messages- Remove skips- Change field name of events.

* skíp: Tier 2 has to refactor required.

* fix: Change log messages - Remove a callback.

* fix: Add file created to check events.

* fix: Check fim_registry event component not exists.

* add: Check that Audit is started when working with whodata.

* fix: Check files created - Add callback of sync initial scan - Remove spaces.

* fix: Check asserts - Remove duplicates variables

* fix test_sync_max_eps for scheduled mode

* add: new test_sync_max_eps for realtime/whodata

* rf: extract common functions and messages

* rf: update wazuh_conf and remove invalid test

* rf: fix test_max_eps.py

* rf: fix wait_for_fim_start_function

* rf: fix test_max_eps for realtime file events

* rf: fix callback

* Fx: Apply Pycodestyle

* rf: fix callback an fim_local_internal_options

* rf: fix codestyle to adhere to pep8

* rf: added whodata cases for test_max_eps

* rf: fix whodata callback for windows

* rf: skipped test because of jenkins behaviour

* Apply suggestions from code review

Co-authored-by: Cami Romero <37776796+CamiRomero@users.noreply.github.com>

* rf: fix variables name in functions

* rf: fix find_value_in_list function

* rf: fix pycodestyle

* rf: remove hardcoded timeouts

* rf: remove skip to test on Jenkins

* refac: disable unneeded fim modules

* fix: fix indentation

* test: skip test_registry_responses_win3

* fix: modify config yml file

* rf: extracted error messages

* fix: added local_internal_options, extracted error messages and fixed key creation

* style: fix to adhere to pep8

* fix: Fix timeout

* rm: remove unnecesary section in test cases

* style: Fix spacing and line lenght

* fix: Modify CB_REGISTRY_DBSYNC_NO_DATA

* fix: Path  check in find_value_in_event_list

* fix: Callbacks to detect fim_registry_key/value

* fix: update imports to module.fim.utils

* rm: Delete unused file fim_synchronization.py

* add: registry_integrity_event callbacks

* fix: event detection in test_sync_enabled_win32

* fix: Callback get registry_key or registry_value

* style: removed whitespaces

* style: Modify comments and Documentation

Co-authored-by: Dámaris  <seyla.gomez@wazuh.com>

* style: rename variable

* rm: Delete unused functions

* rm: Delete duplicated fixture

* fix: Add deleted _create_regular functions

* fix import errors

* fix: Callback CB_INODE_ENTRIES_PATH_COUNT

* fix(#3036): fix file_limit configs

* docu(#3036): update tests min version

* fix(#3036): fix test_registry_limit configs

* docu(#3036): fix min_version

* fix(#3036): CB registry_key_limit_full

* fix(#3036): fix test_file_limit_no_limit callback

* fix(#3036): add local_internal_options to tests

* fix(#3036): test_registry_key_full cb and key

* feat(#3053): add callbacks to fim.event_monitor

* feat(#3053): add fixtures to fim conftest

* feat(#3053): add test_sync_overlap test skeleton

* refactor(#3053): move CBs to fim.event_monitor

* fix(#3053): add new case to test_sync_overlap

* fix(#3053): fix truncate_monitored_files fixture

* feat(#3053): add create_files_in_folder fixture

* docu(#3053): fix test_sync_interval docu and style

* style(#3053): fix blank lines in conftest.py

* docu(#3053): update changelog.md

* style(#3053): fix spacing and indentations

* style(#3053): update spacing and indentation

* fix(#3053): fix config format to work on macOS

* fix(#3053): fix config format to work on macOS

* fix(#3053): update spacing in configuration

* fix(#3053): remove unnecesary list conversion

* refactor(#3036): move CB and import to modules.fim

* docs(#3036): add fixture documentation in tests

* fix(#3036): update config with correct values

* style(#3036): fix spacing in yaml conf files

* fix(#3036): fix config yaml spacing

* style(#3036): fix style and indentations

* fix(#3036): fix wazuh_conf.yaml spacing

* docs(#3036): update changelog.md

* fix(#3053): fix and add cases test_sync_overlap

* refactor(#3053): extract variables and callbacks

* docs(#3053): update changelog.md

* style(#3053): fix spacing

* fix(#3053): add monitored_dir parameter to test

* fix(#3053): fix invalid max_interval value test

* fix(#3036): increase test_max_eps created files

* docu(#3053): update event_monitor documentation

* docu(#3053): fix fim.event_monitor docu

* refactor(#3036): cleaned up callbacks

* style(#3036): removed trailing whitespace

* feat(#3053): add new callbacks

* feat(#3053): new test_sync_time module

* fix(#3053): remove unused callbacks

* docu(#3053): update test_sync_time docu

* style(#3053): fix test_sync_time spacing

* style(#3053): fix test_sync_time spacing

* docu(#3036): update chengelog.md

* docs(#3053): update tests documentation

* style(#3053): remove whitespaces

* docs(#3053): added comments and docu

* style(#3053): fixed indentation issue

* refactor(#1915): refactor fim framework

* fix(#1915): fix imports

* style(#1915): fix spacing and indentations

* fix(#1915): add missing fixture

* style(#1915): fix spacing in yaml files

* fix(#1915): fix callbacks and fixture import

* refactor(#1915): move callbacks to event_monitor

* refactor(#1915): update callback imports

* style(#1915): fix indentation and spacing

* feat(#1915):  update callbacks and functions

* refactor(#1915): update imports from fim framework

* fix(#1915): fix regular_file_cud function

* fix(#1915): fix delete_file usage instances

* fix(#1915): fix test_max_eps

* style(#1915): fix indentation and whitespaces

* fix(#1915): skip test_max_eps module

* fix(#1915): replace removed fixture

* fix(#1915): fix test_synchronize_integrity conf

* fix(#1915): fix test_restrict_valid scheduled mode

* style(#1915): fix test_restrict_valid conf spacing

* style(#1915): remove confs redundant quotes

* fix(#1915): fix test_restrict_valid cases

* fix(#1915): fix windows test cases

* chore: bump version to 4.6

* fix(#1915): revert merge  'master' into dev branch"

This reverts commit bbedbc9, reversing
changes made to 469828c.

* fix(#1915): remove duplicated fixture

* fix(#1915): add delay for difffolder deletion

* style(#1915): fix whitespaces and file names

* fix(#1915): remove redundant vars and functions

* style(#1915): improve documentation

* fix(#1915): extract duplicated function

* docs(#1915): improve documentation

* fix(#1915): remove unneeded file

* chore(#1915): remove unused imports

---------

Co-authored-by: Deblintrake09 <amicalizzi2005@gmail.com>
Co-authored-by: camila <camiromero100@gmail.com>
Co-authored-by: Cami Romero <37776796+CamiRomero@users.noreply.github.com>
Co-authored-by: jmv74211 <jmv74211@gmail.com>
* fix(#3592): extract callback to event_monitor

* fix(#3592): update test to new framework

* docs(#3592): update changelog

* style(#3592): fix whitespaces

* docs(#3592): update documentation date

* docs(#3592): update documentation and changelog
* fix(#3701): minor changes

* feat(#3701): add empty password tests for authd

* style(#3701): fix indents and unnecessary quotes

* feat(#3701): finish new authd tests

* docs(#3701): changelog updated

* revert(#3701): testfile refactor reverted

* docs(#3701): add fixture description

* feat(#3701): add new test case

* fix(#3701): spaces filled password case is now xfail

* fix(#3701): password declared directly in the yaml

* docs(#3701): comment improvement

Co-authored-by: Seyla Dámaris Gomez <seyla.gomez@wazuh.com>

* style(#3701): adapt test strucure

* docs(#3701): fix docstrings

* revert(#3701): remove yaml key validation inside test func

* fix(#3701): correct a typo and move constant to init

---------

Co-authored-by: Seyla Dámaris Gomez <seyla.gomez@wazuh.com>
* feat(#3835): add new module to support migration tool.

* feat(#3835): add function to remove the status file.

* refactor(#3835): rename module.

* fix(#3835): fix cve5 references and minor changes applied

* fix(#3835): apply linter corrections.

* refactor(#3835): change the way of running the tool.

* fix(#3835): minor changes applied.

* docs(#3835): change copyright message.

* fix(#3835): change name of variables.

* docs(#3835): improve utility function documentation.

* refactor(#3835): move function to file library and minor changes.

* fix(#3835): improve some code and add docs.

* fix(#3835): catch specific exceptions.

* fix(#3835): add platform and version specs.

* refactor(#3845): remove library

and remove MySQL credentials

* fix(#3835): fix attribute error.

* refactor(#3835): refactor library to adapt the tests.

* refactor(#3835): remove unused function.
@pro-akim pro-akim linked an issue Apr 13, 2023 that may be closed by this pull request
@juliamagan juliamagan self-requested a review April 17, 2023 10:07
@pro-akim pro-akim changed the title feat(3953): test_group_sync added feat(#3953): test_group_sync added Apr 18, 2023
@pro-akim pro-akim changed the title feat(#3953): test_group_sync added Wazuh manager-agent syncronization testing after group delete Apr 24, 2023
@pro-akim pro-akim changed the title Wazuh manager-agent syncronization testing after group delete Syncronization testing after group deleting Apr 24, 2023
wdb_query = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'script/wdb-query.py')

@pytest.fixture
def delete_logs():
Copy link
Member

Choose a reason for hiding this comment

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

Check if we can use clean_environment()

Copy link
Member Author

Choose a reason for hiding this comment

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

Checked and corrected in #4143

Comment on lines 68 to 83
@pytest.fixture
def group_creation():
delete_all_groups()
for group in groups:
response = host_manager.make_api_call(host=testinfra_hosts[0], token=host_manager.get_api_token(testinfra_hosts[0]), method='POST',
endpoint='/groups', request_body={'group_id': group})
assert response['status'] == 200, f"Failed to create {group} group: {response}"

@pytest.fixture
def agent_group_assignation():
agent_ids = host_manager.run_command(testinfra_hosts[0], f'cut -c 1-3 {WAZUH_PATH}/etc/client.keys').split()
for group in groups:
for agent_id in agent_ids:
response = host_manager.make_api_call(host=testinfra_hosts[0], token=host_manager.get_api_token(testinfra_hosts[0]), method='PUT',
endpoint=f'/agents/{agent_id}/group/{group}')
assert response['status'] == 200, f"Failed to assign agent {agent_id} in {group} group: {response}"
Copy link
Member

Choose a reason for hiding this comment

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

Check if we can use pre_configured_groups()

Copy link
Member Author

Choose a reason for hiding this comment

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

Checked and corrected in #4143

Comment on lines +85 to +89
@pytest.fixture
def delete_group_folder(test_case):
groups_created = host_manager.run_command(testinfra_hosts[0], f'{WAZUH_PATH}/bin/agent_groups')
if test_case['test_case']['group_deleted'] in groups_created:
host_manager.run_command(test_case['test_case']['host'], f"rm -r {WAZUH_PATH}/etc/shared/{test_case['test_case']['group_deleted']} -f")
Copy link
Member

Choose a reason for hiding this comment

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

Check if we can use delete_agent_groups()

Copy link
Member Author

Choose a reason for hiding this comment

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

Checked and corrected in #4143

Comment on lines 59 to 66
def delete_all_groups():
global groups_created
groups_created = host_manager.run_command(testinfra_hosts[0], f'{WAZUH_PATH}/bin/agent_groups')
for group in groups:
if group in groups_created:
response = host_manager.make_api_call(host=testinfra_hosts[0], token=host_manager.get_api_token(testinfra_hosts[0]), method='DELETE',
endpoint=f'/groups?groups_list={group}')
assert response['status'] == 200, f"Failed to delete {group} group: {response}"
Copy link
Member

Choose a reason for hiding this comment

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

Check if we can use delete_agent_groups()

Copy link
Member Author

Choose a reason for hiding this comment

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

Checked and corrected in #4143

Comment on lines 91 to 99
@pytest.fixture
def wdb_query_creator():
wdb = read_file(wdb_query)
host_manager.modify_file_content(host=testinfra_hosts[0], path=f'{WAZUH_PATH}/wdb-query.py',content=wdb)

def query_database():
query = 'global sql select group_sync_status from agent;'
response= host_manager.run_command(testinfra_hosts[0], f'python3 {WAZUH_PATH}/wdb-query.py "{query}"')
return response
Copy link
Member

Choose a reason for hiding this comment

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

Check if we can use execute_wdb_query()

Copy link
Member Author

Choose a reason for hiding this comment

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

Checked and corrected in #4143

Comment on lines 101 to 106
@pytest.fixture
def kill_initial_syncreq():
result = query_database()
while 'syncreq' in result:
time.sleep(1)
result = query_database()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@pytest.fixture
def kill_initial_syncreq():
result = query_database()
while 'syncreq' in result:
time.sleep(1)
result = query_database()
@pytest.fixture
def wait_end_initial_syncreq():
result = query_database()
while 'syncreq' in result:
time.sleep(1)
result = query_database()

Copy link
Member Author

Choose a reason for hiding this comment

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

Checked and corrected in #4143

Comment on lines 108 to 126
@pytest.fixture
def first_check():
global first_time_check
first_time_check = "synced"
s_time = 15
for i in range(s_time):
time.sleep(0.25)
result = query_database()
if 'syncreq' in result:
first_time_check = "syncreq"

@pytest.fixture
def second_check():
time.sleep(10)
global second_time_check
second_time_check = "synced"
result = query_database()
if 'syncreq' in result:
second_time_check = "syncreq"
Copy link
Member

Choose a reason for hiding this comment

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

This should be part of the test

Copy link
Member Author

Choose a reason for hiding this comment

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

Checked and corrected in #4143

Copy link
Member

@juliamagan juliamagan left a comment

Choose a reason for hiding this comment

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

  • The test is for 4.4.0, but the branch is master (4.6.0 at the moment)
  • Delete the script that is no longer used
  • Fix the checks
  • Files have been duplicated when changing directories

@pro-akim pro-akim changed the base branch from master to 4.4 April 25, 2023 11:35
@pro-akim
Copy link
Member Author

pro-akim commented Apr 27, 2023

Related issue
#3953

Description

Wazuh manager handles agent groups.
If a group is deleted from a master cluster, there will be an instance where the agents require resynchronization (syncreq).
If the group is deleted from a worker cluster, the cluster master will take care of reestablishing the group structure without the need for resynchronization.
This test suite tests the correct functioning of the mentioned use case.

Updated

-test_group_synnc delete_folder_master
-test_group_synnc delete_folder_worker1
-test_group_synnc delete_folder_worker2


Testing performed

Tester Test path Jenkins Local OS Commit Notes
@pro-akim (Developer) ⚫⚫⚫ 🟢🟢🟢 Nothing to highlight
@user (Reviewer) ⚫⚫⚫ ⚫⚫⚫ Nothing to highlight

@pro-akim pro-akim requested a review from juliamagan April 27, 2023 15:10
@pro-akim pro-akim changed the title Syncronization testing after group deleting Syncronization testing after group deletingv1 May 2, 2023
@pro-akim
Copy link
Member Author

pro-akim commented May 2, 2023

Corrected in #4143

@pro-akim pro-akim closed this May 3, 2023
@davidjiglesias davidjiglesias deleted the 3953-group_sync_status branch September 8, 2023 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add coverage to group_sync_status updated correctly on each node