From c260c784eb5f7cf575ecd871b495f342816198d3 Mon Sep 17 00:00:00 2001 From: MariusBaldovin Date: Thu, 29 Aug 2024 15:36:08 +0100 Subject: [PATCH 1/5] updated delete device endpoint to respond 404 if report is not found --- framework/python/src/api/api.py | 8 ++++++++ framework/python/src/core/testrun.py | 18 ++++++++---------- testing/api/test_api.py | 15 +++++++++------ 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/framework/python/src/api/api.py b/framework/python/src/api/api.py index 409884fd1..82b4762b7 100644 --- a/framework/python/src/api/api.py +++ b/framework/python/src/api/api.py @@ -465,6 +465,14 @@ async def delete_report(self, request: Request, response: Response): response.status_code = 404 return self._generate_msg(False, "Could not find device") + # Assign the reports folder path from testrun + reports_folder = self._testrun.get_reports_folder(device) + + # Check if reports folder exists + if not os.path.exists(reports_folder): + response.status_code = 404 + return self._generate_msg(False, "Report not found") + if self._testrun.delete_report(device, timestamp_formatted): return self._generate_msg(True, "Deleted report") diff --git a/framework/python/src/core/testrun.py b/framework/python/src/core/testrun.py index 8fe325774..977e97242 100644 --- a/framework/python/src/core/testrun.py +++ b/framework/python/src/core/testrun.py @@ -230,9 +230,7 @@ def _load_test_reports(self, device): device.clear_reports() # Locate reports folder - reports_folder = os.path.join(self._root_dir, - LOCAL_DEVICES_DIR, - device.device_folder, 'reports') + reports_folder = self.get_reports_folder(device) # Check if reports folder exists (device may have no reports) if not os.path.exists(reports_folder): @@ -275,18 +273,18 @@ def _load_test_reports(self, device): test_report.set_mac_addr(device.mac_addr) device.add_report(test_report) + def get_reports_folder(self, device): + """Return the reports folder path for the device""" + return os.path.join(self._root_dir, + LOCAL_DEVICES_DIR, + device.device_folder, 'reports') + def delete_report(self, device: Device, timestamp): LOGGER.debug(f'Deleting test report for device {device.model} ' + f'at {timestamp}') # Locate reports folder - reports_folder = os.path.join(self._root_dir, - LOCAL_DEVICES_DIR, - device.device_folder, 'reports') - - # Check if reports folder exists (device may have no reports) - if not os.path.exists(reports_folder): - return False + reports_folder = self.get_reports_folder(device) for report_folder in os.listdir(reports_folder): if report_folder == timestamp: diff --git a/testing/api/test_api.py b/testing/api/test_api.py index 49f894c86..0f5baae05 100644 --- a/testing/api/test_api.py +++ b/testing/api/test_api.py @@ -956,8 +956,8 @@ def test_delete_report_invalid_timestamp(empty_devices_dir, testrun, # pylint: d # Check if the correct error message returned assert "Incorrect timestamp format" in response["error"] -def test_delete_report_no_report(empty_devices_dir, testrun): # pylint: disable=W0613 - """Test delete report when report does not exist (404)""" +def test_delete_report_no_device(empty_devices_dir, testrun): # pylint: disable=W0613 + """Test delete report when device does not exist (404)""" # Payload to be deleted for a non existing device delete_data = { @@ -977,7 +977,10 @@ def test_delete_report_no_report(empty_devices_dir, testrun): # pylint: disable= # Check if "error" in response assert "error" in response -def test_delete_report_server_error(empty_devices_dir, testrun, # pylint: disable=W0613 + # Check if the correct error message returned + assert "Could not find device" in response["error"] + +def test_delete_report_no_report(empty_devices_dir, testrun, # pylint: disable=W0613 add_device, create_report_folder): """Test for delete report causing internal server error (500)""" @@ -1004,8 +1007,8 @@ def test_delete_report_server_error(empty_devices_dir, testrun, # pylint: disabl data=json.dumps(delete_data), timeout=5) - # Check if status code is 500 (Internal Server Error) - assert r.status_code == 500 + # Check if status code is 404 (not found) + assert r.status_code == 404 # Parse the JSON response response = r.json() @@ -1014,7 +1017,7 @@ def test_delete_report_server_error(empty_devices_dir, testrun, # pylint: disabl assert "error" in response # Check if the correct error message is returned - assert "Error occured whilst deleting report" in response["error"] + assert "Report not found" in response["error"] def test_get_report_success(empty_devices_dir, testrun, # pylint: disable=W0613 add_device, create_report_folder): From 62610dfbc8c9eb4f6a1f1d826a376d3985af1070 Mon Sep 17 00:00:00 2001 From: MariusBaldovin Date: Thu, 29 Aug 2024 15:50:22 +0100 Subject: [PATCH 2/5] fix test_delete_report_no_report --- testing/api/test_api.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/testing/api/test_api.py b/testing/api/test_api.py index 0f5baae05..e92c645ea 100644 --- a/testing/api/test_api.py +++ b/testing/api/test_api.py @@ -980,21 +980,11 @@ def test_delete_report_no_device(empty_devices_dir, testrun): # pylint: disable= # Check if the correct error message returned assert "Could not find device" in response["error"] -def test_delete_report_no_report(empty_devices_dir, testrun, # pylint: disable=W0613 - add_device, create_report_folder): - """Test for delete report causing internal server error (500)""" +def test_delete_report_no_report(empty_devices_dir, testrun, add_device): # pylint: disable=W0613 + """Test for delete report when report does not exist (404)""" # Load the device_name and mac_address from add_device fixture - device_name, mac_address = add_device() - - # Create the report folder and JSON file - create_report_folder(device_name, mac_address, TIMESTAMP) - - # Construct the device report path - device_directory = os.path.join(DEVICES_DIRECTORY, device_name) - - # Remove the folder and all its content before delete request - shutil.rmtree(device_directory) + _, mac_address = add_device() # Prepare the payload for the DELETE request delete_data = { From 3f530108cf5543767576c4cfe29561a8eb651e53 Mon Sep 17 00:00:00 2001 From: MariusBaldovin Date: Tue, 3 Sep 2024 12:55:00 +0100 Subject: [PATCH 3/5] fixed failing tests --- framework/python/src/api/api.py | 12 +- testing/api/devices/device_1.json | 55 +++++ testing/api/devices/device_2.json | 56 +++++ testing/api/test_api.py | 326 ++++++++---------------------- 4 files changed, 204 insertions(+), 245 deletions(-) create mode 100644 testing/api/devices/device_1.json create mode 100644 testing/api/devices/device_2.json diff --git a/framework/python/src/api/api.py b/framework/python/src/api/api.py index 22d712f90..84b4d88c0 100644 --- a/framework/python/src/api/api.py +++ b/framework/python/src/api/api.py @@ -260,6 +260,12 @@ async def start_testrun(self, request: Request, response: Response): device = self._session.get_device(body_json["device"]["mac_addr"]) + # Check if requested device is known in the device repository + if device is None: + response.status_code = status.HTTP_404_NOT_FOUND + return self._generate_msg( + False, "A device with that MAC address could not be found") + # Check if device is fully configured if device.status != "Valid": response.status_code = status.HTTP_400_BAD_REQUEST @@ -277,12 +283,6 @@ async def start_testrun(self, request: Request, response: Response): False, "Testrun cannot be started " + "whilst a test is running on another device") - # Check if requested device is known in the device repository - if device is None: - response.status_code = status.HTTP_404_NOT_FOUND - return self._generate_msg( - False, "A device with that MAC address could not be found") - device.firmware = body_json["device"]["firmware"] # Check if config has been updated (device interface not default) diff --git a/testing/api/devices/device_1.json b/testing/api/devices/device_1.json new file mode 100644 index 000000000..2de82408b --- /dev/null +++ b/testing/api/devices/device_1.json @@ -0,0 +1,55 @@ +{ + "status": "Valid", + "mac_addr": "00:1e:42:28:9e:4a", + "manufacturer": "Teltonika", + "model": "TRB140", + "type": "IoT Gateway", + "technology": "Hardware - Access Control", + "test_pack": "Device Qualification", + "additional_info": [ + { + "question": "What type of device is this?", + "answer": "IoT Gateway" + }, + { + "question": "Please select the technology this device falls into", + "answer": "Hardware - Access Control" + }, + { + "question": "Does your device process any sensitive information? ", + "answer": "Yes" + }, + { + "question": "Can all non-essential services be disabled on your device?", + "answer": "Yes" + }, + { + "question": "Is there a second IP port on the device?", + "answer": "Yes" + }, + { + "question": "Can the second IP port on your device be disabled?", + "answer": "Yes" + } + ], + "test_modules": { + "protocol": { + "enabled": true + }, + "services": { + "enabled": true + }, + "ntp": { + "enabled": true + }, + "tls": { + "enabled": true + }, + "connection": { + "enabled": true + }, + "dns": { + "enabled": true + } + } +} \ No newline at end of file diff --git a/testing/api/devices/device_2.json b/testing/api/devices/device_2.json new file mode 100644 index 000000000..e813bfc72 --- /dev/null +++ b/testing/api/devices/device_2.json @@ -0,0 +1,56 @@ +{ + "status": "Valid", + "mac_addr": "00:1e:42:35:73:c6", + "manufacturer": "Google", + "model": "First", + "type": "IoT Gateway", + "technology": "Hardware - Access Control", + "test_pack": "Device Qualification", + "additional_info": [ + { + "question": "What type of device is this?", + "answer": "IoT Gateway" + }, + { + "question": "Please select the technology this device falls into", + "answer": "Hardware - Access Control" + }, + { + "question": "Does your device process any sensitive information? ", + "answer": "Yes" + }, + { + "question": "Can all non-essential services be disabled on your device?", + "answer": "Yes" + }, + { + "question": "Is there a second IP port on the device?", + "answer": "Yes" + }, + { + "question": "Can the second IP port on your device be disabled?", + "answer": "Yes" + } + ], + + "test_modules": { + "protocol": { + "enabled": true + }, + "services": { + "enabled": false + }, + "ntp": { + "enabled": true + }, + "tls": { + "enabled": false + }, + "connection": { + "enabled": true + }, + "dns": { + "enabled": true + } + } +} \ No newline at end of file diff --git a/testing/api/test_api.py b/testing/api/test_api.py index e92c645ea..614b0af7f 100644 --- a/testing/api/test_api.py +++ b/testing/api/test_api.py @@ -44,6 +44,7 @@ CERTS_PATH = "testing/api/certificates" PROFILES_PATH = "testing/api/profiles" REPORTS_PATH = "testing/api/reports" +DEVICES_PATH = "testing/api/devices" BASELINE_MAC_ADDR = "02:42:aa:00:01:01" ALL_MAC_ADDR = "02:42:aa:00:00:01" @@ -362,20 +363,23 @@ def test_get_system_config(testrun): # pylint: disable=W0613 == api_config["network"]["internet_intf"] ) -def test_start_testrun_success(testing_devices, testrun): # pylint: disable=W0613 +def test_start_testrun_success(empty_devices_dir, testrun, add_device): # pylint: disable=W0613 """Test for testrun started successfully """ + _, mac_address = add_device() + # Payload with device details payload = {"device": { - "mac_addr": BASELINE_MAC_ADDR, - "firmware": "asd", - "test_modules": { - "dns": {"enabled": False}, - "connection": {"enabled": True}, - "ntp": {"enabled": False}, - "baseline": {"enabled": False}, - "nmap": {"enabled": False} - }}} + "mac_addr": mac_address, + "firmware": "test", + "test_modules": { + "protocol": { "enabled": True }, + "services": { "enabled": True }, + "ntp": { "enabled": True }, + "tls": { "enabled": True }, + "connection": { "enabled": True }, + "dns": { "enabled": True } + }}} # Send the post request r = requests.post(f"{API}/system/start", data=json.dumps(payload), timeout=10) @@ -413,20 +417,23 @@ def test_start_testrun_missing_device(testing_devices, testrun): # pylint: disab # Check if 'error' in response assert "error" in response -def test_start_testrun_already_started(testing_devices, testrun): # pylint: disable=W0613 +def test_start_testrun_already_started(empty_devices_dir, testrun, add_device): # pylint: disable=W0613 """Test for testrun already started """ + _, mac_address = add_device() + # Payload with device details payload = {"device": { - "mac_addr": BASELINE_MAC_ADDR, - "firmware": "asd", - "test_modules": { - "dns": {"enabled": False}, - "connection": {"enabled": True}, - "ntp": {"enabled": False}, - "baseline": {"enabled": False}, - "nmap": {"enabled": False} - }}} + "mac_addr": mac_address, + "firmware": "test", + "test_modules": { + "protocol": { "enabled": True }, + "services": { "enabled": True }, + "ntp": { "enabled": True }, + "tls": { "enabled": True }, + "connection": { "enabled": True }, + "dns": { "enabled": True } + }}} # Send the post request (start test) r = requests.post(f"{API}/system/start", data=json.dumps(payload), timeout=10) @@ -446,20 +453,15 @@ def test_start_testrun_already_started(testing_devices, testrun): # pylint: disa # Check if 'error' in response assert "error" in response -def test_start_testrun_device_not_found(testing_devices, testrun): # pylint: disable=W0613 +def test_start_testrun_device_not_found(empty_devices_dir, testrun): # pylint: disable=W0613 """Test for start testrun device not found """ # Payload with device details with no mac address assigned payload = {"device": { - "mac_addr": "", - "firmware": "asd", - "test_modules": { - "dns": {"enabled": False}, - "connection": {"enabled": True}, - "ntp": {"enabled": False}, - "baseline": {"enabled": False}, - "nmap": {"enabled": False} - }}} + "mac_addr": "", + "firmware": "test", + "test_modules": {} + }} # Send the post request r = requests.post(f"{API}/system/start", data=json.dumps(payload), timeout=10) @@ -692,22 +694,23 @@ def test_system_shutdown(testrun): # pylint: disable=W0613 # Check if the response status code is 200 (OK) assert r.status_code == 200, f"Expected status code 200, got {r.status_code}" -def test_system_shutdown_in_progress(testrun): # pylint: disable=W0613 +def test_system_shutdown_in_progress(empty_devices_dir, testrun, add_device): # pylint: disable=W0613 """Test system shutdown during an in-progress test""" + + _, mac_address = add_device() + # Payload with device details to start a test - payload = { - "device": { - "mac_addr": BASELINE_MAC_ADDR, - "firmware": "asd", - "test_modules": { - "dns": {"enabled": False}, - "connection": {"enabled": True}, - "ntp": {"enabled": False}, - "baseline": {"enabled": False}, - "nmap": {"enabled": False} - } - } - } + payload = {"device": { + "mac_addr": mac_address, + "firmware": "test", + "test_modules": { + "protocol": { "enabled": True }, + "services": { "enabled": True }, + "ntp": { "enabled": True }, + "tls": { "enabled": True }, + "connection": { "enabled": True }, + "dns": { "enabled": True } + }}} # Start a test r = requests.post(f"{API}/system/start", data=json.dumps(payload), timeout=10) @@ -794,13 +797,9 @@ def create_and_get_device(): """Utility method to create a device""" # Payload with device details - device = { - "mac_addr": "00:1e:42:28:9e:4a", - "manufacturer": "Teltonika", - "model": "TRB140" - } + device = load_json("device_1.json", directory=DEVICES_PATH) - # Send a POST request to create a new device + # Send a POST request to create a new device requests.post(f"{API}/device", data=json.dumps(device), timeout=5) # Send the GET request to retrieve the created device's folder name @@ -816,8 +815,6 @@ def create_and_get_device(): # Return only the device name and MAC address return device_name, mac_address - - @pytest.fixture() def add_device(): """Fixture to add device during tests""" @@ -1234,18 +1231,8 @@ def test_status_non_compliant(testing_devices, testrun): # pylint: disable=W0613 stop_test_device("x123") def test_create_get_devices(empty_devices_dir, testrun): # pylint: disable=W0613 - device_1 = { - "manufacturer": "Google", - "model": "First", - "mac_addr": "00:1e:42:35:73:c4", - "test_modules": { - "dns": {"enabled": True}, - "connection": {"enabled": True}, - "ntp": {"enabled": True}, - "baseline": {"enabled": True}, - "nmap": {"enabled": True}, - }, - } + + device_1 = load_json("device_1.json", directory=DEVICES_PATH) r = requests.post(f"{API}/device", data=json.dumps(device_1), timeout=5) @@ -1253,18 +1240,8 @@ def test_create_get_devices(empty_devices_dir, testrun): # pylint: disable=W0613 assert r.status_code == 201 assert len(local_get_devices()) == 1 - device_2 = { - "manufacturer": "Google", - "model": "Second", - "mac_addr": "00:1e:42:35:73:c6", - "test_modules": { - "dns": {"enabled": True}, - "connection": {"enabled": True}, - "ntp": {"enabled": True}, - "baseline": {"enabled": True}, - "nmap": {"enabled": True}, - }, - } + device_2 = load_json("device_2.json", directory=DEVICES_PATH) + r = requests.post(f"{API}/device", data=json.dumps(device_2), timeout=5) assert r.status_code == 201 @@ -1296,18 +1273,8 @@ def test_create_get_devices(empty_devices_dir, testrun): # pylint: disable=W0613 ) def test_delete_device_success(empty_devices_dir, testrun): # pylint: disable=W0613 - device_1 = { - "manufacturer": "Google", - "model": "First", - "mac_addr": "00:1e:42:35:73:c4", - "test_modules": { - "dns": {"enabled": True}, - "connection": {"enabled": True}, - "ntp": {"enabled": True}, - "baseline": {"enabled": True}, - "nmap": {"enabled": True}, - }, - } + + device_1 = load_json("device_1.json", directory=DEVICES_PATH) # Send create device request r = requests.post(f"{API}/device", @@ -1319,18 +1286,8 @@ def test_delete_device_success(empty_devices_dir, testrun): # pylint: disable=W0 assert r.status_code == 201 assert len(local_get_devices()) == 1 - device_2 = { - "manufacturer": "Google", - "model": "Second", - "mac_addr": "00:1e:42:35:73:c6", - "test_modules": { - "dns": {"enabled": True}, - "connection": {"enabled": True}, - "ntp": {"enabled": True}, - "baseline": {"enabled": True}, - "nmap": {"enabled": True}, - }, - } + device_2 = load_json("device_2.json", directory=DEVICES_PATH) + r = requests.post(f"{API}/device", data=json.dumps(device_2), timeout=5) @@ -1373,56 +1330,21 @@ def test_delete_device_success(empty_devices_dir, testrun): # pylint: disable=W0 ) def test_delete_device_not_found(empty_devices_dir, testrun): # pylint: disable=W0613 - device_1 = { - "manufacturer": "Google", - "model": "First", - "mac_addr": "00:1e:42:35:73:c4", - "test_modules": { - "dns": {"enabled": True}, - "connection": {"enabled": True}, - "ntp": {"enabled": True}, - "baseline": {"enabled": True}, - "nmap": {"enabled": True}, - }, - } - # Send create device request - r = requests.post(f"{API}/device", - data=json.dumps(device_1), - timeout=5) - print(r.text) - - # Check device has been created - assert r.status_code == 201 - assert len(local_get_devices()) == 1 + payload = {"mac_addr": "non_existing"} # Test that device_1 deletes r = requests.delete(f"{API}/device/", - data=json.dumps(device_1), + data=json.dumps(payload), timeout=5) - assert r.status_code == 200 - assert len(local_get_devices()) == 0 - # Test that device_1 is not found - r = requests.delete(f"{API}/device/", - data=json.dumps(device_1), - timeout=5) assert r.status_code == 404 + assert len(local_get_devices()) == 0 def test_delete_device_no_mac(empty_devices_dir, testrun): # pylint: disable=W0613 - device_1 = { - "manufacturer": "Google", - "model": "First", - "mac_addr": "00:1e:42:35:73:c4", - "test_modules": { - "dns": {"enabled": True}, - "connection": {"enabled": True}, - "ntp": {"enabled": True}, - "baseline": {"enabled": True}, - "nmap": {"enabled": True}, - }, - } + + device_1 = load_json("device_1.json", directory=DEVICES_PATH) # Send create device request r = requests.post(f"{API}/device", @@ -1485,18 +1407,8 @@ def test_delete_device_testrun_running(testing_devices, testrun): # pylint: disa def test_start_system_not_configured_correctly( empty_devices_dir, # pylint: disable=W0613 testrun): # pylint: disable=W0613 - device_1 = { - "manufacturer": "Google", - "model": "First", - "mac_addr": "00:1e:42:35:73:c4", - "test_modules": { - "dns": {"enabled": True}, - "connection": {"enabled": True}, - "ntp": {"enabled": True}, - "baseline": {"enabled": True}, - "nmap": {"enabled": True}, - }, - } + + device_1 = load_json("device_1.json", directory=DEVICES_PATH) # Send create device request r = requests.post(f"{API}/device", @@ -1504,25 +1416,17 @@ def test_start_system_not_configured_correctly( timeout=5) payload = {"device": {"mac_addr": None, "firmware": "asd"}} + r = requests.post(f"{API}/system/start", data=json.dumps(payload), timeout=10) + assert r.status_code == 500 def test_start_device_not_found(empty_devices_dir, # pylint: disable=W0613 testrun): # pylint: disable=W0613 - device_1 = { - "manufacturer": "Google", - "model": "First", - "mac_addr": "00:1e:42:35:73:c4", - "test_modules": { - "dns": {"enabled": True}, - "connection": {"enabled": True}, - "ntp": {"enabled": True}, - "baseline": {"enabled": True}, - "nmap": {"enabled": True}, - }, - } + + device_1 = load_json("device_1.json", directory=DEVICES_PATH) # Send create device request r = requests.post(f"{API}/device", @@ -1543,18 +1447,8 @@ def test_start_device_not_found(empty_devices_dir, # pylint: disable=W0613 def test_start_missing_device_information( empty_devices_dir, # pylint: disable=W0613 testrun): # pylint: disable=W0613 - device_1 = { - "manufacturer": "Google", - "model": "First", - "mac_addr": "00:1e:42:35:73:c4", - "test_modules": { - "dns": {"enabled": True}, - "connection": {"enabled": True}, - "ntp": {"enabled": True}, - "baseline": {"enabled": True}, - "nmap": {"enabled": True}, - }, - } + + device_1 = load_json("device_1.json", directory=DEVICES_PATH) # Send create device request r = requests.post(f"{API}/device", @@ -1570,18 +1464,8 @@ def test_start_missing_device_information( def test_create_device_already_exists( empty_devices_dir, # pylint: disable=W0613 testrun): # pylint: disable=W0613 - device_1 = { - "manufacturer": "Google", - "model": "First", - "mac_addr": "00:1e:42:35:73:c4", - "test_modules": { - "dns": {"enabled": True}, - "connection": {"enabled": True}, - "ntp": {"enabled": True}, - "baseline": {"enabled": True}, - "nmap": {"enabled": True}, - }, - } + + device_1 = load_json("device_1.json", directory=DEVICES_PATH) r = requests.post(f"{API}/device", data=json.dumps(device_1), @@ -1597,8 +1481,8 @@ def test_create_device_already_exists( def test_create_device_invalid_json( empty_devices_dir, # pylint: disable=W0613 testrun): # pylint: disable=W0613 - device_1 = { - } + + device_1 = {} r = requests.post(f"{API}/device", data=json.dumps(device_1), @@ -1665,18 +1549,8 @@ def test_device_edit_device( def test_device_edit_device_not_found( empty_devices_dir, # pylint: disable=W0613 testrun): # pylint: disable=W0613 - device_1 = { - "manufacturer": "Google", - "model": "First", - "mac_addr": "00:1e:42:35:73:c4", - "test_modules": { - "dns": {"enabled": True}, - "connection": {"enabled": True}, - "ntp": {"enabled": True}, - "baseline": {"enabled": True}, - "nmap": {"enabled": True}, - }, - } + + device_1 = load_json("device_1.json", directory=DEVICES_PATH) r = requests.post(f"{API}/device", data=json.dumps(device_1), @@ -1701,18 +1575,8 @@ def test_device_edit_device_not_found( def test_device_edit_device_incorrect_json_format( empty_devices_dir, # pylint: disable=W0613 testrun): # pylint: disable=W0613 - device_1 = { - "manufacturer": "Google", - "model": "First", - "mac_addr": "00:1e:42:35:73:c4", - "test_modules": { - "dns": {"enabled": True}, - "connection": {"enabled": True}, - "ntp": {"enabled": True}, - "baseline": {"enabled": True}, - "nmap": {"enabled": True}, - }, - } + + device_1 = load_json("device_1.json", directory=DEVICES_PATH) r = requests.post(f"{API}/device", data=json.dumps(device_1), @@ -1732,47 +1596,31 @@ def test_device_edit_device_incorrect_json_format( def test_device_edit_device_with_mac_already_exists( empty_devices_dir, # pylint: disable=W0613 testrun): # pylint: disable=W0613 - device_1 = { - "manufacturer": "Google", - "model": "First", - "mac_addr": "00:1e:42:35:73:c4", - "test_modules": { - "dns": {"enabled": True}, - "connection": {"enabled": True}, - "ntp": {"enabled": True}, - "baseline": {"enabled": True}, - "nmap": {"enabled": True}, - }, - } + + device_1 = load_json("device_1.json", directory=DEVICES_PATH) r = requests.post(f"{API}/device", data=json.dumps(device_1), timeout=5) + assert r.status_code == 201 + assert len(local_get_devices()) == 1 - device_2 = { - "manufacturer": "Google", - "model": "Second", - "mac_addr": "00:1e:42:35:73:c6", - "test_modules": { - "dns": {"enabled": True}, - "connection": {"enabled": True}, - "ntp": {"enabled": True}, - "baseline": {"enabled": True}, - "nmap": {"enabled": True}, - }, - } + device_2 = load_json("device_2.json", directory=DEVICES_PATH) + r = requests.post(f"{API}/device", data=json.dumps(device_2), timeout=5) + assert r.status_code == 201 + assert len(local_get_devices()) == 2 updated_device = copy.deepcopy(device_1) updated_device_payload = {} - updated_device_payload = {} + updated_device_payload["device"] = updated_device updated_device_payload["mac_addr"] = "00:1e:42:35:73:c6" updated_device_payload["model"] = "Alphabet" From db7782635586bfe21c8f7760785a8e10df836d87 Mon Sep 17 00:00:00 2001 From: MariusBaldovin Date: Tue, 3 Sep 2024 15:17:37 +0100 Subject: [PATCH 4/5] fixed json formatting --- testing/api/devices/device_1.json | 108 +++++++++++++++--------------- testing/api/devices/device_2.json | 107 +++++++++++++++-------------- 2 files changed, 107 insertions(+), 108 deletions(-) diff --git a/testing/api/devices/device_1.json b/testing/api/devices/device_1.json index 2de82408b..f76f5d2e0 100644 --- a/testing/api/devices/device_1.json +++ b/testing/api/devices/device_1.json @@ -1,55 +1,55 @@ -{ - "status": "Valid", - "mac_addr": "00:1e:42:28:9e:4a", - "manufacturer": "Teltonika", - "model": "TRB140", - "type": "IoT Gateway", - "technology": "Hardware - Access Control", - "test_pack": "Device Qualification", - "additional_info": [ - { - "question": "What type of device is this?", - "answer": "IoT Gateway" - }, - { - "question": "Please select the technology this device falls into", - "answer": "Hardware - Access Control" - }, - { - "question": "Does your device process any sensitive information? ", - "answer": "Yes" - }, - { - "question": "Can all non-essential services be disabled on your device?", - "answer": "Yes" - }, - { - "question": "Is there a second IP port on the device?", - "answer": "Yes" - }, - { - "question": "Can the second IP port on your device be disabled?", - "answer": "Yes" - } - ], - "test_modules": { - "protocol": { - "enabled": true - }, - "services": { - "enabled": true - }, - "ntp": { - "enabled": true - }, - "tls": { - "enabled": true - }, - "connection": { - "enabled": true - }, - "dns": { - "enabled": true - } +{ + "status": "Valid", + "mac_addr": "00:1e:42:28:9e:4a", + "manufacturer": "Teltonika", + "model": "TRB140", + "type": "IoT Gateway", + "technology": "Hardware - Access Control", + "test_pack": "Device Qualification", + "additional_info": [ + { + "question": "What type of device is this?", + "answer": "IoT Gateway" + }, + { + "question": "Please select the technology this device falls into", + "answer": "Hardware - Access Control" + }, + { + "question": "Does your device process any sensitive information?", + "answer": "Yes" + }, + { + "question": "Can all non-essential services be disabled on your device?", + "answer": "Yes" + }, + { + "question": "Is there a second IP port on the device?", + "answer": "Yes" + }, + { + "question": "Can the second IP port on your device be disabled?", + "answer": "Yes" } -} \ No newline at end of file + ], + "test_modules": { + "protocol": { + "enabled": true + }, + "services": { + "enabled": false + }, + "ntp": { + "enabled": true + }, + "tls": { + "enabled": false + }, + "connection": { + "enabled": true + }, + "dns": { + "enabled": true + } + } +} diff --git a/testing/api/devices/device_2.json b/testing/api/devices/device_2.json index e813bfc72..df8a418fb 100644 --- a/testing/api/devices/device_2.json +++ b/testing/api/devices/device_2.json @@ -1,56 +1,55 @@ { - "status": "Valid", - "mac_addr": "00:1e:42:35:73:c6", - "manufacturer": "Google", - "model": "First", - "type": "IoT Gateway", - "technology": "Hardware - Access Control", - "test_pack": "Device Qualification", - "additional_info": [ - { - "question": "What type of device is this?", - "answer": "IoT Gateway" - }, - { - "question": "Please select the technology this device falls into", - "answer": "Hardware - Access Control" - }, - { - "question": "Does your device process any sensitive information? ", - "answer": "Yes" - }, - { - "question": "Can all non-essential services be disabled on your device?", - "answer": "Yes" - }, - { - "question": "Is there a second IP port on the device?", - "answer": "Yes" - }, - { - "question": "Can the second IP port on your device be disabled?", - "answer": "Yes" - } - ], - - "test_modules": { - "protocol": { - "enabled": true - }, - "services": { - "enabled": false - }, - "ntp": { - "enabled": true - }, - "tls": { - "enabled": false - }, - "connection": { - "enabled": true - }, - "dns": { - "enabled": true - } + "status": "Valid", + "mac_addr": "00:1e:42:35:73:c6", + "manufacturer": "Google", + "model": "First", + "type": "IoT Gateway", + "technology": "Hardware - Access Control", + "test_pack": "Device Qualification", + "additional_info": [ + { + "question": "What type of device is this?", + "answer": "IoT Gateway" + }, + { + "question": "Please select the technology this device falls into", + "answer": "Hardware - Access Control" + }, + { + "question": "Does your device process any sensitive information?", + "answer": "Yes" + }, + { + "question": "Can all non-essential services be disabled on your device?", + "answer": "Yes" + }, + { + "question": "Is there a second IP port on the device?", + "answer": "Yes" + }, + { + "question": "Can the second IP port on your device be disabled?", + "answer": "Yes" } -} \ No newline at end of file + ], + "test_modules": { + "protocol": { + "enabled": true + }, + "services": { + "enabled": false + }, + "ntp": { + "enabled": true + }, + "tls": { + "enabled": false + }, + "connection": { + "enabled": true + }, + "dns": { + "enabled": true + } + } +} From 386af90db9a719d55e28212bdcdc84482c443a61 Mon Sep 17 00:00:00 2001 From: MariusBaldovin Date: Thu, 5 Sep 2024 15:47:11 +0100 Subject: [PATCH 5/5] fixed device json --- testing/api/devices/device_1.json | 1 - testing/api/devices/device_2.json | 1 - 2 files changed, 2 deletions(-) diff --git a/testing/api/devices/device_1.json b/testing/api/devices/device_1.json index f76f5d2e0..3be69a082 100644 --- a/testing/api/devices/device_1.json +++ b/testing/api/devices/device_1.json @@ -1,5 +1,4 @@ { - "status": "Valid", "mac_addr": "00:1e:42:28:9e:4a", "manufacturer": "Teltonika", "model": "TRB140", diff --git a/testing/api/devices/device_2.json b/testing/api/devices/device_2.json index df8a418fb..177ee23e6 100644 --- a/testing/api/devices/device_2.json +++ b/testing/api/devices/device_2.json @@ -1,5 +1,4 @@ { - "status": "Valid", "mac_addr": "00:1e:42:35:73:c6", "manufacturer": "Google", "model": "First",