Skip to content

Commit

Permalink
feat(#3112): add API statistics format test
Browse files Browse the repository at this point in the history
  • Loading branch information
juliamagan authored Jan 25, 2023
1 parent 7fabec9 commit a9b814d
Show file tree
Hide file tree
Showing 19 changed files with 2,714 additions and 11 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Release report: TBD

### Added

- Add integration test to check statistics format ([#3813](https://github.com/wazuh/wazuh-qa/pull/3813)) \- (Framework + Tests)
- Add new test to check vulnerable packages with triaged null([#3587](https://github.com/wazuh/wazuh-qa/pull/3587)) \- (Framework + Tests)
- Add new tests analysid handling of invalid/empty rule signature IDs ([#3649]
(https://github.com/wazuh/wazuh-qa/pull/3649)) \- (Framework + Tests)
- Add new tests analysid handling of invalid/empty rule signature IDs ([#3649](https://github.com/wazuh/wazuh-qa/pull/3649)) \- (Framework + Tests)
- Add integration test to check agent database version ([#3768](https://github.com/wazuh/wazuh-qa/pull/3768)) \- (Tests)
- Fix Yara and VirusTotal E2E basic usage tests ([#3660](https://github.com/wazuh/wazuh-qa/pull/3660))
- Add new test to check if syslog message are parsed correctrly in the `archives.json` file ([#3609](https://github.com/wazuh/wazuh-qa/pull/3609)) \- (Framework + Tests)
Expand Down
15 changes: 8 additions & 7 deletions deps/wazuh_testing/wazuh_testing/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def compare_config_api_response(configuration, section):
def get_manager_configuration(section=None, field=None):
"""Get Wazuh manager configuration response from API using GET /manager/configuration
References: https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/api.controllers.manager_controller.get_configuration
References: https://documentation.wazuh.com/current/user-manual/api/reference.html#operation/
api.controllers.manager_controller.get_configuration
Args:
section (str): wazuh configuration section, E.g: "active-response", "ruleset"...
Expand Down Expand Up @@ -180,8 +181,8 @@ def wait_until_api_ready(protocol=API_PROTOCOL, host=API_HOST, port=API_PORT, us
get_token_login_api(protocol, host, port, user, password, login_endpoint, timeout, attempts, 1)


def make_api_call(port=55000, method='GET', endpoint='/', headers=None, request_json=None, params=None, verify=False,
token=None):
def make_api_call(manager_address=API_HOST, port=55000, method='GET', endpoint='/', headers=None, request_json=None,
params=None, verify=False, token=None):
"""Make an API call
Args:
Expand All @@ -206,16 +207,16 @@ def make_api_call(port=55000, method='GET', endpoint='/', headers=None, request_

response = None
if method == 'POST':
response = requests.post(f'https://localhost:{port}{endpoint}', headers=headers, json=request_json,
response = requests.post(f'https://{manager_address}:{port}{endpoint}', headers=headers, json=request_json,
params=params, verify=verify)
elif method == 'DELETE':
response = requests.delete(f'https://localhost:{port}{endpoint}', headers=headers, json=request_json,
response = requests.delete(f'https://{manager_address}:{port}{endpoint}', headers=headers, json=request_json,
params=params, verify=verify)
elif method == 'PUT':
response = requests.put(f'https://localhost:{port}{endpoint}', headers=headers, json=request_json,
response = requests.put(f'https://{manager_address}:{port}{endpoint}', headers=headers, json=request_json,
params=params, verify=verify)
else:
response = requests.get(f'https://localhost:{port}{endpoint}', headers=headers, json=request_json,
response = requests.get(f'https://{manager_address}:{port}{endpoint}', headers=headers, json=request_json,
params=params, verify=verify)
return response

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@

path = os.path.dirname(os.path.abspath(__file__))
rbac_sql_path = os.path.join(WAZUH_PATH, 'api', 'configuration', 'security', 'rbac.db')
con = sqlite3.connect(rbac_sql_path)
cur = con.cursor()

# Configurations

Expand All @@ -88,13 +86,17 @@ def get_configuration(request):

def extra_configuration_before_yield():
# Add a new user in the RBAC database.
con = sqlite3.connect(rbac_sql_path)
cur = con.cursor()
with open(os.path.join(test_data_path, 'schema_add_user.sql')) as f:
sql = f.read()
cur.executescript(sql)


def extra_configuration_after_yield():
# Delete the test_user created in the RBAC database.
con = sqlite3.connect(rbac_sql_path)
cur = con.cursor()
with open(os.path.join(test_data_path, 'schema_delete_user.sql')) as f:
sql = f.read()
cur.executescript(sql)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
import requests
from wazuh_testing import api

# Marks
pytestmark = [pytest.mark.server]


# Tests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
import pytest
import requests

# Marks
pytestmark = [pytest.mark.server]


# Tests

Expand Down
3 changes: 3 additions & 0 deletions tests/integration/test_api/test_rbac/test_add_old_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
import pytest
from wazuh_testing.api import get_security_resource_information

# Marks
pytestmark = [pytest.mark.server]

# Variables
user_id, role_id, policy_id, rule_id = None, None, None, None

Expand Down
3 changes: 3 additions & 0 deletions tests/integration/test_api/test_rbac/test_admin_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
import pytest
import requests

# Marks
pytestmark = [pytest.mark.server]


@pytest.fixture(scope='module')
def get_configuration():
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/test_api/test_rbac/test_policy_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
import requests
from wazuh_testing.api import get_security_resource_information

# Marks

pytestmark = [pytest.mark.server]

# Variables
user_id, role_id, policy_id, rule_id = None, None, None, None
policy_positions = list()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
import pytest
from wazuh_testing.api import get_security_resource_information

# Marks
pytestmark = [pytest.mark.server]

# Variables
user_id, role_id, policy_id, rule_id = None, None, None, None

Expand Down
3 changes: 3 additions & 0 deletions tests/integration/test_api/test_rbac/test_remove_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
import pytest
from wazuh_testing.api import get_security_resource_information

# Marks
pytestmark = [pytest.mark.server]

# Variables
user_id, role_id, policy_id, rule_id = None, None, None, None

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- sections:
- section: global
elements:
- limits:
elements:
- eps:
elements:
- maximum:
value: 500
- timeframe:
value: 10
Loading

0 comments on commit a9b814d

Please sign in to comment.