From d06427d5357ee53f89c88149c335c38f3039f2fd Mon Sep 17 00:00:00 2001 From: Aiden Baker Date: Tue, 3 Sep 2024 13:52:34 -0400 Subject: [PATCH 1/3] Removed REST calls --- tests/api2/test_account.py | 74 +++++++------------------------------- 1 file changed, 12 insertions(+), 62 deletions(-) diff --git a/tests/api2/test_account.py b/tests/api2/test_account.py index b22eeabb08646..b16e44cde9564 100644 --- a/tests/api2/test_account.py +++ b/tests/api2/test_account.py @@ -1,6 +1,3 @@ -import os -import sys - import pytest from middlewared.test.integration.assets.account import user, group @@ -8,12 +5,8 @@ from middlewared.test.integration.utils import call, client from middlewared.test.integration.utils.audit import expect_audit_method_calls -sys.path.append(os.getcwd()) -from functions import DELETE, POST, PUT - -@pytest.mark.parametrize("api", ["ws", "rest"]) -def test_create_account_audit(api): +def test_create_account_audit(): user_id = None try: with expect_audit_method_calls([{ @@ -36,21 +29,13 @@ def test_create_account_audit(api): "home": "/nonexistent", "password": "password", } - if api == "ws": - user_id = call("user.create", payload) - elif api == "rest": - result = POST(f"/user/", payload) - assert result.status_code == 200, result.text - user_id = result.json() - else: - raise ValueError(api) + user_id = call("user.create", payload) finally: if user_id is not None: call("user.delete", user_id) -@pytest.mark.parametrize("api", ["ws", "rest"]) -def test_update_account_audit(api): +def test_update_account_audit(): with user({ "username": "user2", "full_name": "user2", @@ -62,17 +47,10 @@ def test_update_account_audit(api): "params": [u["id"], {}], "description": "Update user user2", }]): - if api == "ws": - call("user.update", u["id"], {}) - elif api == "rest": - result = PUT(f"/user/id/{u['id']}", {}) - assert result.status_code == 200, result.text - else: - raise ValueError(api) + call("user.update", u["id"], {}) -@pytest.mark.parametrize("api", ["ws", "rest"]) -def test_delete_account_audit(api): +def test_delete_account_audit(): with user({ "username": "user2", "full_name": "user2", @@ -84,17 +62,10 @@ def test_delete_account_audit(api): "params": [u["id"], {}], "description": "Delete user user2", }]): - if api == "ws": - call("user.delete", u["id"], {}) - elif api == "rest": - result = DELETE(f"/user/id/{u['id']}") - assert result.status_code == 200, result.text - else: - raise ValueError(api) + call("user.delete", u["id"], {}) -@pytest.mark.parametrize("api", ["ws", "rest"]) -def test_create_group_audit(api): +def test_create_group_audit(): group_id = None try: with expect_audit_method_calls([{ @@ -109,21 +80,13 @@ def test_create_group_audit(api): payload = { "name": "group2", } - if api == "ws": - group_id = call("group.create", payload) - elif api == "rest": - result = POST(f"/group/", payload) - assert result.status_code == 200, result.text - group_id = result.json() - else: - raise ValueError(api) + group_id = call("group.create", payload) finally: if group_id is not None: call("group.delete", group_id) -@pytest.mark.parametrize("api", ["ws", "rest"]) -def test_update_group_audit(api): +def test_update_group_audit(): with group({ "name": "group2", }) as g: @@ -132,17 +95,10 @@ def test_update_group_audit(api): "params": [g["id"], {}], "description": "Update group group2", }]): - if api == "ws": - call("group.update", g["id"], {}) - elif api == "rest": - result = PUT(f"/group/id/{g['id']}", {}) - assert result.status_code == 200, result.text - else: - raise ValueError(api) + call("group.update", g["id"], {}) -@pytest.mark.parametrize("api", ["ws", "rest"]) -def test_delete_group_audit(api): +def test_delete_group_audit(): with group({ "name": "group2", }) as g: @@ -151,13 +107,7 @@ def test_delete_group_audit(api): "params": [g["id"], {}], "description": "Delete group group2", }]): - if api == "ws": - call("group.delete", g["id"], {}) - elif api == "rest": - result = DELETE(f"/group/id/{g['id']}") - assert result.status_code == 200, result.text - else: - raise ValueError(api) + call("group.delete", g["id"], {}) def test_update_account_using_api_key(): From 401217951e8ba9aafbed2124514bbc54227b2d89 Mon Sep 17 00:00:00 2001 From: Aiden Baker Date: Wed, 4 Sep 2024 08:38:59 -0400 Subject: [PATCH 2/3] Starting cleanup --- tests/api2/test_550_vmware.py | 46 +++++++++++++++-------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/tests/api2/test_550_vmware.py b/tests/api2/test_550_vmware.py index b579ecc971e80..f691d16a5fe71 100644 --- a/tests/api2/test_550_vmware.py +++ b/tests/api2/test_550_vmware.py @@ -1,16 +1,7 @@ -#!/usr/bin/env python3 - -# Author: Eric Turgeon -# License: BSD - -import pytest import sys import os -from pytest_dependency import depends -apifolder = os.getcwd() -sys.path.append(apifolder) -from functions import GET, POST, SSH_TEST -from auto_config import user, password + +import pytest try: Reason = 'VMWARE credentials credential is missing' @@ -26,19 +17,20 @@ def test_01_get_vmware_query(): assert isinstance(results.json(), list) is True -if vmw_credentials: - def test_02_create_vmware(): - payload = { - 'hostname': VMWARE_HOST, - 'username': VMWARE_USERNAME, - 'password': VMWARE_PASSWORD - } - results = POST('/vmware/get_datastores/', payload) - assert results.status_code == 200, results.text - assert isinstance(results.json(), list) is True, results.text - - def test_03_verify_vmware_get_datastore_do_not_leak_password(request): - cmd = f"grep -R \"{os.environ['VMWARE_PASSWORD']}\" " \ - "/var/log/middlewared.log" - results = SSH_TEST(cmd, user, password) - assert results['result'] is False, str(results['output']) +@pytest.mark.skipif(not vmw_credentials, reason='Test only valid with VM credentials') +def test_02_create_vmware(): + payload = { + 'hostname': VMWARE_HOST, + 'username': VMWARE_USERNAME, + 'password': VMWARE_PASSWORD + } + results = POST('/vmware/get_datastores/', payload) + assert results.status_code == 200, results.text + assert isinstance(results.json(), list) is True, results.text + +@pytest.mark.skipif(not vmw_credentials, reason='Test only valid with VM credentials') +def test_03_verify_vmware_get_datastore_do_not_leak_password(request): + cmd = f"grep -R \"{os.environ['VMWARE_PASSWORD']}\" " \ + "/var/log/middlewared.log" + results = SSH_TEST(cmd, user, password) + assert results['result'] is False, str(results['output']) From 11eb9578e97fb635ab8862f27af49cfc7481ca86 Mon Sep 17 00:00:00 2001 From: Aiden Baker Date: Wed, 4 Sep 2024 08:49:15 -0400 Subject: [PATCH 3/3] Revert "Starting cleanup" This reverts commit 401217951e8ba9aafbed2124514bbc54227b2d89. --- tests/api2/test_550_vmware.py | 46 ++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/tests/api2/test_550_vmware.py b/tests/api2/test_550_vmware.py index f691d16a5fe71..b579ecc971e80 100644 --- a/tests/api2/test_550_vmware.py +++ b/tests/api2/test_550_vmware.py @@ -1,7 +1,16 @@ -import sys -import os +#!/usr/bin/env python3 + +# Author: Eric Turgeon +# License: BSD import pytest +import sys +import os +from pytest_dependency import depends +apifolder = os.getcwd() +sys.path.append(apifolder) +from functions import GET, POST, SSH_TEST +from auto_config import user, password try: Reason = 'VMWARE credentials credential is missing' @@ -17,20 +26,19 @@ def test_01_get_vmware_query(): assert isinstance(results.json(), list) is True -@pytest.mark.skipif(not vmw_credentials, reason='Test only valid with VM credentials') -def test_02_create_vmware(): - payload = { - 'hostname': VMWARE_HOST, - 'username': VMWARE_USERNAME, - 'password': VMWARE_PASSWORD - } - results = POST('/vmware/get_datastores/', payload) - assert results.status_code == 200, results.text - assert isinstance(results.json(), list) is True, results.text - -@pytest.mark.skipif(not vmw_credentials, reason='Test only valid with VM credentials') -def test_03_verify_vmware_get_datastore_do_not_leak_password(request): - cmd = f"grep -R \"{os.environ['VMWARE_PASSWORD']}\" " \ - "/var/log/middlewared.log" - results = SSH_TEST(cmd, user, password) - assert results['result'] is False, str(results['output']) +if vmw_credentials: + def test_02_create_vmware(): + payload = { + 'hostname': VMWARE_HOST, + 'username': VMWARE_USERNAME, + 'password': VMWARE_PASSWORD + } + results = POST('/vmware/get_datastores/', payload) + assert results.status_code == 200, results.text + assert isinstance(results.json(), list) is True, results.text + + def test_03_verify_vmware_get_datastore_do_not_leak_password(request): + cmd = f"grep -R \"{os.environ['VMWARE_PASSWORD']}\" " \ + "/var/log/middlewared.log" + results = SSH_TEST(cmd, user, password) + assert results['result'] is False, str(results['output'])