diff --git a/deps/wazuh_testing/wazuh_testing/modules/aws/cli_utils.py b/deps/wazuh_testing/wazuh_testing/modules/aws/cli_utils.py index 9f29524c46..36d551c3b6 100644 --- a/deps/wazuh_testing/wazuh_testing/modules/aws/cli_utils.py +++ b/deps/wazuh_testing/wazuh_testing/modules/aws/cli_utils.py @@ -14,10 +14,10 @@ class OutputAnalysisError(Exception): def call_aws_module(*parameters) -> str: - """Given some parameters call the AWS module and return the output + """Given some parameters call the AWS module and return the output. Returns: - str: The command output + str: The command output. """ command = [AWS_MODULE_PATH, *parameters] logger.debug("Calling AWS module with: '%s'", command) @@ -34,16 +34,16 @@ def _default_callback(line: str) -> str: def analyze_command_output( command_output: str, callback: Callable = _default_callback, expected_results: int = 1, error_message: str = '' ): - """Analyze the given command output searching for a pattern + """Analyze the given command output searching for a pattern. Args: - command_output (str): the output to analyze - callback (Callable, optional): a callback to process each line. Defaults to _default_callback. - expected_results (int, optional): number of expected results. Defaults to 1. - error_message (str, optional): message to show with the exception. Defaults to ''. + command_output (str): The output to analyze. + callback (Callable, optional): A callback to process each line. Defaults to _default_callback. + expected_results (int, optional): Number of expected results. Defaults to 1. + error_message (str, optional): Message to show with the exception. Defaults to ''. Raises: - OutputAnalysisError: when the expected results are not correct + OutputAnalysisError: When the expected results are not correct. """ results = [] diff --git a/deps/wazuh_testing/wazuh_testing/modules/aws/data_generator.py b/deps/wazuh_testing/wazuh_testing/modules/aws/data_generator.py index bcfdfce89b..3daa0e9e91 100644 --- a/deps/wazuh_testing/wazuh_testing/modules/aws/data_generator.py +++ b/deps/wazuh_testing/wazuh_testing/modules/aws/data_generator.py @@ -1,6 +1,7 @@ """Utils to generate sample data to AWS""" from datetime import datetime from uuid import uuid4 +from typing import Optional from . import constants as cons @@ -10,18 +11,18 @@ class DataGenerator: BASE_FILE_NAME = '' def get_filename(self, *args, **kwargs) -> str: - """Returns the filename according to the integration format + """Returns the filename according to the integration format. Returns: - str: syntetic filename + str: Syntetic filename. """ raise NotImplementedError() def get_data_sample(self, *args, **kwargs) -> dict: - """Returns a sample of data according to the integration format + """Returns a sample of data according to the integration format. Returns: - dict: syntetic data + dict: Syntetic data. """ raise NotImplementedError() @@ -30,9 +31,14 @@ class CloudTrailDataGenerator(DataGenerator): BASE_PATH = f'{cons.AWS_LOGS}/{cons.RANDOM_ACCOUNT_ID}/{cons.CLOUD_TRAIL}/{cons.US_EAST_1_REGION}/' BASE_FILE_NAME = f'{cons.RANDOM_ACCOUNT_ID}_{cons.CLOUD_TRAIL}_{cons.US_EAST_1_REGION}_' - def get_filename(self, prefix=None, **kwargs) -> str: - """Return the filename in the cloudtrail format - /AWSLogs////CloudTrail//// + def get_filename(self, *args, **kwargs) -> str: + """Return the filename in the cloudtrail format. + + Example: + /AWSLogs////CloudTrail//// + + Returns: + str: Syntetic filename. """ now = datetime.now() path = f"{self.BASE_PATH}{now.strftime(cons.PATH_DATE_FORMAT)}/" @@ -41,6 +47,11 @@ def get_filename(self, prefix=None, **kwargs) -> str: return f'{path}{name}' def get_data_sample(self) -> dict: + """Returns a sample of data according to the cloudtrail format. + + Returns: + dict: Syntetic data. + """ return { 'Records': [ { @@ -93,6 +104,12 @@ def get_data_sample(self) -> dict: def get_data_generator(bucket_type: str) -> DataGenerator: - """Given the bucket type return the correspondant data generator instance + """Given the bucket type return the correspondant data generator instance. + + Args: + bucket_type (str): Bucket type to match the data generator. + + Returns: + DataGenerator: Data generator for the given bucket. """ return buckets_data_mapping[bucket_type]() diff --git a/deps/wazuh_testing/wazuh_testing/modules/aws/db_utils.py b/deps/wazuh_testing/wazuh_testing/modules/aws/db_utils.py index a0c4af1b35..efd6f0a61a 100644 --- a/deps/wazuh_testing/wazuh_testing/modules/aws/db_utils.py +++ b/deps/wazuh_testing/wazuh_testing/modules/aws/db_utils.py @@ -19,28 +19,28 @@ def get_db_connection(path: Path) -> sqlite3.Connection: def s3_db_exists() -> bool: - """Check if `s3_cloudtrail.db` exists + """Check if `s3_cloudtrail.db` exists. Returns: - bool: True if exists else False + bool: True if exists else False. """ return S3_CLOUDTRAIL_DB_PATH.exists() def delete_s3_db() -> None: - """Delete `s3_cloudtrail.db` file""" + """Delete `s3_cloudtrail.db` file.""" if s3_db_exists(): S3_CLOUDTRAIL_DB_PATH.unlink() def get_s3_db_row(table_name: str) -> S3CloudTrailRow: - """Return one row from the given table name + """Return one row from the given table name. Args: - table_name (str): table name to search into + table_name (str): Table name to search into. Returns: - S3CloudTrailRow: the first row of the table + S3CloudTrailRow: The first row of the table. """ connection = get_db_connection(S3_CLOUDTRAIL_DB_PATH) cursor = connection.cursor() @@ -50,13 +50,13 @@ def get_s3_db_row(table_name: str) -> S3CloudTrailRow: def get_multiple_s3_db_row(table_name: str) -> Iterator[S3CloudTrailRow]: - """Return all rows from the given table name + """Return all rows from the given table name. Args: - table_name (str): table name to search into + table_name (str): Table name to search into. Yields: - Iterator[S3CloudTrailRow]: all the rows in the table + Iterator[S3CloudTrailRow]: All the rows in the table. """ connection = get_db_connection(S3_CLOUDTRAIL_DB_PATH) cursor = connection.cursor() @@ -66,13 +66,13 @@ def get_multiple_s3_db_row(table_name: str) -> Iterator[S3CloudTrailRow]: def table_exists(table_name: str) -> bool: - """Check if the given table name exists + """Check if the given table name exists. Args: - table_name (str): table name to search for + table_name (str): Table name to search for. Returns: - bool: True if exists else False + bool: True if exists else False. """ connection = get_db_connection(S3_CLOUDTRAIL_DB_PATH) cursor = connection.cursor() diff --git a/deps/wazuh_testing/wazuh_testing/modules/aws/event_monitor.py b/deps/wazuh_testing/wazuh_testing/modules/aws/event_monitor.py index 5392299c40..60066d91a3 100644 --- a/deps/wazuh_testing/wazuh_testing/modules/aws/event_monitor.py +++ b/deps/wazuh_testing/wazuh_testing/modules/aws/event_monitor.py @@ -13,10 +13,10 @@ def make_aws_callback(pattern, prefix=''): Args: pattern (str): String to match on the log. - prefix (str): regular expression used as prefix before the pattern. + prefix (str): Regular expression used as prefix before the pattern. Returns: - lambda: function that returns if there's a match in the file + lambda: Function that returns if there's a match in the file. """ pattern = r'\s+'.join(pattern.split()) regex = re.compile(r'{}{}'.format(prefix, pattern)) @@ -25,13 +25,13 @@ def make_aws_callback(pattern, prefix=''): def callback_detect_aws_module_called(parameters: list) -> Callable: - """Detects if aws module was called with correct parameters + """Detects if aws module was called with correct parameters. Args: - parameters (list): values to check + parameters (list): Values to check. Returns: - Callable: callback to match the line + Callable: Callback to match the line. """ regex = re.compile(fr'.*DEBUG: Launching S3 Command: {" ".join(parameters)}\n*') return lambda line: regex.match(line) diff --git a/deps/wazuh_testing/wazuh_testing/modules/aws/s3_utils.py b/deps/wazuh_testing/wazuh_testing/modules/aws/s3_utils.py index 42d9f7b108..a114eca7b2 100644 --- a/deps/wazuh_testing/wazuh_testing/modules/aws/s3_utils.py +++ b/deps/wazuh_testing/wazuh_testing/modules/aws/s3_utils.py @@ -14,14 +14,14 @@ def upload_file(bucket_type: str, bucket_name: str) -> str: - """Upload a file to an S3 bucket + """Upload a file to an S3 bucket. Args: - bucket_type (str): Bucket type to generate the data - bucket_name (str): Bucket to upload + bucket_type (str): Bucket type to generate the data. + bucket_name (str): Bucket to upload. Returns: - str: the name of the file if was uploaded, else '' + str: The name of the file if was uploaded, else ''. """ dg = get_data_generator(bucket_type) filename = dg.get_filename() @@ -42,20 +42,20 @@ def delete_file(filename: str, bucket_name: str) -> None: """Delete a given file from the bucket. Args: - filename (str): Full filename to delete - bucket_name (str): bucket that contains the file + filename (str): Full filename to delete. + bucket_name (str): Bucket that contains the file. """ s3.Object(bucket_name, filename).delete() def file_exists(filename: str, bucket_name: str) -> bool: - """Check if a file exists in a bucket + """Check if a file exists in a bucket. Args: - filename (str): Full filename to check - bucket_name (str): bucket that contains the file + filename (str): Full filename to check. + bucket_name (str): Bucket that contains the file. Returns: - bool: True if exists else False + bool: True if exists else False. """ exists = True try: @@ -68,14 +68,14 @@ def file_exists(filename: str, bucket_name: str) -> bool: def get_last_file_key(bucket_type: str, bucket_name: str) -> str: - """Return the last file key contained in a default path of a bucket + """Return the last file key contained in a default path of a bucket. Args: - bucket_type (str): Bucket type to obtain the data generator - bucket_name (str): Bucket that contains the file + bucket_type (str): Bucket type to obtain the data generator. + bucket_name (str): Bucket that contains the file. Returns: - str: The last key in the bucket + str: The last key in the bucket. """ dg = get_data_generator(bucket_type) diff --git a/tests/integration/test_aws/test_discard_regex.py b/tests/integration/test_aws/test_discard_regex.py index bdc08afa1d..22a2f6624f 100644 --- a/tests/integration/test_aws/test_discard_regex.py +++ b/tests/integration/test_aws/test_discard_regex.py @@ -49,8 +49,8 @@ def test_discard_regex( - test: - Check in the ossec.log that a line has appeared calling the module with correct parameters. - Check the expected number of events were forwarded to analysisd, only logs stored in the bucket and skips - the ones that match with regex - - Check the database was created and updated accordingly + the ones that match with regex. + - Check the database was created and updated accordingly. - teardown: - Truncate wazuh logs. - Restore initial configuration, both ossec.conf and local_internal_options.conf. @@ -71,7 +71,7 @@ def test_discard_regex( brief: Apply changes to the ossec.conf configuration. - clean_s3_cloudtrail_db: type: fixture - brief: Delete the DB file before and after the test execution + brief: Delete the DB file before and after the test execution. - configure_local_internal_options_function: type: fixture brief: Apply changes to the local_internal_options.conf configuration. @@ -83,11 +83,11 @@ def test_discard_regex( brief: Restart the wazuh service. - wazuh_log_monitor: type: fixture - brief: Return a `ossec.log` monitor + brief: Return a `ossec.log` monitor. assertions: - Check in the log that the module was called with correct parameters. - - Check the expected number of events were forwarded to analysisd - - Check the database was created and updated accordingly + - Check the expected number of events were forwarded to analysisd. + - Check the database was created and updated accordingly. input_description: - The `configuration_discard_regex` file provides the module configuration for this test. - The `cases_discard_regex` file provides the test cases. diff --git a/tests/integration/test_aws/test_only_logs_after.py b/tests/integration/test_aws/test_only_logs_after.py index 703efb02d7..8fed2d44bf 100644 --- a/tests/integration/test_aws/test_only_logs_after.py +++ b/tests/integration/test_aws/test_only_logs_after.py @@ -58,11 +58,11 @@ def test_without_only_logs_after( - Check in the ossec.log that a line has appeared calling the module with correct parameters. - Check the expected number of events were sent to analysisd. Only the logs whose timestamp is greater than the date specified in the configuration should be processed. - - Check the database was created and updated accordingly + - Check the database was created and updated accordingly. - teardown: - Truncate wazuh logs. - Restore initial configuration, both ossec.conf and local_internal_options.conf. - - Delete the uploaded file + - Delete the uploaded file. wazuh_min_version: 4.5.0 parameters: - configuration: @@ -73,7 +73,7 @@ def test_without_only_logs_after( brief: Get metadata from the module. - upload_and_delete_file_to_s3: type: fixture - brief: Upload a file for the day of the execution and delete after the test + brief: Upload a file for the day of the execution and delete after the test. - load_wazuh_basic_configuration: type: fixture brief: Load basic wazuh configuration. @@ -82,7 +82,7 @@ def test_without_only_logs_after( brief: Apply changes to the ossec.conf configuration. - clean_s3_cloudtrail_db: type: fixture - brief: Delete the DB file before and after the test execution + brief: Delete the DB file before and after the test execution. - configure_local_internal_options_function: type: fixture brief: Apply changes to the local_internal_options.conf configuration. @@ -94,7 +94,7 @@ def test_without_only_logs_after( brief: Restart the wazuh service. - wazuh_log_monitor: type: fixture - brief: Return a `ossec.log` monitor + brief: Return a `ossec.log` monitor. assertions: - Check in the log that the module was called with correct parameters. - Check in the bucket that the uploaded log was removed. @@ -176,7 +176,7 @@ def test_with_only_logs_after( - teardown: - Truncate wazuh logs. - Restore initial configuration, both ossec.conf and local_internal_options.conf. - - Delete the uploaded file + - Delete the uploaded file. wazuh_min_version: 4.5.0 parameters: - configuration: @@ -193,7 +193,7 @@ def test_with_only_logs_after( brief: Apply changes to the ossec.conf configuration. - clean_s3_cloudtrail_db: type: fixture - brief: Delete the DB file before and after the test execution + brief: Delete the DB file before and after the test execution. - configure_local_internal_options_function: type: fixture brief: Apply changes to the local_internal_options.conf configuration. @@ -205,7 +205,7 @@ def test_with_only_logs_after( brief: Restart the wazuh service. - wazuh_log_monitor: type: fixture - brief: Return a `ossec.log` monitor + brief: Return a `ossec.log` monitor. assertions: - Check in the log that the module was called with correct parameters. - Check in the bucket that the uploaded log was removed. @@ -268,27 +268,27 @@ def test_multiple_calls( metadata, clean_s3_cloudtrail_db, load_wazuh_basic_configuration, restart_wazuh_function, delete_file_from_s3 ): """ - description: Call the AWS module multiple times with different only_logs_after values + description: Call the AWS module multiple times with different only_logs_after values. test_phases: - setup: - - Delete the s3_cloudtrail.db + - Delete the `s3_cloudtrail.db`. - test: - - Call the module without only_logs_after and check that no logs were processed + - Call the module without only_logs_after and check that no logs were processed. - Upload a log file for the day of the test execution and call the module with the same parameters as - before, check that the uploaded logs were processed - - Call the module with the same parameters and check that no logs were processed, there were no duplicates + before, check that the uploaded logs were processed. + - Call the module with the same parameters and check that no logs were processed, there were no duplicates. - Call the module with only_logs_after set in the past and check that the expected number of logs were - processed - - Call the module with the same parameters in and check there were no duplicates + processed. + - Call the module with the same parameters in and check there were no duplicates. - Call the module with only_logs_after set with an older date check that old logs were processed without - duplicates + duplicates. - Call the module with only_logs_after set with an early date than setted previously and check that no logs - were processed, there were no duplicates + were processed, there were no duplicates. - teardown: - - Delete the s3_cloudtrail.db - - Delete the uploaded files + - Delete the `s3_cloudtrail.db`. + - Delete the uploaded files. wazuh_min_version: 4.5.0 parameters: - metadata: @@ -296,7 +296,7 @@ def test_multiple_calls( brief: Get metadata from the module. - clean_s3_cloudtrail_db: type: fixture - brief: Delete the DB file before and after the test execution + brief: Delete the DB file before and after the test execution. - load_wazuh_basic_configuration: type: fixture brief: Load basic wazuh configuration. @@ -305,7 +305,7 @@ def test_multiple_calls( brief: Restart the wazuh service. - delete_file_from_s3: type: fixture - brief: Delete the a file after the test execution + brief: Delete the a file after the test execution. input_description: - The `cases_multiple_calls` file provides the test cases. """ diff --git a/tests/integration/test_aws/test_path.py b/tests/integration/test_aws/test_path.py index f0c3fe4b93..75c81772ae 100644 --- a/tests/integration/test_aws/test_path.py +++ b/tests/integration/test_aws/test_path.py @@ -49,13 +49,13 @@ def test_path( - test: - Check in the ossec.log that a line has appeared calling the module with correct parameters. - If a path that does not exist was specified, make sure that a message is displayed in the ossec.log - warning the user - - Check the command was called with the correct parameters - - Check the database was created and updated accordingly + warning the user. + - Check the command was called with the correct parameters. + - Check the database was created and updated accordingly. - teardown: - Truncate wazuh logs. - Restore initial configuration, both ossec.conf and local_internal_options.conf. - - Delete the uploaded file + - Delete the uploaded file. wazuh_min_version: 4.5.0 parameters: - configuration: @@ -72,7 +72,7 @@ def test_path( brief: Apply changes to the ossec.conf configuration. - clean_s3_cloudtrail_db: type: fixture - brief: Delete the DB file before and after the test execution + brief: Delete the DB file before and after the test execution. - configure_local_internal_options_function: type: fixture brief: Apply changes to the local_internal_options.conf configuration. @@ -84,11 +84,11 @@ def test_path( brief: Restart the wazuh service. - wazuh_log_monitor: type: fixture - brief: Return a `ossec.log` monitor + brief: Return a `ossec.log` monitor. assertions: - Check in the log that the module was called with correct parameters. - - Check the expected number of events were forwarded to analysisd - - Check the database was created and updated accordingly, using the correct path for each entry + - Check the expected number of events were forwarded to analysisd. + - Check the database was created and updated accordingly, using the correct path for each entry. input_description: - The `configuration_path` file provides the module configuration for this test. - The `cases_path` file provides the test cases. diff --git a/tests/integration/test_aws/test_path_suffix.py b/tests/integration/test_aws/test_path_suffix.py index 9c458d905f..6f89b31b38 100644 --- a/tests/integration/test_aws/test_path_suffix.py +++ b/tests/integration/test_aws/test_path_suffix.py @@ -49,13 +49,13 @@ def test_path_suffix( - test: - Check in the ossec.log that a line has appeared calling the module with correct parameters. - If a path_suffix that does not exist was specified, make sure that a message is displayed in the ossec.log - warning the user - - Check the command was called with the correct parameters - - Check the database was created and updated accordingly + warning the user. + - Check the command was called with the correct parameters. + - Check the database was created and updated accordingly. - teardown: - Truncate wazuh logs. - Restore initial configuration, both ossec.conf and local_internal_options.conf. - - Delete the uploaded file + - Delete the uploaded file. wazuh_min_version: 4.5.0 parameters: - configuration: @@ -84,11 +84,11 @@ def test_path_suffix( brief: Restart the wazuh service. - wazuh_log_monitor: type: fixture - brief: Return a `ossec.log` monitor + brief: Return a `ossec.log` monitor. assertions: - Check in the log that the module was called with correct parameters. - - Check the expected number of events were forwarded to analysisd - - Check the database was created and updated accordingly, using the correct path for each entry + - Check the expected number of events were forwarded to analysisd. + - Check the database was created and updated accordingly, using the correct path for each entry. input_description: - The `configuration_path_suffix` file provides the module configuration for this test. - The `cases_path_suffix` file provides the test cases. diff --git a/tests/integration/test_aws/test_regions.py b/tests/integration/test_aws/test_regions.py index a8ae05d9ec..28078dd52c 100644 --- a/tests/integration/test_aws/test_regions.py +++ b/tests/integration/test_aws/test_regions.py @@ -54,14 +54,14 @@ def test_regions( - test: - Check in the ossec.log that a line has appeared calling the module with correct parameters. - If a region that does not exist was specified, make sure that a message is displayed in the ossec.log - warning the user + warning the user. - Check the expected number of events were forwarded to analysisd, only logs stored in the bucket - for the specified region - - Check the database was created and updated accordingly + for the specified region. + - Check the database was created and updated accordingly. - teardown: - Truncate wazuh logs. - Restore initial configuration, both ossec.conf and local_internal_options.conf. - - Delete the uploaded file + - Delete the uploaded file. wazuh_min_version: 4.5.0 parameters: - configuration: @@ -78,7 +78,7 @@ def test_regions( brief: Apply changes to the ossec.conf configuration. - clean_s3_cloudtrail_db: type: fixture - brief: Delete the DB file before and after the test execution + brief: Delete the DB file before and after the test execution. - configure_local_internal_options_function: type: fixture brief: Apply changes to the local_internal_options.conf configuration. @@ -90,11 +90,11 @@ def test_regions( brief: Restart the wazuh service. - wazuh_log_monitor: type: fixture - brief: Return a `ossec.log` monitor + brief: Return a `ossec.log` monitor. assertions: - Check in the log that the module was called with correct parameters. - - Check the expected number of events were forwarded to analysisd - - Check the database was created and updated accordingly, using the correct path for each entry + - Check the expected number of events were forwarded to analysisd. + - Check the database was created and updated accordingly, using the correct path for each entry. input_description: - The `configuration_regions` file provides the module configuration for this test. - The `cases_regions` file provides the test cases. diff --git a/tests/integration/test_aws/test_remove_from_bucket.py b/tests/integration/test_aws/test_remove_from_bucket.py index a8f8e66e05..a0bef561ad 100644 --- a/tests/integration/test_aws/test_remove_from_bucket.py +++ b/tests/integration/test_aws/test_remove_from_bucket.py @@ -62,7 +62,7 @@ def test_remove_from_bucket( brief: Get metadata from the module. - upload_file_to_s3: type: fixture - brief: Upload a file to S3 bucket for the day of the execution + brief: Upload a file to S3 bucket for the day of the execution. - load_wazuh_basic_configuration: type: fixture brief: Load basic wazuh configuration. @@ -71,7 +71,7 @@ def test_remove_from_bucket( brief: Apply changes to the ossec.conf configuration. - clean_s3_cloudtrail_db: type: fixture - brief: Delete the DB file before and after the test execution + brief: Delete the DB file before and after the test execution. - configure_local_internal_options_function: type: fixture brief: Apply changes to the local_internal_options.conf configuration. @@ -83,7 +83,7 @@ def test_remove_from_bucket( brief: Restart the wazuh service. - wazuh_log_monitor: type: fixture - brief: Return a `ossec.log` monitor + brief: Return a `ossec.log` monitor. assertions: - Check in the log that the module was called with correct parameters. - Check in the bucket that the uploaded log was removed.