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

Add missing q in endpoints. Changes in utils.py #5431

Merged
merged 7 commits into from
Jul 10, 2020

Conversation

Selutario
Copy link
Contributor

@Selutario Selutario commented Jul 7, 2020

Related issue
#5344

Description

Summary

Hello team. This PR includes multiple changes to the q parameter. There have also been many things that, after researching and developing them, we have decided not to include. The summary list of changes is:

  • Parameter q now does not split strings by commas. It still accepts lists and dictionaries as before.
  • Method filter_array_by_query (used inside process_array()) now accepts nested values like in the WazuhDBQuery class.
  • Using non-percent-encoded semicolons within a query now throws an exception to avoid incorrect results.
  • Parameter q can now be used on 14 extra endpoints.
  • Integrated tests have been added for all the endpoints mentioned in the previous point.
  • Integrated tests that use more complex q have been added.

Future changes

After comparing and investigating multiple solutions, we may add the parameter q as body in future changes. In this way, any query could be inserted without coding it, such as:

{
    'q': 'benchmark~CIS;(pass>200,fail<100);score!=0'
}

We also find it interesting to use a new format that makes the query parameter easier to understand and more flexible. An example would be:

{"name": "wazuh-agent1"}
{"status" : {"$in" : ["active", "disconnected"]}}
{"os.name" : {"$not" : "ubuntu"}}
{"status" : {"$nin" : ["never_connected", "disconnected", "pending"]}}
{"$and": [{"os.version": "18"}, {"os.name": "ubuntu"}]}

However, OpenAPI 3.0.0 (the latest version and the one we are using right now) does not support the use of body on endpoints with the GET or HEAD method. For this reason, we may rethink using it when OA version 3.1.0 is released: OAI/OpenAPI-Specification#1937

Tests

pytest test_agents_GET_endpoints.tavern.yaml
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.8.2, pytest-5.4.3, py-1.8.2, pluggy-0.13.1
rootdir: /home/selu/Git/wazuh/api/test/integration, inifile: pytest.ini
plugins: tavern-1.2.2, cov-2.10.0
collected 90 items                                                                                                                                                                                           

test_agents_GET_endpoints.tavern.yaml ..........................................................................................                                                                       [100%]

============================================================================================== warnings summary ==============================================================================================
pytest test_decoders_endpoints.tavern.yaml
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.8.2, pytest-5.4.3, py-1.8.2, pluggy-0.13.1
rootdir: /home/selu/Git/wazuh/api/test/integration, inifile: pytest.ini
plugins: tavern-1.2.2, cov-2.10.0
collected 23 items                                                                                                                                                                                           

test_decoders_endpoints.tavern.yaml .......................                                                                                                                                            [100%]

============================================================================================== warnings summary ==============================================================================================

(There is an error related with an incorrect rule in the ruleset)

pytest test_rules_endpoints.tavern.yaml
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.8.2, pytest-5.4.3, py-1.8.2, pluggy-0.13.1
rootdir: /home/selu/Git/wazuh/api/test/integration, inifile: pytest.ini
plugins: tavern-1.2.2, cov-2.10.0
collected 13 items                                                                                                                                                                                           

test_rules_endpoints.tavern.yaml ....F........                                                                                                                                                         [100%]

================================================================================================== FAILURES ==================================================================================================
pytest test_syscheck_endpoints.tavern.yaml
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.8.2, pytest-5.4.3, py-1.8.2, pluggy-0.13.1
rootdir: /home/selu/Git/wazuh/api/test/integration, inifile: pytest.ini
plugins: tavern-1.2.2, cov-2.10.0
collected 35 items                                                                                                                                                                                           

test_syscheck_endpoints.tavern.yaml ...................................                                                                                                                                [100%]

============================================================================================== warnings summary ==============================================================================================
pytest test_ciscat_endpoints.tavern.yaml
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.8.2, pytest-5.4.3, py-1.8.2, pluggy-0.13.1
rootdir: /home/selu/Git/wazuh/api/test/integration, inifile: pytest.ini
plugins: tavern-1.2.2, cov-2.10.0
collected 11 items                                                                                                                                                                                           

test_ciscat_endpoints.tavern.yaml ...........                                                                                                                                                          [100%]

============================================================================================== warnings summary ==============================================================================================
pytest test_cluster_endpoints.tavern.yaml
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.8.2, pytest-5.4.3, py-1.8.2, pluggy-0.13.1
rootdir: /home/selu/Git/wazuh/api/test/integration, inifile: pytest.ini
plugins: tavern-1.2.2, cov-2.10.0
collected 56 items                                                                                                                                                                                           

test_cluster_endpoints.tavern.yaml ........................................................                                                                                                            [100%]

============================================================================================== warnings summary ==============================================================================================
pytest test_syscollector_endpoints.tavern.yaml
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.8.2, pytest-5.4.3, py-1.8.2, pluggy-0.13.1
rootdir: /home/selu/Git/wazuh/api/test/integration, inifile: pytest.ini
plugins: tavern-1.2.2, cov-2.10.0
collected 161 items                                                                                                                                                                                          

test_syscollector_endpoints.tavern.yaml .............................................................................................................................................................. [ 66%]
...

============================================================================================== warnings summary ==============================================================================================
pytest test_mitre_endpoints.tavern.yaml
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.8.2, pytest-5.4.3, py-1.8.2, pluggy-0.13.1
rootdir: /home/selu/Git/wazuh/api/test/integration, inifile: pytest.ini
plugins: tavern-1.2.2, cov-2.10.0
collected 1 item                                                                                                                                                                                             

test_mitre_endpoints.tavern.yaml .                                                                                                                                                                     [100%]

============================================================================================== warnings summary ==============================================================================================

Kind regards,
Selu.

@Selutario Selutario self-assigned this Jul 7, 2020
api/api/controllers/agents_controller.py Outdated Show resolved Hide resolved
api/api/controllers/agents_controller.py Outdated Show resolved Hide resolved
api/api/util.py Show resolved Hide resolved
api/test/integration/test_ciscat_endpoints.tavern.yaml Outdated Show resolved Hide resolved
api/api/controllers/agents_controller.py Outdated Show resolved Hide resolved
api/api/uri_parser.py Outdated Show resolved Hide resolved
@davidjiglesias davidjiglesias merged commit 8b824bb into 4.0 Jul 10, 2020
@davidjiglesias davidjiglesias deleted the dev-5344-q-parameter branch July 10, 2020 10:38
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.

2 participants