From 6f0498891019e0c1d7537d21c21c3b43816bd078 Mon Sep 17 00:00:00 2001 From: Matias Pereyra Date: Thu, 18 Jan 2024 02:04:42 +0000 Subject: [PATCH] Updating tests after removing references to the legacy vulnerability detector module --- .../data/agent/agent_messages.yaml | 235 +----------------- .../data/global/wazuh_db_backup_command.yaml | 4 +- .../data/wazuh_db_backups_conf.yaml | 2 + .../test_agent_database_version.py | 4 +- .../test_wazuh_db/test_wazuh_db.py | 4 +- 5 files changed, 10 insertions(+), 239 deletions(-) diff --git a/tests/integration/test_wazuh_db/data/agent/agent_messages.yaml b/tests/integration/test_wazuh_db/data/agent/agent_messages.yaml index e76e1ad0ac..924e3e8d4a 100644 --- a/tests/integration/test_wazuh_db/data/agent/agent_messages.yaml +++ b/tests/integration/test_wazuh_db/data/agent/agent_messages.yaml @@ -1,218 +1,4 @@ --- -- - name: "Agents' CVEs table: vuln_cves" - description: "Checks the commands insert and clear" - test_case: - - - input: 'agent 000 vuln_cves insert {"name":"test_name", - "version":"1.0", - "architecture":"x64", - "cve":"CVE-2021-0001", - "reference":"03c06c4f118618400772367b1cf7e73ce0178e02", - "type":"PACKAGE", - "status":"VALID", - "check_pkg_existence":true, - "severity":null, - "cvss2_score":0, - "cvss3_score":0}' - output: 'ok {"action":"INSERT","status":"SUCCESS"}' - stage: "agent vuln_cves insert package when it does not exist in sys_programs" - - - input: 'agent 000 vuln_cves insert {"name":"test_package", - "version":"1.0", - "architecture":"x86", - "cve":"CVE-2021-1001", - "reference":"03c06c4f118618400772367b1cf7e73ce0178e02", - "type":"PACKAGE", - "status":"VALID", - "check_pkg_existence":false, - "severity":"Medium", - "cvss2_score":5.0, - "cvss3_score":6.1}' - output: 'ok {"action":"INSERT","status":"SUCCESS"}' - stage: "agent vuln_cves insert test_package without checking if the package is present in sys_programs" - - - input: 'agent 000 sql SELECT * FROM vuln_cves where cve="CVE-2021-1001"' - output: 'ok [{"name":"test_package","version":"1.0","architecture":"x86","cve":"CVE-2021-1001","detection_time":"*","severity":"Medium","cvss2_score":5,"cvss3_score":6.1,"reference":"03c06c4f118618400772367b1cf7e73ce0178e02","type":"PACKAGE","status":"VALID"}]' - stage: "agent vuln_cves checking test_package" - use_regex: "yes" - - - input: 'agent 000 vuln_cves insert {"name":"test_package", - "version":"1.0", - "architecture":"x86", - "cve":"CVE-2021-1001", - "reference":"03c06c4f118618400772367b1cf7e73ce0178e02", - "type":"PACKAGE", - "status":"VALID", - "check_pkg_existence":false, - "severity":"Medium", - "cvss2_score":5.0, - "cvss3_score":6.1}' - output: 'ok {"action":"UPDATE","status":"SUCCESS"}' - stage: "agent vuln_cves update already inserted entry" - - - input: 'agent 000 sql INSERT INTO sys_programs (scan_id,scan_time,format,name,priority,section,size,vendor,install_time,version,architecture,multiarch,source,description,location,triaged,cpe,msu_name,checksum,item_id) - VALUES(0,"2021/04/07 22:00:00","deb","test package","optional","utils","7490","Wazuh wazuh@wazuh.com",NULL,"1.0.0","amd64",NULL,NULL,"Test package",NULL,0,NULL,NULL,"e7dbc9bba5a0ee252866536225b952d3de7ea5cb","777fef8cc434b597769d102361af718d29ef72c1")' - output: 'ok []' - stage: "agent vuln_cves adding dummy test package to sys_programs" - - - input: 'agent 000 sql SELECT * FROM sys_programs WHERE name = "test package"' - output: 'ok [{"scan_id":0,"scan_time":"2021/04/07 22:00:00","format":"deb","name":"test package","priority":"optional","section":"utils","size":7490,"vendor":"Wazuh wazuh@wazuh.com","version":"1.0.0","architecture":"amd64","description":"Test package","triaged":0,"checksum":"e7dbc9bba5a0ee252866536225b952d3de7ea5cb","item_id":"777fef8cc434b597769d102361af718d29ef72c1"}]' - stage: "agent vuln_cves checking test package in sys_programs" - - - input: 'agent 000 vuln_cves insert {"name":"test package", - "version":"1.0", - "architecture":"x86", - "cve":"CVE-2021-1002", - "reference":"777fef8cc434b597769d102361af718d29ef72c1", - "type":"OS", - "status":"PENDING", - "check_pkg_existence":true, - "severity":null, - "cvss2_score":0, - "cvss3_score":0}' - output: 'ok {"action":"INSERT","status":"SUCCESS"}' - stage: "agent vuln_cves insert with spaces in json payload and the test package exist in sys_programs" - - - input: 'agent 000 sql SELECT * FROM vuln_cves WHERE name = "test package"' - output: 'ok [{"name":"test package","version":"1.0","architecture":"x86","cve":"CVE-2021-1002","detection_time":"*","cvss2_score":0,"cvss3_score":0,"reference":"777fef8cc434b597769d102361af718d29ef72c1","type":"OS","status":"PENDING"}]' - stage: "agent vuln_cves checking test package" - use_regex: "yes" - - - input: 'agent 000 vuln_cves insert {"name":"test_package","cve":"CVE-2021-1001"}' - output: "err Invalid JSON data, missing required fields" - stage: "agent vuln_cves insert incomplete package" - - - input: 'agent 000 vuln_cves insert {"name":"test_package",' - output: "err Invalid JSON syntax, near '{\"name\":\"test_package\",'" - stage: "agent vuln_cves insert invalid JSON" - - - input: 'agent 000 vuln_cves' - output: "err Invalid vuln_cves query syntax, near 'vuln_cves'" - stage: "agent vuln_cves missing command" - - - input: 'agent 000 vuln_cves insert' - output: "err Invalid JSON syntax, near ''" - stage: "agent vuln_cves missing payload" - - - input: 'agent 000 vuln_cves insert {"name":"test_package2", - "version":"3.0", - "architecture":"x86", - "cve":"CVE-2021-1001", - "reference":"99efe684b5ff4646b3c754de46cb6a9cbee9fbaa", - "type":"PACKAGE", - "status":"VALID", - "check_pkg_existence":false, - "severity":"Untriaged", - "cvss2_score":0, - "cvss3_score":0}' - output: 'ok {"action":"INSERT","status":"SUCCESS"}' - stage: "agent vuln_cves insert package with same CVE without checking if the package is present in sys_programs" - - - input: 'agent 000 sql SELECT * FROM vuln_cves WHERE name = "test_package2"' - output: 'ok []' - stage: "agent vuln_cves checking package insertion with same CVE" - use_regex: "yes" - - - input: 'agent 000 vuln_cves insert {"name":"test_package2", - "version":"3.0", - "architecture":"x86", - "cve":"CVE-2021-1002", - "reference":"99efe684b5ff4646b3c754de46cb6a9cbee9fbaa", - "type":"PACKAGE", - "status":"VALID", - "check_pkg_existence":false, - "severity":"High", - "cvss2_score":8.2, - "cvss3_score":9.35}' - output: 'ok {"action":"INSERT","status":"SUCCESS"}' - stage: "agent vuln_cves insert same package with different CVE without checking if the package is present in sys_programs" - - - input: 'agent 000 sql SELECT * FROM vuln_cves WHERE name = "test_package2" AND cve = "CVE-2021-1002"' - output: 'ok [{"name":"test_package2","version":"3.0","architecture":"x86","cve":"CVE-2021-1002","detection_time":"*","severity":"High","cvss2_score":8.2,"cvss3_score":9.35,"reference":"99efe684b5ff4646b3c754de46cb6a9cbee9fbaa","type":"PACKAGE","status":"VALID"}]' - stage: "agent vuln_cves checking package with different CVE" - use_regex: "yes" - - - input: 'agent 000 vuln_cves update_status {"old_status":"PENDING", - "new_status":"OBSOLETE"}' - output: 'ok' - stage: "agent vuln_cves update specific status to another one" - - - input: 'agent 000 sql SELECT distinct status FROM vuln_cves' - output: 'ok [{"status":"OBSOLETE"},{"status":"VALID"}]' - stage: 'agent vuln_cves checking change specific status by another one' - - - input: 'agent 000 vuln_cves update_status {"new_status":"PENDING", - "type":"OS"}' - output: 'ok' - stage: 'agent vuln_cves update status by type "OS"' - - - input: 'agent 000 sql SELECT count(status) FROM vuln_cves WHERE type = "OS"' - output: 'ok [{"count(status)":1}]' - stage: 'agent vuln_cves checking update status by type "OS"' - - - input: 'agent 000 vuln_cves update_status {"new_status":"PENDING", - "type":"PACKAGE"}' - output: 'ok' - stage: 'agent vuln_cves update status by type "PACKAGE"' - - - input: 'agent 000 sql SELECT count(status) FROM vuln_cves WHERE type = "PACKAGE"' - output: 'ok [{"count(status)":4}]' - stage: 'agent vuln_cves checking update status by type "PACKAGE"' - - - input: 'agent 000 vuln_cves update_status {"new_status":"VALID", - "type":"PACKAGE"}' - output: 'ok' - stage: 'agent vuln_cves update status by type "PACKAGE" again' - - - input: 'agent 000 sql SELECT count(status) FROM vuln_cves WHERE type = "PACKAGE"' - output: 'ok [{"count(status)":4}]' - stage: 'agent vuln_cves checking update status by type "PACKAGE" again' - - - input: 'agent 000 vuln_cves remove {"status":"PENDING"}' - output: 'ok [{"name":"test package","version":"1.0","architecture":"x86","cve":"CVE-2021-1002","detection_time":"*","cvss2_score":0,"cvss3_score":0,"reference":"777fef8cc434b597769d102361af718d29ef72c1","type":"OS","status":"PENDING"}]' - stage: 'agent vuln_cves remove by status' - use_regex: "yes" - - - input: 'agent 000 sql SELECT distinct status FROM vuln_cves' - output: 'ok [{"status":"VALID"}]' - stage: 'agent vuln_cves checking remove by status' - - - input: 'agent 000 vuln_cves insert {"name":"test package", - "version":"1.0", - "architecture":"x86", - "cve":"CVE-2021-1002", - "reference":"777fef8cc434b597769d102361af718d29ef72c1", - "type":"OS", - "status":"PENDING", - "check_pkg_existence":true, - "severity":"Low", - "cvss2_score":3.2, - "cvss3_score":2.1}' - output: 'ok {"action":"INSERT","status":"SUCCESS"}' - stage: "agent vuln_cves insert with spaces in json payload and the test package exist in sys_programs again" - - - input: 'agent 000 sql SELECT distinct status FROM vuln_cves' - output: 'ok [{"status":"PENDING"},{"status":"VALID"}]' - stage: "agent vuln_cves checking status" - - - input: 'agent 000 vuln_cves update_status {"old_status":"*", - "new_status":"OBSOLETE"}' - output: 'ok' - stage: "agent vuln_cves update all status" - - - input: 'agent 000 sql SELECT distinct status FROM vuln_cves' - output: 'ok [{"status":"OBSOLETE"}]' - stage: 'agent vuln_cves checking update all status' - - - input: 'agent 000 vuln_cves remove {"status":"OBSOLETE"}' - output: 'ok [{"name":"test_name","version":"1.0","architecture":"x64","cve":"CVE-2021-0001","detection_time":"*","cvss2_score":0,"cvss3_score":0,"reference":"03c06c4f118618400772367b1cf7e73ce0178e02","type":"PACKAGE","status":"OBSOLETE"},{"name":"test_package","version":"1.0","architecture":"x86","cve":"CVE-2021-1001","detection_time":"*","severity":"Medium","cvss2_score":5,"cvss3_score":6.1,"reference":"03c06c4f118618400772367b1cf7e73ce0178e02","type":"PACKAGE","status":"OBSOLETE"},{"name":"test_package2","version":"3.0","architecture":"x86","cve":"CVE-2021-1001","detection_time":"*","severity":"Untriaged","cvss2_score":0,"cvss3_score":0,"reference":"99efe684b5ff4646b3c754de46cb6a9cbee9fbaa","type":"PACKAGE","status":"OBSOLETE"},{"name":"test_package2","version":"3.0","architecture":"x86","cve":"CVE-2021-1002","detection_time":"*","severity":"High","cvss2_score":8.2,"cvss3_score":9.35,"reference":"99efe684b5ff4646b3c754de46cb6a9cbee9fbaa","type":"PACKAGE","status":"OBSOLETE"},{"name":"test package","version":"1.0","architecture":"x86","cve":"CVE-2021-1002","detection_time":"*","severity":"Low","cvss2_score":3.2,"cvss3_score":2.1,"reference":"777fef8cc434b597769d102361af718d29ef72c1","type":"OS","status":"OBSOLETE"}]' - stage: 'agent vuln_cves remove by status to clear vuln_cve table' - use_regex: "yes" - - - input: 'agent 000 sql SELECT * FROM vuln_cves' - output: 'ok []' - stage: "agent vuln_cve checking empty table again" - name: 'Not existing agent' description: 'Check messages from not registered agents.' @@ -223,7 +9,7 @@ stage: 'Syscheck query to a non-existing agent' - name: "Agents' OS table: sys_osinfo" - description: "It checks the commands get, set and set_triaged" + description: "It checks the commands get and set" test_case: - input: 'agent 000 sql DELETE FROM sys_osinfo' @@ -239,16 +25,8 @@ stage: "agent sys_osinfo set information" - input: 'agent 000 osinfo get' - output: 'ok [{"scan_id":0,"scan_time":"2021/04/08 10:00:00","hostname":"focal","architecture":"x86_64","os_name":"Ubuntu","os_version":"20.04.2 LTS (Focal Fossa)","os_codename":"focal","os_major":"20","os_minor":"04","os_patch":"2","os_build":"1","os_platform":"ubuntu","sysname":"Linux","release":"5.4.0-70-generic","version":"#78-Ubuntu SMP Thu Apr 08 10:00:00 UTC 2021","os_release":"1","checksum":"legacy","triaged":0,"reference":"54d5344c8f49eae38d81651495227c5080755b45"}]' + output: 'ok [{"scan_id":0,"scan_time":"2021/04/08 10:00:00","hostname":"focal","architecture":"x86_64","os_name":"Ubuntu","os_version":"20.04.2 LTS (Focal Fossa)","os_codename":"focal","os_major":"20","os_minor":"04","os_patch":"2","os_build":"1","os_platform":"ubuntu","sysname":"Linux","release":"5.4.0-70-generic","version":"#78-Ubuntu SMP Thu Apr 08 10:00:00 UTC 2021","os_release":"1","checksum":"legacy","reference":"54d5344c8f49eae38d81651495227c5080755b45"}]' stage: "agent sys_osinfo getting information" - - - input: 'agent 000 osinfo set_triaged' - output: 'ok' - stage: "agent sys_osinfo set triaged" - - - input: 'agent 000 sql SELECT triaged FROM sys_osinfo WHERE triaged = 1' - output: 'ok [{"triaged":1}]' - stage: "agent sys_osinfo checking triaged" - input: 'agent 000 sql DELETE FROM sys_osinfo' output: "ok []" @@ -309,15 +87,6 @@ input: 'agent 003 sql UPDATE sync_info SET last_attempt = 1, last_completion = 1 where component = "syscollector-packages"' output: 'ok []' stage: "agent sync_info set synced" - - - input: 'agent 003 sql UPDATE sys_programs SET triaged = 1 WHERE name = "test_rpm_pkg"' - output: 'ok []' - stage: "agent sys_programs set package as triaged" - - - input: 'agent 003 package get not_triaged' - output: ['due {"name":"test_deb_pkg","version":"1.0.0","architecture":"amd64","vendor":"Wazuh wazuh@wazuh.com","item_id":"1"}', - 'ok {"status":"SUCCESS"}'] - stage: "agent sys_programs getting not triaged packages" - input: 'agent 003 package get' output: ['due {"name":"test_deb_pkg","version":"1.0.0","architecture":"amd64","vendor":"Wazuh wazuh@wazuh.com","item_id":"1"}', diff --git a/tests/integration/test_wazuh_db/data/global/wazuh_db_backup_command.yaml b/tests/integration/test_wazuh_db/data/global/wazuh_db_backup_command.yaml index 55a3a5f440..39cd530684 100644 --- a/tests/integration/test_wazuh_db/data/global/wazuh_db_backup_command.yaml +++ b/tests/integration/test_wazuh_db/data/global/wazuh_db_backup_command.yaml @@ -84,6 +84,6 @@ - backups_amount: 1 restore: true - snapshot: + snapshot: None save_pre_restore: false - restore_response: err Invalid JSON syntax \ No newline at end of file + restore_response: err Invalid JSON syntax diff --git a/tests/integration/test_wazuh_db/data/wazuh_db_backups_conf.yaml b/tests/integration/test_wazuh_db/data/wazuh_db_backups_conf.yaml index c68393236e..0603bdca49 100644 --- a/tests/integration/test_wazuh_db/data/wazuh_db_backups_conf.yaml +++ b/tests/integration/test_wazuh_db/data/wazuh_db_backups_conf.yaml @@ -1,4 +1,6 @@ - tags: + - wazuh_db + - wdb_socket apply_to_modules: - test_db_backup - test_wdb_backup_configs diff --git a/tests/integration/test_wazuh_db/test_agent_database_version.py b/tests/integration/test_wazuh_db/test_agent_database_version.py index e3f2b0689e..54b989d212 100644 --- a/tests/integration/test_wazuh_db/test_agent_database_version.py +++ b/tests/integration/test_wazuh_db/test_agent_database_version.py @@ -9,7 +9,7 @@ pytestmark = [TIER0, LINUX, SERVER] # Variables -expected_database_version = '12' +expected_database_version = '13' # Fixtures @@ -45,7 +45,7 @@ def test_agent_database_version(restart_wazuh_daemon, remove_agents): - Verify that database version is the expected one. expected_output: - - Database version: 12 + - Database version: 13 tags: - wazuh_db diff --git a/tests/integration/test_wazuh_db/test_wazuh_db.py b/tests/integration/test_wazuh_db/test_wazuh_db.py index 5e2d799465..b8f94d858a 100644 --- a/tests/integration/test_wazuh_db/test_wazuh_db.py +++ b/tests/integration/test_wazuh_db/test_wazuh_db.py @@ -300,10 +300,10 @@ def pre_insert_packages(): for pkg_n in range(PACKAGES_NUMBER): command = f"agent 000 sql INSERT OR REPLACE INTO sys_programs \ (scan_id,scan_time,format,name,priority,section,size,vendor,install_time,version,\ - architecture,multiarch,source,description,location,triaged,cpe,msu_name,checksum,item_id)\ + architecture,multiarch,source,description,location,cpe,msu_name,checksum,item_id)\ VALUES(0,'2021/04/07 22:00:00','deb','test_package_{pkg_n}','optional','utils',{random.randint(200,1000)},\ 'Wazuh wazuh@wazuh.com',NULL,'{random.randint(1,10)}.0.0','all',NULL,NULL,'Test package {pkg_n}',\ - NULL,0,NULL,NULL,'{random.getrandbits(128)}','{random.getrandbits(128)}')" + NULL,NULL,NULL,'{random.getrandbits(128)}','{random.getrandbits(128)}')" receiver_sockets[0].send(command, size=True) response = receiver_sockets[0].receive(size=True).decode() data = response.split()