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

Update delta file schema for the migration tool tests #4375

Merged
merged 2 commits into from
Aug 3, 2023

Conversation

jftuduri
Copy link
Member

Related issue
Closes #4374

Description

This PR updates the delta file schema to match the changes to the delta files that will be introduced by https://github.com/wazuh/intelligence-platform/pull/1000. This file is used in the migration tool tests.

Updated

  • deps/wazuh_testing/wazuh_testing/tools/migration_tool/delta_schema.json

Testing performed

Before

Previous to this change one of the the migration tool tests failed when applied to the thub.com/wazuh/intelligence-platform/pull/1000.

Tests output prior to this change
ft@ft-nb:~/wazuh/repos/dev/intelligence-platform$ python3 -m pytest qa/tests/end_to_end/ --env dev
===================================================================== test session starts ======================================================================
platform linux -- Python 3.10.6, pytest-7.1.2, pluggy-1.2.0
rootdir: /home/ft/wazuh/repos/dev/intelligence-platform/qa, configfile: pytest.ini
plugins: metadata-2.0.4, testinfra-5.0.0, html-3.1.1
collected 20 items                                                                                                                                             

qa/tests/end_to_end/test_feed_ingestion/test_invalid_inputs.py ....                                                                                      [ 20%]
qa/tests/end_to_end/test_feed_ingestion/test_valid_inputs.py .............F..                                                                            [100%]

=========================================================================== FAILURES ===========================================================================
____________________________________________________ test_delta_schema[ARCH_DELTA_DELETE_SCHEMA_VALIDATION] ____________________________________________________

configuration = {'description': 'Arch Linux', 'remotes': [{'compressed': 'raw', 'dataFormat': 'json', 'downloadPath': 'downloads/arch/...oadPath': 'downloads/arch/arch_base_test.json', 'lastSnapshotFilePath': 'snapshots/arch/arch', ...}], 'vendor': 'arch'}
metadata = {'description': 'Verify the tool generates the deltas correctly when a new vulnerability is removed.', 'name': 'ARCH_DELTA_DELETE_SCHEMA_VALIDATION', 'vendor': 'arch'}
prepare_migration_tool_config_file = PosixPath('/home/ft/wazuh/repos/dev/intelligence-platform/qa/tests/end_to_end/test_feed_ingestion/data/configuration/temp_configuration_file.json')
clean_migration_tool_log = None, remove_generated_files = None, drop_generated_tables = None

    @pytest.mark.environment(name='dev')
    @pytest.mark.tier(level=1)
    @pytest.mark.parametrize('configuration,metadata', zip(t3_config, t3_metadata), ids=t3_cases_id)
    def test_delta_schema(configuration, metadata, prepare_migration_tool_config_file, clean_migration_tool_log,
                          remove_generated_files, drop_generated_tables):
        '''
        description: Given 2 feeds from a vendor, and both are different, when the migration is run for each feed, then the
                     migration is completed and the format of the generated file with the deltas is the correct.
    
        test_phases:
            - setup:
                - Prepare the configuration file for the Migration Tool to run.
                - Clean the output files generated by the tool, the tables created in the DB and the log.
            - test:
                - Run the tool for each feed.
                - Check if the tool fails while processing the feed.
                - Check if the format of the generated file with the deltas is correct.
            - teardown:
                - Remove the configuration files generated.
                - Clean the output files generated by the tool, the tables created in the DB and the log.
    
        tier: 1
    
        parameters:
            - configuration:
                type: dict
                brief: Configuration parameters from where the configuration file will be built.
            - metadata:
                type: dict
                brief: Test case metadata.
            - prepare_migration_tool_config_file:
                type: fixture
                brief: Prepare the configuration file for the Migration Tool to run.
            - clean_migration_tool_log:
                type: fixture
                brief: Clean Migration Tool's log file.
            - remove_generated_files:
                type: fixture
                brief: Remove all the files that have been generated during the execution.
            - drop_generated_tables:
                type: fixture
                brief: Drop the tables that were generated during the execution.
    
        assertions:
            - Verify that the execution of the tool does not fail.
            - Verify that the format of the generated file with the deltas is correct.
    
        input_description:
            - The `cases_delta_schema` file provides the test cases.
    
        expected_output:
            - No errors while executing the tool
            - No errors in the format.
        '''
        deltas_filepath = os.path.join(SNAPSHOTS_DIR, configuration['vendor'])
        configuration_file_path = prepare_migration_tool_config_file
    
        # Run the tool (to get the desired state)
        output, err_output = run_content_migration_tool(configuration_file_path)
        if err_output != '' or output == '':
            pytest.fail(f"The execution of the binary have failed unexpectedly:\n{err_output}")
    
        latest_delta_file = get_latest_delta_file(deltas_filepath)
        delta_file_content = read_json_file(latest_delta_file)
        elements = delta_file_content['elements']
    
        # Validate file with deltas
        errors = validate_against_delta_schema(elements)
        errors = '\n'.join(errors)
>       assert len(errors) == 0, 'The delta file is invalid according to the CVE5 schema.\n' \
                                 f"Validation Error: {errors}Tool result at: {latest_delta_file}.\nTool output:\n{output}"
E       AssertionError: The delta file is invalid according to the CVE5 schema.
E         Validation Error: 'data_blob' is a required property
E         'data_blob' is a required property
E         'data_blob' is a required propertyTool result at: /var/wazuh/incoming/snapshots/arch/arch.delta.1690572474.json.
E         Tool output:
E         
E         ################ Wazuh Content Migration ################
E         
E         Content migration has been processed for 1 vendor/s in 00:00:00.
E         
E         => Arch Linux content migration (2 remote/s)
E               Remote exited successfully:
E                       URL: 'http://localhost:8888/arch/arch_vuln_added_test.json'
E                       Total CVEs associated: 4
E                       Last migration: Never
E               Remote exited successfully:
E                       URL: 'http://localhost:8888/arch/arch_base_test.json'
E                       Total CVEs associated: 1
E                       Last migration: Never
E         
E         
E       assert 104 == 0
E        +  where 104 = len("'data_blob' is a required property\n'data_blob' is a required property\n'data_blob' is a required property")

qa/tests/end_to_end/test_feed_ingestion/test_valid_inputs.py:297: AssertionError
--------------------------------------------------------------------- Captured stderr call ---------------------------------------------------------------------
127.0.0.1 - - [28/Jul/2023 16:27:53] "GET /arch/arch_vuln_added_test.json HTTP/1.1" 200 -
127.0.0.1 - - [28/Jul/2023 16:27:54] "GET /arch/arch_base_test.json HTTP/1.1" 200 -
=================================================================== short test summary info ====================================================================
FAILED qa/tests/end_to_end/test_feed_ingestion/test_valid_inputs.py::test_delta_schema[ARCH_DELTA_DELETE_SCHEMA_VALIDATION] - AssertionError: The delta file ...
=========================================================== 1 failed, 19 passed in 516.46s (0:08:36) ===========================================================
ft@ft-nb:~/wazuh/repos/dev/intelligence-platform$ git submodule status
 c8c1d870bb2642f08da8fd3294fab6d16dfc842a qa/wazuh-qa (v4.4.5-393-gc8c1d870b)
 3aa7c4b4a442f6ddfb52484fe766da769a8af50a shared/http-request (remotes/origin/HEAD

After

With the change to the schema, all tests pass successfully:
all_test_ok

Tests output with this change
ft@ft-nb:~/wazuh/repos/dev/intelligence-platform$ python3 -m pytest qa/tests/end_to_end/ --env dev
===================================================================== test session starts ======================================================================
platform linux -- Python 3.10.6, pytest-7.1.2, pluggy-1.2.0
rootdir: /home/ft/wazuh/repos/dev/intelligence-platform/qa, configfile: pytest.ini
plugins: metadata-2.0.4, testinfra-5.0.0, html-3.1.1
collected 20 items                                                                                                                                             

qa/tests/end_to_end/test_feed_ingestion/test_invalid_inputs.py ....                                                                                      [ 20%]
qa/tests/end_to_end/test_feed_ingestion/test_valid_inputs.py ................                                                                            [100%]

================================================================ 20 passed in 460.77s (0:07:40) ================================================================
ft@ft-nb:~/wazuh/repos/dev/intelligence-platform$ git submodule status 
+6bb1481e3f5b7331f0055f3059f448d408f1d526 qa/wazuh-qa (v4.4.5-399-g6bb1481e3)
 3aa7c4b4a442f6ddfb52484fe766da769a8af50a shared/http-request (remotes/origin/HEAD)
ft@ft-nb:~/wazuh/repos/dev/intelligence-platform$ git log -1 --oneline
3ee9661c (HEAD -> dev-989-fix-diffengine-inconsistencies, origin/dev-989-fix-diffengine-inconsistencies) Use 'at' to access the fieldName element 

@jftuduri jftuduri self-assigned this Jul 28, 2023
- 'data_blob' is no longer a required field on 'delete' operations.
@jftuduri jftuduri force-pushed the dev-4374-update-migration-tool-delta-file-schema branch from 6bb1481 to e8ce3c0 Compare July 28, 2023 20:09
@jftuduri jftuduri marked this pull request as ready for review July 28, 2023 20:10
@Dwordcito Dwordcito self-requested a review August 3, 2023 12:54
Dwordcito
Dwordcito previously approved these changes Aug 3, 2023
@Damian-Mangold Damian-Mangold force-pushed the dev-4374-update-migration-tool-delta-file-schema branch from f0d75d0 to d5755ef Compare August 3, 2023 13:25
@Dwordcito Dwordcito self-requested a review August 3, 2023 13:55
@Dwordcito Dwordcito merged commit b262f03 into master Aug 3, 2023
5 checks passed
@Dwordcito Dwordcito deleted the dev-4374-update-migration-tool-delta-file-schema branch August 3, 2023 13:55
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.

Update the JSON schema used by the migration tool
3 participants