From 5d2c1cb3a799bb43962efdcc5c6186c8f6772046 Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 20 Dec 2021 13:32:32 +0100 Subject: [PATCH 01/17] add: Add new test_queue_socket_status first approach #1850 --- .../test_queue_socket_status.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/integration/test_analysisd/test_queue_socket_status/test_queue_socket_status.py diff --git a/tests/integration/test_analysisd/test_queue_socket_status/test_queue_socket_status.py b/tests/integration/test_analysisd/test_queue_socket_status/test_queue_socket_status.py new file mode 100644 index 0000000000..ac3daac5f8 --- /dev/null +++ b/tests/integration/test_analysisd/test_queue_socket_status/test_queue_socket_status.py @@ -0,0 +1,35 @@ +import os +import pytest +import subprocess + +from wazuh_testing.tools import WAZUH_PATH + + +# Marks +pytestmark = [pytest.mark.linux, pytest.mark.tier(level=0), pytest.mark.server] + +# variables + +ANALYSISD_SOCKET = os.path.join(WAZUH_PATH, 'queue', 'sockets', 'queue') +analysisd_path = os.path.join(WAZUH_PATH,'bin', 'wazuh-analysisd') +command_exec = f'{analysisd_path} -t' + + + +def test_queue_socket_status(): + current_inode_file = os.stat(ANALYSISD_SOCKET).st_ino + current_status_time = os.path.getmtime(ANALYSISD_SOCKET) + + # Updating Analysisd + run = subprocess.Popen(['/bin/bash', '-c', command_exec]) + run.communicate() + + try: + assert current_inode_file == os.stat(ANALYSISD_SOCKET).st_ino + except AssertionError: + raise AssertionError(f'The Inode value for the socket {ANALYSISD_SOCKET} has changed') + + try: + assert current_status_time == os.path.getmtime(ANALYSISD_SOCKET) + except AssertionError: + raise AssertionError(f'The Filetime value for the socket {ANALYSISD_SOCKET} has changed') From d19996a6eb6e55d687696b90582bd09e2b5abab0 Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 21 Dec 2021 14:00:41 +0100 Subject: [PATCH 02/17] add: Added stopping and restarting analysisd daemon implementation #1850 --- .../test_queue_socket_status.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_analysisd/test_queue_socket_status/test_queue_socket_status.py b/tests/integration/test_analysisd/test_queue_socket_status/test_queue_socket_status.py index ac3daac5f8..4a73792a05 100644 --- a/tests/integration/test_analysisd/test_queue_socket_status/test_queue_socket_status.py +++ b/tests/integration/test_analysisd/test_queue_socket_status/test_queue_socket_status.py @@ -3,6 +3,8 @@ import subprocess from wazuh_testing.tools import WAZUH_PATH +from wazuh_testing.tools.services import control_service, check_daemon_status + # Marks @@ -15,11 +17,21 @@ command_exec = f'{analysisd_path} -t' - def test_queue_socket_status(): + + # Check if analysisd daemon is running + check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd') + current_inode_file = os.stat(ANALYSISD_SOCKET).st_ino current_status_time = os.path.getmtime(ANALYSISD_SOCKET) + # Stop analysisd daemon + control_service('stop', daemon='wazuh-analysisd') + check_daemon_status(running_condition=False, target_daemon='wazuh-analysisd') + + control_service('start', daemon='wazuh-analysisd') + + # Updating Analysisd run = subprocess.Popen(['/bin/bash', '-c', command_exec]) run.communicate() From f3b7af715e887f0f8e28cfb7e5d07a64ab8b9d18 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 22 Dec 2021 11:27:36 +0100 Subject: [PATCH 03/17] refac: Changed test name #1850 --- .../test_queue_socket_properties.py} | 41 ++++++++----------- 1 file changed, 17 insertions(+), 24 deletions(-) rename tests/integration/test_analysisd/{test_queue_socket_status/test_queue_socket_status.py => test_queue_socket_properties/test_queue_socket_properties.py} (52%) diff --git a/tests/integration/test_analysisd/test_queue_socket_status/test_queue_socket_status.py b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py similarity index 52% rename from tests/integration/test_analysisd/test_queue_socket_status/test_queue_socket_status.py rename to tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py index 4a73792a05..ec3c8fd422 100644 --- a/tests/integration/test_analysisd/test_queue_socket_status/test_queue_socket_status.py +++ b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py @@ -5,43 +5,36 @@ from wazuh_testing.tools import WAZUH_PATH from wazuh_testing.tools.services import control_service, check_daemon_status - - # Marks pytestmark = [pytest.mark.linux, pytest.mark.tier(level=0), pytest.mark.server] # variables - ANALYSISD_SOCKET = os.path.join(WAZUH_PATH, 'queue', 'sockets', 'queue') analysisd_path = os.path.join(WAZUH_PATH,'bin', 'wazuh-analysisd') command_exec = f'{analysisd_path} -t' +# Fixture +def configure_analysisd_queue_socket(): + # restart analysisd daemon + control_service('restart', daemon='wazuh-analysisd') + check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd') -def test_queue_socket_status(): - + # Updating Analysisd + run = subprocess.Popen(['/bin/bash', '-c', command_exec]) + run.communicate() + +def test_queue_socket_properties(): # Check if analysisd daemon is running - check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd') + if check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd') is not True: + control_service('start', daemon='wazuh-analysisd') current_inode_file = os.stat(ANALYSISD_SOCKET).st_ino current_status_time = os.path.getmtime(ANALYSISD_SOCKET) - # Stop analysisd daemon - control_service('stop', daemon='wazuh-analysisd') - check_daemon_status(running_condition=False, target_daemon='wazuh-analysisd') - - control_service('start', daemon='wazuh-analysisd') + configure_analysisd_queue_socket() + assert current_inode_file == os.stat(ANALYSISD_SOCKET).st_ino, \ + f"The Inode value for the socket {ANALYSISD_SOCKET} has changed" - # Updating Analysisd - run = subprocess.Popen(['/bin/bash', '-c', command_exec]) - run.communicate() - - try: - assert current_inode_file == os.stat(ANALYSISD_SOCKET).st_ino - except AssertionError: - raise AssertionError(f'The Inode value for the socket {ANALYSISD_SOCKET} has changed') - - try: - assert current_status_time == os.path.getmtime(ANALYSISD_SOCKET) - except AssertionError: - raise AssertionError(f'The Filetime value for the socket {ANALYSISD_SOCKET} has changed') + assert current_status_time == os.path.getmtime(ANALYSISD_SOCKET), \ + f"The Filetime value for the socket {ANALYSISD_SOCKET} has changed" \ No newline at end of file From edd005538c2c7edf2fcc0fb0dfad334f37d6bea2 Mon Sep 17 00:00:00 2001 From: Fernando Date: Thu, 23 Dec 2021 13:27:35 +0100 Subject: [PATCH 04/17] add: Added new fixtures implementation #1850 --- .../test_queue_socket_properties.py | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py index ec3c8fd422..9bcc435bcb 100644 --- a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py +++ b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py @@ -6,35 +6,42 @@ from wazuh_testing.tools.services import control_service, check_daemon_status # Marks + pytestmark = [pytest.mark.linux, pytest.mark.tier(level=0), pytest.mark.server] # variables + ANALYSISD_SOCKET = os.path.join(WAZUH_PATH, 'queue', 'sockets', 'queue') analysisd_path = os.path.join(WAZUH_PATH,'bin', 'wazuh-analysisd') command_exec = f'{analysisd_path} -t' -# Fixture -def configure_analysisd_queue_socket(): +# Fixtures + +@pytest.fixture(scope="function") +def socket_file_properties(): + return os.stat(ANALYSISD_SOCKET).st_ino, os.path.getmtime(ANALYSISD_SOCKET) + +@pytest.fixture(scope="function") +def run_analysisd_test_config(): # restart analysisd daemon control_service('restart', daemon='wazuh-analysisd') check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd') - # Updating Analysisd + # run analysisd test configuration mode run = subprocess.Popen(['/bin/bash', '-c', command_exec]) run.communicate() -def test_queue_socket_properties(): + +def test_queue_socket_properties(socket_file_properties, run_analysisd_test_config): # Check if analysisd daemon is running - if check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd') is not True: - control_service('start', daemon='wazuh-analysisd') + check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd') - current_inode_file = os.stat(ANALYSISD_SOCKET).st_ino - current_status_time = os.path.getmtime(ANALYSISD_SOCKET) + current_inode_file, current_status_time = socket_file_properties - configure_analysisd_queue_socket() + run_analysisd_test_config assert current_inode_file == os.stat(ANALYSISD_SOCKET).st_ino, \ f"The Inode value for the socket {ANALYSISD_SOCKET} has changed" assert current_status_time == os.path.getmtime(ANALYSISD_SOCKET), \ - f"The Filetime value for the socket {ANALYSISD_SOCKET} has changed" \ No newline at end of file + f"The Filetime value for the socket {ANALYSISD_SOCKET} has changed" From 52bdeb03cc802d4e4f66a5e411fcfc16302defca Mon Sep 17 00:00:00 2001 From: Fernando Date: Fri, 24 Dec 2021 10:04:44 +0100 Subject: [PATCH 05/17] doc: Documented test_queue_socket_properties #1850 --- .../test_queue_socket_properties.py | 87 ++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py index 9bcc435bcb..62c098f384 100644 --- a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py +++ b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py @@ -1,3 +1,56 @@ +''' +copyright: Copyright (C) 2015-2021, 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: The 'wazuh-analysisd' daemon refreshes the queue socket file every time the daemon is set to + the testing configuration. + Specifically, this test will check if after setting up the 'wazuh-analysisd' daemon to the + testing configuration the Inode and Filetime properties of the queue socket are changed. + +tier: 0 + +modules: + - analysisd + +components: + - manager + +daemons: + - wazuh-analysisd + +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-analysisd.html + +tags: + - analysisd +''' import os import pytest import subprocess @@ -19,10 +72,12 @@ @pytest.fixture(scope="function") def socket_file_properties(): + """Get the Inode and File time value of the 'queue' socket of 'wazuh-analysisd'""" return os.stat(ANALYSISD_SOCKET).st_ino, os.path.getmtime(ANALYSISD_SOCKET) @pytest.fixture(scope="function") def run_analysisd_test_config(): + """Run the test configuration mode for the 'wazuh-analysisd' daemon""" # restart analysisd daemon control_service('restart', daemon='wazuh-analysisd') check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd') @@ -33,6 +88,36 @@ def run_analysisd_test_config(): def test_queue_socket_properties(socket_file_properties, run_analysisd_test_config): + ''' + description: Check if when the 'wazuh-analysisd' daemon is set up to the testing configuration, the Inode value + and the File time value of the 'queue' socket are modified. + + wazuh_min_version: 4.2.0 + + parameters: + - socket_file_properties: + type: fixture + brief: Obtain the current properties of the 'queue' socket. + - run_analysisd_test_config: + type: fixture + brief: Change the wazuh-analysisd daemon configuration into the testing configuration mode. + + + assertions: + - Verify that the Inode value of the socket file does not change its value after analysisd gets the + testing configuration set up. + - Verify that the File time value of the socket file does not change its value after analysisd + gets the testing configuration set up. + + input_description: The test gets the current properties of the socket file and some configutation parameters + to configure the 'wazuh-analysisd' daemon. + + expected_output: + - f"The Inode value for the socket {ANALYSISD_SOCKET} has changed" + - f"The Filetime value for the socket {ANALYSISD_SOCKET} has changed" + tags: + - errors + ''' # Check if analysisd daemon is running check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd') @@ -44,4 +129,4 @@ def test_queue_socket_properties(socket_file_properties, run_analysisd_test_conf f"The Inode value for the socket {ANALYSISD_SOCKET} has changed" assert current_status_time == os.path.getmtime(ANALYSISD_SOCKET), \ - f"The Filetime value for the socket {ANALYSISD_SOCKET} has changed" + f"The File time value for the socket {ANALYSISD_SOCKET} has changed" From 4a46c7768d325032ff71b4f5fac862a6b38e7316 Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 28 Dec 2021 10:15:58 +0100 Subject: [PATCH 06/17] add: Add documentation's requested changes #1850 --- .../test_queue_socket_properties.py | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py index 62c098f384..3fa271b66c 100644 --- a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py +++ b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py @@ -7,10 +7,9 @@ type: integration -brief: The 'wazuh-analysisd' daemon refreshes the queue socket file every time the daemon is set to - the testing configuration. - Specifically, this test will check if after setting up the 'wazuh-analysisd' daemon to the - testing configuration the Inode and Filetime properties of the queue socket are changed. +brief: The 'wazuh-analysisd' daemon refreshes the queue socket file every time the testing configuration is executed + Specifically, this test will check if after running the configuration test of 'wazuh-analysisd' the properties + of the queue socket file are changed. tier: 0 @@ -72,12 +71,12 @@ @pytest.fixture(scope="function") def socket_file_properties(): - """Get the Inode and File time value of the 'queue' socket of 'wazuh-analysisd'""" + """Get the inode and modification time values of the 'queue' socket of 'wazuh-analysisd'""" return os.stat(ANALYSISD_SOCKET).st_ino, os.path.getmtime(ANALYSISD_SOCKET) @pytest.fixture(scope="function") def run_analysisd_test_config(): - """Run the test configuration mode for the 'wazuh-analysisd' daemon""" + """Run the daemon configuration test mode of 'wazuh-analysisd'""" # restart analysisd daemon control_service('restart', daemon='wazuh-analysisd') check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd') @@ -89,8 +88,8 @@ def run_analysisd_test_config(): def test_queue_socket_properties(socket_file_properties, run_analysisd_test_config): ''' - description: Check if when the 'wazuh-analysisd' daemon is set up to the testing configuration, the Inode value - and the File time value of the 'queue' socket are modified. + description: check if after running the configuration test of 'wazuh-analysisd' the properties + of the queue socket file are changed. wazuh_min_version: 4.2.0 @@ -100,21 +99,21 @@ def test_queue_socket_properties(socket_file_properties, run_analysisd_test_conf brief: Obtain the current properties of the 'queue' socket. - run_analysisd_test_config: type: fixture - brief: Change the wazuh-analysisd daemon configuration into the testing configuration mode. + brief: Run the daemon configuration test mode of 'wazuh-analysisd' assertions: - - Verify that the Inode value of the socket file does not change its value after analysisd gets the - testing configuration set up. - - Verify that the File time value of the socket file does not change its value after analysisd - gets the testing configuration set up. + - Verify that the Inode value of the socket file does not change its value after running the + configuration test of 'wazuh-analysisd' + - Verify that the File time value of the socket file does not change its value after running the + configuration test of 'wazuh-analysisd' - input_description: The test gets the current properties of the socket file and some configutation parameters - to configure the 'wazuh-analysisd' daemon. + input_description: The test gets the current properties of the socket file and some parameters + to run the daemon configuration test of 'wazuh-analysisd'. expected_output: - - f"The Inode value for the socket {ANALYSISD_SOCKET} has changed" - - f"The Filetime value for the socket {ANALYSISD_SOCKET} has changed" + - f"The inode value for the socket {ANALYSISD_SOCKET} has changed" + - f"The modification time property for the socket {ANALYSISD_SOCKET} has changed" tags: - errors ''' @@ -126,7 +125,7 @@ def test_queue_socket_properties(socket_file_properties, run_analysisd_test_conf run_analysisd_test_config assert current_inode_file == os.stat(ANALYSISD_SOCKET).st_ino, \ - f"The Inode value for the socket {ANALYSISD_SOCKET} has changed" + f"The inode value for the socket {ANALYSISD_SOCKET} has changed" assert current_status_time == os.path.getmtime(ANALYSISD_SOCKET), \ - f"The File time value for the socket {ANALYSISD_SOCKET} has changed" + f"The modification time property value for the socket {ANALYSISD_SOCKET} has changed" From 23955d5ab6dbf6c42389482c2a5266882b133f25 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 29 Dec 2021 12:46:39 +0100 Subject: [PATCH 07/17] add: Add new documentation's requested changes #1850 --- .../test_queue_socket_properties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py index 3fa271b66c..9c50fc0d4a 100644 --- a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py +++ b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py @@ -7,7 +7,7 @@ type: integration -brief: The 'wazuh-analysisd' daemon refreshes the queue socket file every time the testing configuration is executed +brief: The 'wazuh-analysisd' daemon refreshes the queue socket file every time the test configuration is executed Specifically, this test will check if after running the configuration test of 'wazuh-analysisd' the properties of the queue socket file are changed. From e1f487f46207a25a49e4442932aa9ec9e2b972b9 Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 3 Jan 2022 09:48:57 +0100 Subject: [PATCH 08/17] doc: Add new requested documentation's changes #1850 --- .../test_queue_socket_properties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py index 9c50fc0d4a..5e3c17c1f7 100644 --- a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py +++ b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py @@ -7,7 +7,7 @@ type: integration -brief: The 'wazuh-analysisd' daemon refreshes the queue socket file every time the test configuration is executed +brief: The 'wazuh-analysisd' daemon refreshes the queue socket file every time the configuration test is executed Specifically, this test will check if after running the configuration test of 'wazuh-analysisd' the properties of the queue socket file are changed. From 79ce42e03436c8f73a137ae06f6346fbb5487814 Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 18 Jan 2022 10:05:20 +0100 Subject: [PATCH 09/17] fix: fix style with pep8 style guide #1850 --- .../test_queue_socket_properties.py | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py index 5e3c17c1f7..a25283c054 100644 --- a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py +++ b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py @@ -8,7 +8,7 @@ type: integration brief: The 'wazuh-analysisd' daemon refreshes the queue socket file every time the configuration test is executed - Specifically, this test will check if after running the configuration test of 'wazuh-analysisd' the properties + Specifically, this test will check if after running the configuration test of 'wazuh-analysisd' the properties of the queue socket file are changed. tier: 0 @@ -61,34 +61,36 @@ pytestmark = [pytest.mark.linux, pytest.mark.tier(level=0), pytest.mark.server] -# variables +# Variables ANALYSISD_SOCKET = os.path.join(WAZUH_PATH, 'queue', 'sockets', 'queue') -analysisd_path = os.path.join(WAZUH_PATH,'bin', 'wazuh-analysisd') +analysisd_path = os.path.join(WAZUH_PATH, 'bin', 'wazuh-analysisd') command_exec = f'{analysisd_path} -t' # Fixtures + @pytest.fixture(scope="function") def socket_file_properties(): """Get the inode and modification time values of the 'queue' socket of 'wazuh-analysisd'""" return os.stat(ANALYSISD_SOCKET).st_ino, os.path.getmtime(ANALYSISD_SOCKET) + @pytest.fixture(scope="function") def run_analysisd_test_config(): """Run the daemon configuration test mode of 'wazuh-analysisd'""" - # restart analysisd daemon + # restart analysisd daemon control_service('restart', daemon='wazuh-analysisd') check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd') # run analysisd test configuration mode run = subprocess.Popen(['/bin/bash', '-c', command_exec]) run.communicate() - + def test_queue_socket_properties(socket_file_properties, run_analysisd_test_config): ''' - description: check if after running the configuration test of 'wazuh-analysisd' the properties + description: check if after running the configuration test of 'wazuh-analysisd' the properties of the queue socket file are changed. wazuh_min_version: 4.2.0 @@ -100,14 +102,14 @@ def test_queue_socket_properties(socket_file_properties, run_analysisd_test_conf - run_analysisd_test_config: type: fixture brief: Run the daemon configuration test mode of 'wazuh-analysisd' - + assertions: - Verify that the Inode value of the socket file does not change its value after running the configuration test of 'wazuh-analysisd' - Verify that the File time value of the socket file does not change its value after running the configuration test of 'wazuh-analysisd' - + input_description: The test gets the current properties of the socket file and some parameters to run the daemon configuration test of 'wazuh-analysisd'. @@ -117,7 +119,7 @@ def test_queue_socket_properties(socket_file_properties, run_analysisd_test_conf tags: - errors ''' - # Check if analysisd daemon is running + # Check if analysisd daemon is running check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd') current_inode_file, current_status_time = socket_file_properties @@ -125,7 +127,7 @@ def test_queue_socket_properties(socket_file_properties, run_analysisd_test_conf run_analysisd_test_config assert current_inode_file == os.stat(ANALYSISD_SOCKET).st_ino, \ - f"The inode value for the socket {ANALYSISD_SOCKET} has changed" + f"The inode value for the socket {ANALYSISD_SOCKET} has changed" assert current_status_time == os.path.getmtime(ANALYSISD_SOCKET), \ - f"The modification time property value for the socket {ANALYSISD_SOCKET} has changed" + f"The modification time property value for the socket {ANALYSISD_SOCKET} has changed" From f0da290be72f303d2b2f2fdc64277dc52a6f05b7 Mon Sep 17 00:00:00 2001 From: mauromalara Date: Mon, 31 Jan 2022 10:19:14 -0300 Subject: [PATCH 10/17] refac: Some variables extracted from the QA framework. #1850 --- .../test_queue_socket_properties.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py index a25283c054..de657c398f 100644 --- a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py +++ b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py @@ -54,7 +54,7 @@ import pytest import subprocess -from wazuh_testing.tools import WAZUH_PATH +from wazuh_testing.tools import WAZUH_PATH, ANALYSISD_QUEUE_SOCKET_PATH, ANALYSISD_DAEMON from wazuh_testing.tools.services import control_service, check_daemon_status # Marks @@ -63,8 +63,7 @@ # Variables -ANALYSISD_SOCKET = os.path.join(WAZUH_PATH, 'queue', 'sockets', 'queue') -analysisd_path = os.path.join(WAZUH_PATH, 'bin', 'wazuh-analysisd') +analysisd_path = os.path.join(WAZUH_PATH, 'bin', ANALYSISD_DAEMON) command_exec = f'{analysisd_path} -t' # Fixtures @@ -73,7 +72,7 @@ @pytest.fixture(scope="function") def socket_file_properties(): """Get the inode and modification time values of the 'queue' socket of 'wazuh-analysisd'""" - return os.stat(ANALYSISD_SOCKET).st_ino, os.path.getmtime(ANALYSISD_SOCKET) + return os.stat(ANALYSISD_QUEUE_SOCKET_PATH).st_ino, os.path.getmtime(ANALYSISD_QUEUE_SOCKET_PATH) @pytest.fixture(scope="function") @@ -114,8 +113,8 @@ def test_queue_socket_properties(socket_file_properties, run_analysisd_test_conf to run the daemon configuration test of 'wazuh-analysisd'. expected_output: - - f"The inode value for the socket {ANALYSISD_SOCKET} has changed" - - f"The modification time property for the socket {ANALYSISD_SOCKET} has changed" + - f"The inode value for the socket {ANALYSISD_QUEUE_SOCKET_PATH} has changed" + - f"The modification time property for the socket {ANALYSISD_QUEUE_SOCKET_PATH} has changed" tags: - errors ''' @@ -126,8 +125,8 @@ def test_queue_socket_properties(socket_file_properties, run_analysisd_test_conf run_analysisd_test_config - assert current_inode_file == os.stat(ANALYSISD_SOCKET).st_ino, \ - f"The inode value for the socket {ANALYSISD_SOCKET} has changed" + assert current_inode_file == os.stat(ANALYSISD_QUEUE_SOCKET_PATH).st_ino, \ + f"The inode value for the socket {ANALYSISD_QUEUE_SOCKET_PATH} has changed" - assert current_status_time == os.path.getmtime(ANALYSISD_SOCKET), \ - f"The modification time property value for the socket {ANALYSISD_SOCKET} has changed" + assert current_status_time == os.path.getmtime(ANALYSISD_QUEUE_SOCKET_PATH), \ + f"The modification time property value for the socket {ANALYSISD_QUEUE_SOCKET_PATH} has changed" From c46a84f77e4ec69ffd53b87c7947ed073bcc8e6c Mon Sep 17 00:00:00 2001 From: mauromalara Date: Wed, 2 Feb 2022 14:23:27 -0300 Subject: [PATCH 11/17] doc: wazuh_min_version changed --- .../test_queue_socket_properties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py index de657c398f..a9e7c48d89 100644 --- a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py +++ b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py @@ -92,7 +92,7 @@ def test_queue_socket_properties(socket_file_properties, run_analysisd_test_conf description: check if after running the configuration test of 'wazuh-analysisd' the properties of the queue socket file are changed. - wazuh_min_version: 4.2.0 + wazuh_min_version: 4.2.2 parameters: - socket_file_properties: From 31d70d50aa25cf2b434ea6f2a81fb20a08e4eec3 Mon Sep 17 00:00:00 2001 From: mauromalara Date: Wed, 2 Feb 2022 14:33:24 -0300 Subject: [PATCH 12/17] doc: CHANGELOG.md updated. #1850 --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a37595b484..b2d2454d2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file. ## [v4.3.0] ### Added +- Add test fim with file currently open ([#2300](https://github.com/wazuh/wazuh-qa/pull/2300)) +- Test manager sends AR log format as expected ([#2347](https://github.com/wazuh/wazuh-qa/pull/2347)) +- Syscollector deltas IT ([#2146](https://github.com/wazuh/wazuh-qa/pull/2146)) +- CVEs alerts inventory for Vulnerability Detector - VDT and WDB Integration Tests implementation ([#1243](https://github.com/wazuh/wazuh-qa/pull/1243)) +- Analysisd - add new test to check the pre-decoding stage of analysisd ([#2406](https://github.com/wazuh/wazuh-qa/pull/2406)) +- Add test to check if files can be accessed while FIM has them opened ([#705](https://github.com/wazuh/wazuh-qa/pull/705)) +- Analysisd - add new test to check analysisd socket properties ([#2405](https://github.com/wazuh/wazuh-qa/pull/2405)) ### Changed From 3cf67fc37d1040484253665e3387856d8936bfb0 Mon Sep 17 00:00:00 2001 From: Juan Nicolas Asselle Date: Fri, 4 Feb 2022 20:27:50 +0000 Subject: [PATCH 13/17] Fixtures rearrangement to test unmodified socket --- .../test_queue_socket_properties.py | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py index a9e7c48d89..242c40a9df 100644 --- a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py +++ b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py @@ -76,18 +76,26 @@ def socket_file_properties(): @pytest.fixture(scope="function") -def run_analysisd_test_config(): - """Run the daemon configuration test mode of 'wazuh-analysisd'""" +def restart_analysisd(): + """Restart and wait 'wazuh-analysisd' startup""" # restart analysisd daemon control_service('restart', daemon='wazuh-analysisd') check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd') - # run analysisd test configuration mode + +@pytest.fixture(scope="function") +def run_analysisd_test_config(): + """Run the daemon configuration test mode of 'wazuh-analysisd'""" run = subprocess.Popen(['/bin/bash', '-c', command_exec]) run.communicate() -def test_queue_socket_properties(socket_file_properties, run_analysisd_test_config): +before_socket_properties = socket_file_properties +after_socket_properties = socket_file_properties + + +def test_queue_socket_properties(restart_analysisd, before_socket_properties, run_analysisd_test_config, + after_socket_properties): ''' description: check if after running the configuration test of 'wazuh-analysisd' the properties of the queue socket file are changed. @@ -95,13 +103,18 @@ def test_queue_socket_properties(socket_file_properties, run_analysisd_test_conf wazuh_min_version: 4.2.2 parameters: - - socket_file_properties: + - restart_analysisd: + type: fixture + brief: Restart wazuh-analyisd. + - before_socket_properties: type: fixture - brief: Obtain the current properties of the 'queue' socket. + brief: Obtain the previous properties of the 'queue' socket. - run_analysisd_test_config: type: fixture brief: Run the daemon configuration test mode of 'wazuh-analysisd' - + - after_socket_properties: + type: fixture + brief: Obtain the later properties of the 'queue' socket. assertions: - Verify that the Inode value of the socket file does not change its value after running the @@ -118,15 +131,11 @@ def test_queue_socket_properties(socket_file_properties, run_analysisd_test_conf tags: - errors ''' - # Check if analysisd daemon is running - check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd') - - current_inode_file, current_status_time = socket_file_properties - - run_analysisd_test_config + before_inode_file, before_status_time = before_socket_properties + after_inode_file, after_status_time = after_socket_properties - assert current_inode_file == os.stat(ANALYSISD_QUEUE_SOCKET_PATH).st_ino, \ + assert before_inode_file == after_inode_file, \ f"The inode value for the socket {ANALYSISD_QUEUE_SOCKET_PATH} has changed" - assert current_status_time == os.path.getmtime(ANALYSISD_QUEUE_SOCKET_PATH), \ + assert before_status_time == after_status_time, \ f"The modification time property value for the socket {ANALYSISD_QUEUE_SOCKET_PATH} has changed" From 509513365c12cbc3c9a0b160152fa98d204dbd35 Mon Sep 17 00:00:00 2001 From: mauromalara Date: Mon, 21 Feb 2022 16:58:29 -0300 Subject: [PATCH 14/17] doc: parameter brief changed. #1850 --- .../test_queue_socket_properties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py index 242c40a9df..c772d7bd27 100644 --- a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py +++ b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py @@ -105,7 +105,7 @@ def test_queue_socket_properties(restart_analysisd, before_socket_properties, ru parameters: - restart_analysisd: type: fixture - brief: Restart wazuh-analyisd. + brief: Restart wazuh-analysisd. - before_socket_properties: type: fixture brief: Obtain the previous properties of the 'queue' socket. From effa132e70e66fdc8e173d7ea39a94a3e8e29c1d Mon Sep 17 00:00:00 2001 From: mauromalara Date: Mon, 21 Feb 2022 17:07:20 -0300 Subject: [PATCH 15/17] doc: tag changed. #1850 --- .../test_queue_socket_properties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py index c772d7bd27..51bad1a2fa 100644 --- a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py +++ b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py @@ -129,7 +129,7 @@ def test_queue_socket_properties(restart_analysisd, before_socket_properties, ru - f"The inode value for the socket {ANALYSISD_QUEUE_SOCKET_PATH} has changed" - f"The modification time property for the socket {ANALYSISD_QUEUE_SOCKET_PATH} has changed" tags: - - errors + - analysisd ''' before_inode_file, before_status_time = before_socket_properties after_inode_file, after_status_time = after_socket_properties From b464f1493244f31f807bfc89c1b0de4183c289b4 Mon Sep 17 00:00:00 2001 From: mauromalara Date: Mon, 21 Feb 2022 17:16:07 -0300 Subject: [PATCH 16/17] doc: min version corrected. #1850 --- .../test_queue_socket_properties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py index 51bad1a2fa..f555bef780 100644 --- a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py +++ b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py @@ -100,7 +100,7 @@ def test_queue_socket_properties(restart_analysisd, before_socket_properties, ru description: check if after running the configuration test of 'wazuh-analysisd' the properties of the queue socket file are changed. - wazuh_min_version: 4.2.2 + wazuh_min_version: 4.3.0 parameters: - restart_analysisd: From 179fd42ccd8403d59339fba86354c2cba87c2021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo?= Date: Thu, 17 Mar 2022 11:19:42 +0000 Subject: [PATCH 17/17] fix: recover mauromalara last improvements in the framework and test_queue_socket_properties Co-authored-by: mauromalara --- CHANGELOG.md | 8 +------ .../wazuh_testing/tools/__init__.py | 2 ++ tests/integration/test_analysisd/conftest.py | 15 +++++------- .../test_queue_socket_properties.py | 24 +++++-------------- 4 files changed, 15 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 182e6396a9..fbcd0b25d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,13 +8,6 @@ Wazuh commit: TBD \ Release report: TBD ### Added -- Add test fim with file currently open ([#2300](https://github.com/wazuh/wazuh-qa/pull/2300)) -- Test manager sends AR log format as expected ([#2347](https://github.com/wazuh/wazuh-qa/pull/2347)) -- Syscollector deltas IT ([#2146](https://github.com/wazuh/wazuh-qa/pull/2146)) -- CVEs alerts inventory for Vulnerability Detector - VDT and WDB Integration Tests implementation ([#1243](https://github.com/wazuh/wazuh-qa/pull/1243)) -- Analysisd - add new test to check the pre-decoding stage of analysisd ([#2406](https://github.com/wazuh/wazuh-qa/pull/2406)) -- Add test to check if files can be accessed while FIM has them opened ([#705](https://github.com/wazuh/wazuh-qa/pull/705)) -- Analysisd - add new test to check analysisd socket properties ([#2405](https://github.com/wazuh/wazuh-qa/pull/2405)) - Add `qa-docs` `v0.1`([#2649](https://github.com/wazuh/wazuh-qa/pull/2649)) - Add `qa-ctl` `v0.3.1`([#2649](https://github.com/wazuh/wazuh-qa/pull/2649)) @@ -24,6 +17,7 @@ Release report: TBD - CVEs alerts inventory for Vulnerability Detector - VDT and WDB Integration Tests implementation ([#1243](https://github.com/wazuh/wazuh-qa/pull/1243)) - Analysisd - add new test to check the pre-decoding stage of analysisd ([#2406](https://github.com/wazuh/wazuh-qa/pull/2406)) - Add test to check if files can be accessed while FIM has them opened ([#705](https://github.com/wazuh/wazuh-qa/pull/705)) +- Analysisd - add a new test to check analysisd socket properties ([#2405](https://github.com/wazuh/wazuh-qa/pull/2405)) - Add system test to check synchronization between agent and manager when one of this was stopped. ([#2536](https://github.com/wazuh/wazuh-qa/pull/2536)) ### Changed diff --git a/deps/wazuh_testing/wazuh_testing/tools/__init__.py b/deps/wazuh_testing/wazuh_testing/tools/__init__.py index b5eab0f3bf..f30b99c448 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/__init__.py +++ b/deps/wazuh_testing/wazuh_testing/tools/__init__.py @@ -25,6 +25,7 @@ ANALYSIS_STATISTICS_FILE = None UPGRADE_PATH = os.path.join(WAZUH_PATH, 'upgrade') AGENT_AUTH_BINARY_PATH = os.path.join(WAZUH_PATH, 'agent-auth.exe') + ANALYSISD_BINARY_PATH = None HOSTS_FILE_PATH = os.path.join("C:", os.sep, "Windows", "System32", "drivers", "etc", "hosts") GLOBAL_DB_PATH = None WAZUH_UNIX_USER = 'wazuh' @@ -63,6 +64,7 @@ ANALYSIS_STATISTICS_FILE = os.path.join(WAZUH_PATH, 'var', 'run', 'wazuh-analysisd.state') UPGRADE_PATH = os.path.join(WAZUH_PATH, 'var', 'upgrade') AGENT_AUTH_BINARY_PATH = os.path.join(WAZUH_PATH, 'bin', 'agent-auth') + ANALYSISD_BINARY_PATH = os.path.join(WAZUH_PATH, 'bin', 'wazuh-analysisd') if sys.platform == 'sunos5': HOSTS_FILE_PATH = os.path.join('/', 'etc', 'inet', 'hosts') else: diff --git a/tests/integration/test_analysisd/conftest.py b/tests/integration/test_analysisd/conftest.py index e28c896213..3b3d076fb9 100644 --- a/tests/integration/test_analysisd/conftest.py +++ b/tests/integration/test_analysisd/conftest.py @@ -9,10 +9,9 @@ from wazuh_testing.tools import (ALERT_FILE_PATH, LOG_FILE_PATH, WAZUH_UNIX_USER, WAZUH_UNIX_GROUP, - CUSTOM_RULES_PATH) + CUSTOM_RULES_PATH, ANALYSISD_DAEMON) from wazuh_testing.tools.file import truncate_file -from wazuh_testing.tools.services import control_service -from wazuh_testing.mocking import create_mocked_agent, delete_mocked_agent +from wazuh_testing.tools.services import control_service, check_daemon_status from wazuh_testing.tools.monitoring import FileMonitor @@ -68,16 +67,14 @@ def configure_custom_rules(request, get_configuration): @pytest.fixture(scope='module') def restart_analysisd(): - """wazuh-analysisd restart and log truncation""" - required_logtest_daemons = ['wazuh-analysisd'] + """Restart analysisd and truncate logs.""" truncate_file(ALERT_FILE_PATH) truncate_file(LOG_FILE_PATH) - for daemon in required_logtest_daemons: - control_service('restart', daemon=daemon) + control_service('restart', daemon=ANALYSISD_DAEMON) + check_daemon_status(running_condition=True, target_daemon=ANALYSISD_DAEMON) yield - for daemon in required_logtest_daemons: - control_service('stop', daemon=daemon) + control_service('stop', daemon=ANALYSISD_DAEMON) diff --git a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py index f555bef780..2dbff0012d 100644 --- a/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py +++ b/tests/integration/test_analysisd/test_queue_socket_properties/test_queue_socket_properties.py @@ -54,19 +54,14 @@ import pytest import subprocess -from wazuh_testing.tools import WAZUH_PATH, ANALYSISD_QUEUE_SOCKET_PATH, ANALYSISD_DAEMON -from wazuh_testing.tools.services import control_service, check_daemon_status +from wazuh_testing.tools import ANALYSISD_BINARY_PATH, ANALYSISD_QUEUE_SOCKET_PATH -# Marks +# Marks pytestmark = [pytest.mark.linux, pytest.mark.tier(level=0), pytest.mark.server] # Variables - -analysisd_path = os.path.join(WAZUH_PATH, 'bin', ANALYSISD_DAEMON) -command_exec = f'{analysisd_path} -t' - -# Fixtures +command_exec = f'{ANALYSISD_BINARY_PATH} -t' @pytest.fixture(scope="function") @@ -75,14 +70,6 @@ def socket_file_properties(): return os.stat(ANALYSISD_QUEUE_SOCKET_PATH).st_ino, os.path.getmtime(ANALYSISD_QUEUE_SOCKET_PATH) -@pytest.fixture(scope="function") -def restart_analysisd(): - """Restart and wait 'wazuh-analysisd' startup""" - # restart analysisd daemon - control_service('restart', daemon='wazuh-analysisd') - check_daemon_status(running_condition=True, target_daemon='wazuh-analysisd') - - @pytest.fixture(scope="function") def run_analysisd_test_config(): """Run the daemon configuration test mode of 'wazuh-analysisd'""" @@ -94,10 +81,11 @@ def run_analysisd_test_config(): after_socket_properties = socket_file_properties +# Tests def test_queue_socket_properties(restart_analysisd, before_socket_properties, run_analysisd_test_config, after_socket_properties): ''' - description: check if after running the configuration test of 'wazuh-analysisd' the properties + description: Check if after running the configuration test of 'wazuh-analysisd' the properties of the queue socket file are changed. wazuh_min_version: 4.3.0 @@ -105,7 +93,7 @@ def test_queue_socket_properties(restart_analysisd, before_socket_properties, ru parameters: - restart_analysisd: type: fixture - brief: Restart wazuh-analysisd. + brief: Restart analysisd and truncate logs. - before_socket_properties: type: fixture brief: Obtain the previous properties of the 'queue' socket.