forked from p34709852/monkey
Island: Pass the data directory to init_app_resources()
This commit is contained in:
parent
6cfdcaaec7
commit
c03a5aac4b
|
@ -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("/<path:static_path>", "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
|
||||
|
|
|
@ -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.")
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue