Island: Rename FileUpload resource to PBAFileUpload

This commit is contained in:
Ilija Lazoroski 2022-08-05 09:23:51 +02:00
parent d30c2df0c8
commit 0a6fa1e7d7
3 changed files with 17 additions and 13 deletions

View File

@ -40,7 +40,7 @@ from monkey_island.cc.resources.netmap import NetMap
from monkey_island.cc.resources.node import Node
from monkey_island.cc.resources.node_states import NodeStates
from monkey_island.cc.resources.pba_file_download import PBAFileDownload
from monkey_island.cc.resources.pba_file_upload import FileUpload
from monkey_island.cc.resources.pba_file_upload import PBAFileUpload
from monkey_island.cc.resources.ransomware_report import RansomwareReport
from monkey_island.cc.resources.root import Root
from monkey_island.cc.resources.security_report import SecurityReport
@ -181,7 +181,7 @@ def init_restful_endpoints(api: FlaskDIWrapper):
# API Spec: These two should be the same resource, GET for download and POST for upload
api.add_resource(PBAFileDownload)
api.add_resource(FileUpload)
api.add_resource(PBAFileUpload)
api.add_resource(PropagationCredentials)
api.add_resource(RemoteRun)

View File

@ -18,7 +18,7 @@ WINDOWS_PBA_TYPE = "PBAwindows"
# NOTE: This resource will be reworked when the Custom PBA feature is rebuilt as a payload plugin.
class FileUpload(AbstractResource):
class PBAFileUpload(AbstractResource):
# API Spec: FileUpload -> PBAFileUpload. Change endpoint accordingly.
"""
File upload endpoint used to send/receive Custom PBA files

View File

@ -9,7 +9,11 @@ from tests.utils import raise_
from common import DIContainer
from monkey_island.cc.repository import IAgentConfigurationRepository, IFileRepository
from monkey_island.cc.resources.pba_file_upload import LINUX_PBA_TYPE, WINDOWS_PBA_TYPE, FileUpload
from monkey_island.cc.resources.pba_file_upload import (
LINUX_PBA_TYPE,
WINDOWS_PBA_TYPE,
PBAFileUpload,
)
TEST_FILE_CONTENTS = b"m0nk3y"
TEST_FILE = (
@ -54,7 +58,7 @@ def flask_client(
@pytest.mark.parametrize("pba_os", [LINUX_PBA_TYPE, WINDOWS_PBA_TYPE])
def test_pba_file_upload_post(flask_client: FlaskClient, pba_os: str):
url = get_url_for_resource(FileUpload, target_os=pba_os)
url = get_url_for_resource(PBAFileUpload, target_os=pba_os)
resp = flask_client.post(
url,
data=TEST_FILE,
@ -65,7 +69,7 @@ def test_pba_file_upload_post(flask_client: FlaskClient, pba_os: str):
def test_pba_file_upload_post__invalid(flask_client: FlaskClient):
url = get_url_for_resource(FileUpload, target_os="bogus")
url = get_url_for_resource(PBAFileUpload, target_os="bogus")
resp = flask_client.post(
url,
data=TEST_FILE,
@ -80,7 +84,7 @@ def test_pba_file_upload_post__internal_server_error(
flask_client: FlaskClient, pba_os: str, file_repository: IFileRepository
):
file_repository.save_file = lambda x, y: raise_(Exception())
url = get_url_for_resource(FileUpload, target_os=pba_os)
url = get_url_for_resource(PBAFileUpload, target_os=pba_os)
resp = flask_client.post(
url,
@ -93,14 +97,14 @@ def test_pba_file_upload_post__internal_server_error(
@pytest.mark.parametrize("pba_os", [LINUX_PBA_TYPE, WINDOWS_PBA_TYPE])
def test_pba_file_upload_get__file_not_found(flask_client: FlaskClient, pba_os: str):
url = get_url_for_resource(FileUpload, target_os=pba_os, filename="bobug_mogus.py")
url = get_url_for_resource(PBAFileUpload, target_os=pba_os, filename="bobug_mogus.py")
resp = flask_client.get(url)
assert resp.status_code == 404
@pytest.mark.parametrize("pba_os", [LINUX_PBA_TYPE, WINDOWS_PBA_TYPE])
def test_file_download_endpoint_500(open_error_flask_client, pba_os: str):
url = get_url_for_resource(FileUpload, target_os=pba_os, filename="bobug_mogus.py")
url = get_url_for_resource(PBAFileUpload, target_os=pba_os, filename="bobug_mogus.py")
resp = open_error_flask_client.get(url)
@ -110,7 +114,7 @@ def test_file_download_endpoint_500(open_error_flask_client, pba_os: str):
@pytest.mark.parametrize("pba_os", [LINUX_PBA_TYPE, WINDOWS_PBA_TYPE])
def test_pba_file_upload_endpoint(flask_client: FlaskClient, pba_os: str):
url_with_os = get_url_for_resource(FileUpload, target_os=pba_os)
url_with_os = get_url_for_resource(PBAFileUpload, target_os=pba_os)
resp_post = flask_client.post(
url_with_os,
data=TEST_FILE,
@ -118,7 +122,7 @@ def test_pba_file_upload_endpoint(flask_client: FlaskClient, pba_os: str):
follow_redirects=True,
)
url_with_filename = get_url_for_resource(FileUpload, target_os=pba_os, filename="test.py")
url_with_filename = get_url_for_resource(PBAFileUpload, target_os=pba_os, filename="test.py")
resp_get = flask_client.get(url_with_filename)
assert resp_get.status_code == 200
assert resp_get.data == TEST_FILE_CONTENTS
@ -135,7 +139,7 @@ def test_pba_file_upload_endpoint(flask_client: FlaskClient, pba_os: str):
def test_pba_file_upload_endpoint__invalid(flask_client: FlaskClient):
url_with_os = get_url_for_resource(FileUpload, target_os="bogus")
url_with_os = get_url_for_resource(PBAFileUpload, target_os="bogus")
resp_post = flask_client.post(
url_with_os,
data=TEST_FILE,
@ -144,7 +148,7 @@ def test_pba_file_upload_endpoint__invalid(flask_client: FlaskClient):
)
url_with_filename = get_url_for_resource(
FileUpload, target_os="bogus", filename="bobug_mogus.py"
PBAFileUpload, target_os="bogus", filename="bobug_mogus.py"
)
resp_get = flask_client.get(url_with_filename)
resp_delete = flask_client.delete(url_with_os, data="test.py", content_type="text/plain;")