From c03a5aac4bb014002be179caabc3ebc630d24c67 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 25 Apr 2022 10:26:32 -0400 Subject: [PATCH] Island: Pass the data directory to init_app_resources() --- monkey/monkey_island/cc/app.py | 7 ++++--- monkey/monkey_island/cc/server_setup.py | 2 +- .../unit_tests/monkey_island/cc/resources/conftest.py | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/monkey/monkey_island/cc/app.py b/monkey/monkey_island/cc/app.py index 78f09b4de..77d52ac8c 100644 --- a/monkey/monkey_island/cc/app.py +++ b/monkey/monkey_island/cc/app.py @@ -1,6 +1,7 @@ import os import uuid from datetime import timedelta +from pathlib import Path import flask_restful from flask import Flask, Response, send_from_directory @@ -111,7 +112,7 @@ def init_app_url_rules(app): app.add_url_rule("/", "serve_static_file", serve_static_file) -def init_api_resources(api): +def init_api_resources(api, data_dir: Path): api.add_resource(Root, "/api") api.add_resource(Registration, "/api/registration") api.add_resource(Authenticate, "/api/auth") @@ -168,7 +169,7 @@ def init_api_resources(api): api.add_resource(TelemetryBlackboxEndpoint, "/api/test/telemetry") -def init_app(mongo_url): +def init_app(mongo_url, data_dir: Path): app = Flask(__name__) api = flask_restful.Api(app) @@ -177,6 +178,6 @@ def init_app(mongo_url): init_app_config(app, mongo_url) init_app_services(app) init_app_url_rules(app) - init_api_resources(api) + init_api_resources(api, data_dir) return app diff --git a/monkey/monkey_island/cc/server_setup.py b/monkey/monkey_island/cc/server_setup.py index 98f29de10..072cb32a8 100644 --- a/monkey/monkey_island/cc/server_setup.py +++ b/monkey/monkey_island/cc/server_setup.py @@ -129,7 +129,7 @@ def _configure_gevent_exception_handling(data_dir): def _start_island_server(should_setup_only, config_options: IslandConfigOptions): populate_exporter_list() - app = init_app(mongo_setup.MONGO_URL) + app = init_app(mongo_setup.MONGO_URL, Path(config_options.data_dir)) if should_setup_only: logger.warning("Setup only flag passed. Exiting.") diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/conftest.py b/monkey/tests/unit_tests/monkey_island/cc/resources/conftest.py index 4779bd0e2..903528be2 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/conftest.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/conftest.py @@ -10,14 +10,14 @@ from monkey_island.cc.services.representations import output_json @pytest.fixture -def flask_client(monkeypatch_session): +def flask_client(monkeypatch_session, tmp_path): monkeypatch_session.setattr(flask_jwt_extended, "verify_jwt_in_request", lambda: None) - with mock_init_app().test_client() as client: + with mock_init_app(tmp_path).test_client() as client: yield client -def mock_init_app(): +def mock_init_app(data_dir): app = Flask(__name__) app.config["SECRET_KEY"] = "test_key" @@ -25,7 +25,7 @@ def mock_init_app(): api.representations = {"application/json": output_json} monkey_island.cc.app.init_app_url_rules(app) - monkey_island.cc.app.init_api_resources(api) + monkey_island.cc.app.init_api_resources(api, data_dir) flask_jwt_extended.JWTManager(app)