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

test_synchronization system test tries to load a list as a JSON #5043

Closed
rauldpm opened this issue Feb 27, 2024 · 3 comments · Fixed by #5089
Closed

test_synchronization system test tries to load a list as a JSON #5043

rauldpm opened this issue Feb 27, 2024 · 3 comments · Fixed by #5089
Assignees
Labels

Comments

@rauldpm
Copy link
Member

rauldpm commented Feb 27, 2024

Description

The test_synchrronization.py is being marked as failed because it tries to load a list as a JSON. The steps are:

  1. The test makes a query to wazuh-db to obtain a fim entry, this is done at:

result = query_db(host_manager, db_script, db_path, f'\"{query}\"')

  1. That call gets the query using the Python script:

https:/wazuh/wazuh-qa/blob/master/tests/system/scripts/system_query_db.py

  1. Then, the query result is loaded as a JSON at:

But the query result is given as a list:

root@wazuh-manager: /var/ossec/queue/db# python /var/system_query_db.py --db_path /var/ossec/queue/db/001.db --query "select * from fim_entry where full_path='/testdir1/testdir1.txt'"
[(u'/testdir1/testdir1.txt', u'/testdir1/testdir1.txt', u'file', 1709054500, 1, None, None, None, 0, u'rw-r--r--', u'0', u'0', u'd41d8cd98f00b204e9800998ecf8427e', u'da39a3ee5e6b4b0d3255bfef95601890afd80709', u'root', u'root', 1709054494, 2079376, u'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', None, None, u'e79c68b86d746f1c88bcf337ba9462aeee68fad6')]

JSON does not know how to interpret it, resulting in the following error and failed test:

>           raise JSONDecodeError("Expecting value", s, err.value) from None
E           json.decoder.JSONDecodeError: Expecting value: line 1 column 2 (char 1)

This can be reproduced using the following Python script:

import json

def test():
    s = "[(u/testdir1/testdir1.txt', u'/testdir1/testdir1.txt', u'file', 1709054500, 1, None, None, None, 0, u'rw-r--r--', u'0', u'0', u'd41d8cd98f00b204e9800998ecf8427e', u'da39a3ee5e6b4b0d3255bfef95601890afd80709', u'root', u'root', 1709054494, 2079376, u'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', None, None, u'e79c68b86d746f1c88bcf337ba9462aeee68fad6')]"
    #s = "[]"
    #s = '{"name":"John", "age":30, "car":null}'
    #s = '{}'
    assert not json.loads(s)

It has been detected that sometimes, the query is returned as an empty list, in this case, the JSON load call accepts it and the test passes, marking the test as PASSED

If the query is given as a JSON with content, the test will fail (expected), and if the JSON query is empty, then the test will PASS

We need to review and fix this test to avoid false positives and convert the query list as a query JSON


Cataloged as High impact bugs because the test does not always fail, and if it does, the test will fail due to the assert (regardless of the format of the result), so we have to fix the format so that the error message is correct and we can catalog correctly the error

@rauldpm rauldpm changed the title test_synchronization system test tries to load a list as a JSON test_synchronization system test tries to load a list as a JSON Feb 27, 2024
@rafabailon rafabailon self-assigned this Mar 7, 2024
@rafabailon rafabailon linked a pull request Mar 8, 2024 that will close this issue
@rafabailon
Copy link
Member

Update

I have changed the way the queries are executed to use the same method as in other scripts. I have also changed the assert condition to adapt it to the new way of obtaining the data.

I have done tests locally, getting the tests to pass completely 10 times in a row.

@rafabailon
Copy link
Member

Note

The issue is in Pending Final Review. The review and the merge are missing. I move the ETA.

@rauldpm
Copy link
Member Author

rauldpm commented Mar 20, 2024

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants