From 1d938e58f844c008dfc5611a13f421e97675f0cd Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 26 Apr 2022 13:38:52 -0400 Subject: [PATCH] Island: Prefix private functions with "_" in FileUpload resource --- .../monkey_island/cc/resources/pba_file_upload.py | 13 ++++++------- .../cc/resources/test_pba_file_upload.py | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/monkey/monkey_island/cc/resources/pba_file_upload.py b/monkey/monkey_island/cc/resources/pba_file_upload.py index bb2608872..5fdde2045 100644 --- a/monkey/monkey_island/cc/resources/pba_file_upload.py +++ b/monkey/monkey_island/cc/resources/pba_file_upload.py @@ -30,7 +30,6 @@ class FileUpload(flask_restful.Resource): # TODO: Fix references/coupling to filepond # TODO: Replace "file_type" with "target_os" or similar - # TODO: Prefix private functions with "_" # TODO: Add comment explaining why this is basically a duplicate of the endpoint in the # PBAFileDownload resource. @jwt_required @@ -40,7 +39,7 @@ class FileUpload(flask_restful.Resource): :param file_type: Type indicates which file to send, linux or windows :return: Returns file contents """ - if self.is_pba_file_type_supported(file_type): + if self._is_pba_file_type_supported(file_type): return Response(status=HTTPStatus.UNPROCESSABLE_ENTITY, mimetype="text/plain") # Verify that file_name is indeed a file from config @@ -67,10 +66,10 @@ class FileUpload(flask_restful.Resource): :param file_type: Type indicates which file was received, linux or windows :return: Returns flask response object with uploaded file's filename """ - if self.is_pba_file_type_supported(file_type): + if self._is_pba_file_type_supported(file_type): return Response(status=HTTPStatus.UNPROCESSABLE_ENTITY, mimetype="text/plain") - filename = self.upload_pba_file( + filename = self._upload_pba_file( # TODO: This "filepond" string can be changed to be more generic in the `react-filepond` # component. request.files["filepond"], @@ -80,7 +79,7 @@ class FileUpload(flask_restful.Resource): response = Response(response=filename, status=200, mimetype="text/plain") return response - def upload_pba_file(self, file_storage: FileStorage, is_linux=True): + def _upload_pba_file(self, file_storage: FileStorage, is_linux=True): """ Uploads PBA file to island's file system :param request_: Request object containing PBA file @@ -103,7 +102,7 @@ class FileUpload(flask_restful.Resource): :param file_type: Type indicates which file was deleted, linux of windows :return: Empty response """ - if self.is_pba_file_type_supported(file_type): + if self._is_pba_file_type_supported(file_type): return Response(status=HTTPStatus.UNPROCESSABLE_ENTITY, mimetype="text/plain") filename_path = ( @@ -117,5 +116,5 @@ class FileUpload(flask_restful.Resource): return make_response({}, 200) @staticmethod - def is_pba_file_type_supported(file_type: str) -> bool: + def _is_pba_file_type_supported(file_type: str) -> bool: return file_type not in {LINUX_PBA_TYPE, WINDOWS_PBA_TYPE} diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/test_pba_file_upload.py b/monkey/tests/unit_tests/monkey_island/cc/resources/test_pba_file_upload.py index 28b908c86..00e10757d 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/test_pba_file_upload.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/test_pba_file_upload.py @@ -94,7 +94,7 @@ def test_pba_file_upload_post__internal_server_error( flask_client, pba_os, monkeypatch, mock_set_config_value ): monkeypatch.setattr( - "monkey_island.cc.resources.pba_file_upload.FileUpload.upload_pba_file", + "monkey_island.cc.resources.pba_file_upload.FileUpload._upload_pba_file", lambda x, y: raise_(Exception()), )