From db2e9fa2082b83cb6b4d99d29e3975f3460b3287 Mon Sep 17 00:00:00 2001 From: jitendracandela <78074038+jitendracandela@users.noreply.github.com> Date: Tue, 11 Jul 2023 17:28:09 +0530 Subject: [PATCH] Wifi 12468 (#833) * Added 4 Security Services Rest API Tests cases Signed-off-by: jitendracandela * Added test cases for security_profiles, Authenticator QR Code Signed-off-by: jitendracandela * Added CRUD User and CRUD subuser test cases Signed-off-by: jitendracandela * Removed print Signed-off-by: jitendracandela * Added headers in PUT method Signed-off-by: jitendracandela * Removed systemConfiguration API test case Signed-off-by: jitendracandela * Added ow_sanity_lf marker only in sanity test cases Signed-off-by: jitendracandela --------- Signed-off-by: jitendracandela --- libs/tip_2x/controller.py | 2 +- .../ucentral_gateway/test_securityservice.py | 215 +++++++++++++++++- 2 files changed, 208 insertions(+), 9 deletions(-) diff --git a/libs/tip_2x/controller.py b/libs/tip_2x/controller.py index 82d7c549b..c8bf9dd09 100644 --- a/libs/tip_2x/controller.py +++ b/libs/tip_2x/controller.py @@ -99,7 +99,7 @@ class ConfigureController: resp = requests.post(uri, params=params, data=payload, headers=self.make_headers(), verify=False, timeout=120) elif method == "PUT": - resp = requests.put(uri, params=params, data=payload, verify=False, timeout=120) + resp = requests.put(uri, params=params, data=payload, headers=self.make_headers(), verify=False, timeout=120) elif method == "DELETE": resp = requests.delete(uri, headers=self.make_headers(), params=params, verify=False, timeout=120) diff --git a/tests/controller_tests/ucentral_gateway/test_securityservice.py b/tests/controller_tests/ucentral_gateway/test_securityservice.py index 63f78742f..a3dc9ddb4 100644 --- a/tests/controller_tests/ucentral_gateway/test_securityservice.py +++ b/tests/controller_tests/ucentral_gateway/test_securityservice.py @@ -3,13 +3,14 @@ 2.x Security Services Rest API Tests: Test Login, Logout API's """ +import logging +import time import pytest import json import allure @pytest.mark.uc_sanity -@pytest.mark.ow_sanity_lf @pytest.mark.ow_sdk_tests @pytest.mark.ow_sdk_load_tests @pytest.mark.owsec_api_tests @@ -21,6 +22,7 @@ class TestUcentralSecService(object): @allure.testcase(name="WIFI-3450", url="https://telecominfraproject.atlassian.net/browse/WIFI-3450") @pytest.mark.system_endpoints + @pytest.mark.ow_sanity_lf def test_secservice_system_endpoints(self, get_target_object): """ Test the system endpoints to verify list of services that are present @@ -28,12 +30,12 @@ class TestUcentralSecService(object): """ resp = get_target_object.controller_library_object.request("sec", "systemEndpoints", "GET", None, None) body = resp.url + "," + str(resp.status_code) + ',' + resp.text - #allure.attach(name="security systemEndpoints", body=body) + # allure.attach(name="security systemEndpoints", body=body) if resp.status_code != 200: assert False services = json.loads(resp.text) - #print(services) + # print(services) if 'endpoints' not in services: assert False @@ -61,6 +63,7 @@ class TestUcentralSecService(object): @allure.testcase(name="WIFI-3451", url="https://telecominfraproject.atlassian.net/browse/WIFI-3451") @pytest.mark.security_versions + @pytest.mark.ow_sanity_lf def test_secservice_get_version(self, get_target_object): """ Test the system endpoint to verify the version of the service @@ -70,18 +73,19 @@ class TestUcentralSecService(object): params = {'command': 'info'} resp = get_target_object.controller_library_object.request("sec", "system", "GET", params, None) body = resp.url + "," + str(resp.status_code) + ',' + resp.text - #allure.attach(name="security get version result", body=body) + # allure.attach(name="security get version result", body=body) if resp.status_code != 200: assert False system = json.loads(resp.text) - #print(system) + # print(system) if 'version' not in system: assert False if system['version'] == '': assert False @allure.title("Get Security Service Uptime") + @pytest.mark.ow_sanity_lf def test_secservice_get_uptime(self, get_target_object): """ Test the system endpoint to verify the uptime of the service @@ -91,11 +95,11 @@ class TestUcentralSecService(object): params = {'command': 'info'} resp = get_target_object.controller_library_object.request("sec", "system", "GET", params, None) body = resp.url + "," + str(resp.status_code) + ',' + resp.text - #allure.attach(name="security get uptime", body=body) + # allure.attach(name="security get uptime", body=body) if resp.status_code != 200: assert False system = json.loads(resp.text) - #print(system) + # print(system) if 'uptime' not in system: assert False @@ -106,4 +110,199 @@ class TestUcentralSecService(object): assert False if system['start'] == '': - assert False \ No newline at end of file + assert False + + @allure.title("Allows any microservice to validate a token and get security policy for a specific user") + @allure.testcase(name="WIFI-12608", + url="https://telecominfraproject.atlassian.net/browse/WIFI-12608") + @pytest.mark.validatetoken + def test_validatetoken(self, get_target_object): + """ + Allows any microservice to validate a token and get security policy for a specific user + Unique marker:pytest -m "validatetoken" + """ + print("Token: ", get_target_object.controller_library_object.access_token) + params = {'token': get_target_object.controller_library_object.access_token} + resp = get_target_object.controller_library_object.request("sec", "validateToken", "GET", params, None) + + if resp.status_code != 200: + assert False + + # @allure.title("Get system configuration items") + # @allure.testcase(name="WIFI-12609", + # url="https://telecominfraproject.atlassian.net/browse/WIFI-12609") + # @pytest.mark.system_configuration_items + # def test_system_configuration_items(self, get_target_object): + # """ + # Get system configuration items + # Unique marker:pytest -m "system_configuration_items" + # """ + # params = {'entries': "element1"} + # resp = get_target_object.controller_library_object.request("sec", "systemConfiguration", "GET", params, None) + # + # if resp.status_code != 200: + # assert False + + @allure.title("Get List of existing users(User Management)") + @allure.testcase(name="WIFI-12605", + url="https://telecominfraproject.atlassian.net/browse/WIFI-12605") + @pytest.mark.list_of_existing_users_user_management + def test_list_of_existing_users_user_management(self, get_target_object): + """ + Retrieve a list of existing users as well as some information about them + Unique marker:pytest -m "list_of_existing_users_user_management" + """ + resp = get_target_object.controller_library_object.request("sec", "users", "GET", None, None) + + if resp.status_code != 200: + assert False + + @allure.title("CRUD User") + @allure.testcase(name="WIFI-12632", + url="https://telecominfraproject.atlassian.net/browse/WIFI-12632") + @pytest.mark.crud_user + def test_crud_user(self, get_target_object): + """ + CRUD User + Unique marker:pytest -m "crud_user" + """ + payload = { + "id": "0", + "name": "Default User", + "description": "Testing through Automation", + "email": "testautomation@telecominfraproject.com", + "validated": True, + "validationEmail": "testautomation@telecominfraproject.com", + "changePassword": True, + "currentPassword": "OpenWifi%123", + "userRole": "root" + } + # Delete if user already exist + resp = get_target_object.controller_library_object.request("sec", "users", "GET", None, None) + resp = resp.json() + all_users = resp["users"] + for i in all_users: + if i["email"] == payload["email"]: + logging.info("User already exist") + resp = get_target_object.controller_library_object.request("sec", "user/" + str(i["id"]), "DELETE", + None, None) + time.sleep(2) + if resp.status_code != 200: + assert False + + # Create a single user + payload = json.dumps(payload) + resp = get_target_object.controller_library_object.request("sec", "user/0", "POST", None, payload) + if resp.status_code != 200: + assert False + time.sleep(2) + resp = resp.json() + user_id = resp['id'] + # Retrieve the information for a single user + resp = get_target_object.controller_library_object.request("sec", "user/" + str(user_id), "GET", None, None) + if resp.status_code != 200: + assert False + # Modify a single user + edited_payload = { + "name": "Modified name" + } + edited_payload = json.dumps(edited_payload) + resp = get_target_object.controller_library_object.request("sec", "user/" + str(user_id), "PUT", None, + edited_payload) + if resp.status_code != 200: + assert False + + # Delete a single user + resp = get_target_object.controller_library_object.request("sec", "user/" + str(user_id), "DELETE", None, + None) + if resp.status_code != 200: + assert False + + @allure.title("Get the Authenticator QR Code") + @allure.testcase(name="WIFI-12633", + url="https://telecominfraproject.atlassian.net/browse/WIFI-12633") + @pytest.mark.authenticator_qr_code + def test_authenticator_qr_code(self, get_target_object): + """ + Get the Authenticator QR Code + Unique marker:pytest -m "authenticator_qr_code" + """ + params = {'reset': False} + resp = get_target_object.controller_library_object.request("sec", "totp", "GET", params, None) + + if resp.status_code != 200: + assert False + + @allure.title("Get List of existing users(Subscribers)") + @allure.testcase(name="WIFI-12606", + url="https://telecominfraproject.atlassian.net/browse/WIFI-12606") + @pytest.mark.list_of_existing_users_subscribers + def test_list_of_existing_users_subscribers(self, get_target_object): + """ + Retrieve a list of existing users as well as some information about them + Unique marker:pytest -m "list_of_existing_users_subscribers" + """ + resp = get_target_object.controller_library_object.request("sec", "subusers", "GET", None, None) + + if resp.status_code != 200: + assert False + + @allure.title("CRUD subuser") + @allure.testcase(name="WIFI-12643", + url="https://telecominfraproject.atlassian.net/browse/WIFI-12643") + @pytest.mark.crud_subuser + def test_crud_subuser(self, get_target_object): + """ + CRUD subuser + Unique marker:pytest -m "crud_subuser" + """ + payload = { + "id": "0", + "name": "Default User", + "description": "Testing through Automation", + "email": "testautomation@telecominfraproject.com", + "validated": True, + "validationEmail": "testautomation@telecominfraproject.com", + "changePassword": False, + "currentPassword": "OpenWifi%123", + "userRole": "subscriber" + } + # Delete if user already exist + resp = get_target_object.controller_library_object.request("sec", "subusers", "GET", None, None) + resp = resp.json() + all_users = resp["users"] + for i in all_users: + if i["email"] == payload["email"]: + logging.info("User already exist") + resp = get_target_object.controller_library_object.request("sec", "subuser/" + str(i["id"]), "DELETE", + None, None) + time.sleep(2) + if resp.status_code != 200: + assert False + # Create a single user + payload = json.dumps(payload) + resp = get_target_object.controller_library_object.request("sec", "subuser/0", "POST", None, payload) + if resp.status_code != 200: + assert False + time.sleep(2) + resp = resp.json() + user_id = resp['id'] + # Retrieve the information for a single user + resp = get_target_object.controller_library_object.request("sec", "subuser/" + str(user_id), "GET", None, None) + if resp.status_code != 200: + assert False + # Modify a single user + edited_payload = { + "name": "Modified name" + } + edited_payload = json.dumps(edited_payload) + resp = get_target_object.controller_library_object.request("sec", "subuser/" + str(user_id), "PUT", None, + edited_payload) + if resp.status_code != 200: + assert False + + # Delete a single user + resp = get_target_object.controller_library_object.request("sec", "subuser/" + str(user_id), "DELETE", None, + None) + if resp.status_code != 200: + assert False