From c9245eb77db244cda95dd17f8d30c7e402049e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Mag=C3=A1n?= Date: Tue, 17 Jan 2023 16:53:38 +0100 Subject: [PATCH 1/6] feat(#3764): add test_agent_database_version --- .../test_agent_database_version.py | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 tests/integration/test_wazuh_db/test_agent_database_version.py diff --git a/tests/integration/test_wazuh_db/test_agent_database_version.py b/tests/integration/test_wazuh_db/test_agent_database_version.py new file mode 100644 index 0000000000..ed48875014 --- /dev/null +++ b/tests/integration/test_wazuh_db/test_agent_database_version.py @@ -0,0 +1,105 @@ +''' +copyright: Copyright (C) 2015-2022, Wazuh Inc. + + Created by Wazuh, Inc. . + + This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 + +type: integration + +brief: Wazuh-db is the daemon in charge of the databases with all the Wazuh persistent information, exposing a socket + to receive requests and provide information. The Wazuh core uses list-based databases to store information + related to agent keys, and FIM/Rootcheck event data. + This test checks that the agent database version is the expected. + +tier: 0 + +modules: + - wazuh_db + +components: + - manager + +daemons: + - wazuh-db + +os_platform: + - linux + +os_version: + - Arch Linux + - Amazon Linux 2 + - Amazon Linux 1 + - CentOS 8 + - CentOS 7 + - CentOS 6 + - Ubuntu Focal + - Ubuntu Bionic + - Ubuntu Xenial + - Ubuntu Trusty + - Debian Buster + - Debian Stretch + - Debian Jessie + - Debian Wheezy + - Red Hat 8 + - Red Hat 7 + - Red Hat 6 + +references: + - https://documentation.wazuh.com/current/user-manual/reference/daemons/wazuh-db.html + +tags: + - wazuh_db +''' +import os +from time import sleep + +from wazuh_testing import DB_PATH, T_5 +from wazuh_testing.modules import TIER0, LINUX, SERVER +from wazuh_testing.db_interface import get_sqlite_query_result +from wazuh_testing.wazuh_db import query_wdb + +# Marks +pytestmark = [TIER0, LINUX, SERVER] + + +# Configurations + + + +# Variables + + + +# Fixtures + + +# Tests +def test_agent_database_version(): + ''' + description: Check that the agent database version is the expected one. To do this, it performs a query to the agent + database that gets the database version. + + wazuh_min_version: 4.4.0 + + parameters: + + assertions: + - Verify that database version is the expected one. + + input_description: + + expected_output: + - Database version: 10 + + tags: + - wazuh_db + - wdb_socket + ''' + version = get_sqlite_query_result(os.path.join(DB_PATH, '000.db'), + "SELECT value FROM metadata WHERE key='db_version'") + # Wait for wazuh-db to start and create the wdb socket + sleep(T_5) + version2 = query_wdb("agent 0 sql SELECT value FROM metadata WHERE key='db_version'") + + assert version[0] == version2[0]['value'] == '10' From 357a9a4887bbc0ebc55beb5af5c13952e7791e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Mag=C3=A1n?= Date: Wed, 18 Jan 2023 11:49:09 +0100 Subject: [PATCH 2/6] feat(#3764): add simulated agent --- .../test_agent_database_version.py | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/tests/integration/test_wazuh_db/test_agent_database_version.py b/tests/integration/test_wazuh_db/test_agent_database_version.py index ed48875014..ad4dceeedb 100644 --- a/tests/integration/test_wazuh_db/test_agent_database_version.py +++ b/tests/integration/test_wazuh_db/test_agent_database_version.py @@ -55,25 +55,15 @@ from time import sleep from wazuh_testing import DB_PATH, T_5 -from wazuh_testing.modules import TIER0, LINUX, SERVER from wazuh_testing.db_interface import get_sqlite_query_result +from wazuh_testing.modules import TIER0, LINUX, SERVER from wazuh_testing.wazuh_db import query_wdb +from wazuh_testing.tools.agent_simulator import create_agents, connect # Marks pytestmark = [TIER0, LINUX, SERVER] -# Configurations - - - -# Variables - - - -# Fixtures - - # Tests def test_agent_database_version(): ''' @@ -96,10 +86,16 @@ def test_agent_database_version(): - wazuh_db - wdb_socket ''' - version = get_sqlite_query_result(os.path.join(DB_PATH, '000.db'), - "SELECT value FROM metadata WHERE key='db_version'") + agents = create_agents(1, 'localhost') + connect(agents[0]) + + manager_version = get_sqlite_query_result(os.path.join(DB_PATH, '000.db'), + "SELECT value FROM metadata WHERE key='db_version'") + agent_version = get_sqlite_query_result(os.path.join(DB_PATH, f'{agents[0].id}.db'), + "SELECT value FROM metadata WHERE key='db_version'") # Wait for wazuh-db to start and create the wdb socket sleep(T_5) - version2 = query_wdb("agent 0 sql SELECT value FROM metadata WHERE key='db_version'") + manager_version2 = query_wdb("agent 0 sql SELECT value FROM metadata WHERE key='db_version'") + agent_version2 = query_wdb(f"agent {agents[0].id} sql SELECT value FROM metadata WHERE key='db_version'") - assert version[0] == version2[0]['value'] == '10' + assert manager_version[0] == manager_version2[0]['value'] == '10' == agent_version[0] == agent_version2[0]['value'] From ff1234745276d1392766bbebd0fde7ab252ce493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Mag=C3=A1n?= Date: Wed, 18 Jan 2023 13:00:30 +0100 Subject: [PATCH 3/6] fix(#3764): apply some improvements --- .../test_agent_database_version.py | 94 +++++-------------- 1 file changed, 21 insertions(+), 73 deletions(-) diff --git a/tests/integration/test_wazuh_db/test_agent_database_version.py b/tests/integration/test_wazuh_db/test_agent_database_version.py index ad4dceeedb..79de425498 100644 --- a/tests/integration/test_wazuh_db/test_agent_database_version.py +++ b/tests/integration/test_wazuh_db/test_agent_database_version.py @@ -1,84 +1,37 @@ -''' -copyright: Copyright (C) 2015-2022, Wazuh Inc. - - Created by Wazuh, Inc. . - - This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 - -type: integration - -brief: Wazuh-db is the daemon in charge of the databases with all the Wazuh persistent information, exposing a socket - to receive requests and provide information. The Wazuh core uses list-based databases to store information - related to agent keys, and FIM/Rootcheck event data. - This test checks that the agent database version is the expected. - -tier: 0 - -modules: - - wazuh_db - -components: - - manager - -daemons: - - wazuh-db - -os_platform: - - linux - -os_version: - - Arch Linux - - Amazon Linux 2 - - Amazon Linux 1 - - CentOS 8 - - CentOS 7 - - CentOS 6 - - Ubuntu Focal - - Ubuntu Bionic - - Ubuntu Xenial - - Ubuntu Trusty - - Debian Buster - - Debian Stretch - - Debian Jessie - - Debian Wheezy - - Red Hat 8 - - Red Hat 7 - - Red Hat 6 - -references: - - https://documentation.wazuh.com/current/user-manual/reference/daemons/wazuh-db.html - -tags: - - wazuh_db -''' -import os -from time import sleep - -from wazuh_testing import DB_PATH, T_5 -from wazuh_testing.db_interface import get_sqlite_query_result from wazuh_testing.modules import TIER0, LINUX, SERVER from wazuh_testing.wazuh_db import query_wdb -from wazuh_testing.tools.agent_simulator import create_agents, connect +from wazuh_testing.tools import agent_simulator as ag # Marks pytestmark = [TIER0, LINUX, SERVER] +# Variables +expected_database_version = '10' + # Tests -def test_agent_database_version(): +def test_agent_database_version(restart_wazuh_daemon): ''' description: Check that the agent database version is the expected one. To do this, it performs a query to the agent database that gets the database version. + test_phases: + - setup: + - Restart wazuh-manager service. + - test: + - Check that the manager database version is the expected one. + - Check that the agent database version is the expected one. + wazuh_min_version: 4.4.0 parameters: + - restart_wazuh_daemon: + type: fixture + brief: Restart the wazuh service. assertions: - Verify that database version is the expected one. - input_description: - expected_output: - Database version: 10 @@ -86,16 +39,11 @@ def test_agent_database_version(): - wazuh_db - wdb_socket ''' - agents = create_agents(1, 'localhost') - connect(agents[0]) + agents = ag.create_agents(1, 'localhost') + ag.connect(agents[0]) - manager_version = get_sqlite_query_result(os.path.join(DB_PATH, '000.db'), - "SELECT value FROM metadata WHERE key='db_version'") - agent_version = get_sqlite_query_result(os.path.join(DB_PATH, f'{agents[0].id}.db'), - "SELECT value FROM metadata WHERE key='db_version'") - # Wait for wazuh-db to start and create the wdb socket - sleep(T_5) - manager_version2 = query_wdb("agent 0 sql SELECT value FROM metadata WHERE key='db_version'") - agent_version2 = query_wdb(f"agent {agents[0].id} sql SELECT value FROM metadata WHERE key='db_version'") + manager_version = query_wdb("agent 0 sql SELECT value FROM metadata WHERE key='db_version'")[0]['value'] + agent_version = query_wdb(f"agent {agents[0].id} sql SELECT value FROM metadata WHERE key='db_version'")[0]['value'] - assert manager_version[0] == manager_version2[0]['value'] == '10' == agent_version[0] == agent_version2[0]['value'] + assert manager_version == expected_database_version + assert agent_version == expected_database_version From b80fc61c85c36f3d87e42f2c9a55e7fa0c9eb4e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Mag=C3=A1n?= Date: Wed, 18 Jan 2023 13:16:29 +0100 Subject: [PATCH 4/6] docs(#3764): add steps in test stage --- tests/integration/test_wazuh_db/test_agent_database_version.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/integration/test_wazuh_db/test_agent_database_version.py b/tests/integration/test_wazuh_db/test_agent_database_version.py index 79de425498..cf761153c8 100644 --- a/tests/integration/test_wazuh_db/test_agent_database_version.py +++ b/tests/integration/test_wazuh_db/test_agent_database_version.py @@ -19,6 +19,8 @@ def test_agent_database_version(restart_wazuh_daemon): - setup: - Restart wazuh-manager service. - test: + - Get the version of the manager database through the socket + - Get the version of the agent database through the socket - Check that the manager database version is the expected one. - Check that the agent database version is the expected one. From 67d10004b11eac40f7139d620194f440cd7966d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Mag=C3=A1n?= Date: Wed, 18 Jan 2023 14:14:22 +0100 Subject: [PATCH 5/6] fix(#3764): add error message --- .../test_wazuh_db/test_agent_database_version.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_wazuh_db/test_agent_database_version.py b/tests/integration/test_wazuh_db/test_agent_database_version.py index cf761153c8..3b592efafa 100644 --- a/tests/integration/test_wazuh_db/test_agent_database_version.py +++ b/tests/integration/test_wazuh_db/test_agent_database_version.py @@ -47,5 +47,9 @@ def test_agent_database_version(restart_wazuh_daemon): manager_version = query_wdb("agent 0 sql SELECT value FROM metadata WHERE key='db_version'")[0]['value'] agent_version = query_wdb(f"agent {agents[0].id} sql SELECT value FROM metadata WHERE key='db_version'")[0]['value'] - assert manager_version == expected_database_version - assert agent_version == expected_database_version + assert manager_version == expected_database_version, 'The manager database version is not the expected one. \n' \ + f'Expected version: {expected_database_version}\n'\ + f'Obtained version: {manager_version}' + assert agent_version == expected_database_version, 'The agent database version is not the expected one. \n' \ + f'Expected version: {expected_database_version}\n'\ + f'Obtained version: {agent_version}' From 4dc3dee7322ef104cb1ab9811fa102a2e35a99ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Mag=C3=A1n?= Date: Wed, 18 Jan 2023 14:19:00 +0100 Subject: [PATCH 6/6] feat(#3764): update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d706222323..882775521c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Release report: TBD ### Added +- Add integration test to check agent database version ([#3768](https://github.com/wazuh/wazuh-qa/pull/3768)) \- (Tests) - Fix Yara and VirusTotal E2E basic usage tests ([#3660](https://github.com/wazuh/wazuh-qa/pull/3660)) - Add new test to check if syslog message are parsed correctrly in the `archives.json` file ([#3609](https://github.com/wazuh/wazuh-qa/pull/3609)) \- (Framework + Tests) - Add new logging tests for analysisd EPS limitation ([#3509](https://github.com/wazuh/wazuh-qa/pull/3509)) \- (Framework + Tests)