mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 05:54:19 +01:00
Properly check SAFE_MODE and allow plugins to be loaded from tests optionally
This commit is contained in:
@@ -189,7 +189,6 @@ def create_app(config='CTFd.config.Config'):
|
|||||||
app.register_error_handler(500, general_error)
|
app.register_error_handler(500, general_error)
|
||||||
app.register_error_handler(502, gateway_error)
|
app.register_error_handler(502, gateway_error)
|
||||||
|
|
||||||
if app.config.get('SAFE_MODE', False):
|
init_plugins(app)
|
||||||
init_plugins(app)
|
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|||||||
@@ -146,15 +146,16 @@ def init_plugins(app):
|
|||||||
:param app: A CTFd application
|
:param app: A CTFd application
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
modules = sorted(glob.glob(os.path.dirname(__file__) + "/*"))
|
if app.config.get('SAFE_MODE', False) is False:
|
||||||
blacklist = {'__pycache__'}
|
modules = sorted(glob.glob(os.path.dirname(__file__) + "/*"))
|
||||||
for module in modules:
|
blacklist = {'__pycache__'}
|
||||||
module_name = os.path.basename(module)
|
for module in modules:
|
||||||
if os.path.isdir(module) and module_name not in blacklist:
|
module_name = os.path.basename(module)
|
||||||
module = '.' + module_name
|
if os.path.isdir(module) and module_name not in blacklist:
|
||||||
module = importlib.import_module(module, package='CTFd.plugins')
|
module = '.' + module_name
|
||||||
module.load(app)
|
module = importlib.import_module(module, package='CTFd.plugins')
|
||||||
print(" * Loaded module, %s" % module)
|
module.load(app)
|
||||||
|
print(" * Loaded module, %s" % module)
|
||||||
|
|
||||||
app.jinja_env.globals.update(get_admin_plugin_menu_bar=get_admin_plugin_menu_bar)
|
app.jinja_env.globals.update(get_admin_plugin_menu_bar=get_admin_plugin_menu_bar)
|
||||||
app.jinja_env.globals.update(get_user_page_menu_bar=get_user_page_menu_bar)
|
app.jinja_env.globals.update(get_user_page_menu_bar=get_user_page_menu_bar)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from CTFd import create_app
|
from CTFd import create_app
|
||||||
|
from CTFd.config import TestingConfig
|
||||||
from CTFd.models import *
|
from CTFd.models import *
|
||||||
from CTFd.cache import cache
|
from CTFd.cache import cache
|
||||||
from sqlalchemy_utils import database_exists, create_database, drop_database
|
from sqlalchemy_utils import database_exists, create_database, drop_database
|
||||||
@@ -15,8 +16,11 @@ else:
|
|||||||
binary_type = bytes
|
binary_type = bytes
|
||||||
|
|
||||||
|
|
||||||
def create_ctfd(ctf_name="CTFd", name="admin", email="admin@ctfd.io", password="password", user_mode="users", setup=True):
|
def create_ctfd(ctf_name="CTFd", name="admin", email="admin@ctfd.io", password="password", user_mode="users", setup=True, enable_plugins=False):
|
||||||
app = create_app('CTFd.config.TestingConfig')
|
if enable_plugins:
|
||||||
|
TestingConfig.SAFE_MODE = False
|
||||||
|
|
||||||
|
app = create_app(TestingConfig)
|
||||||
|
|
||||||
if setup:
|
if setup:
|
||||||
app = setup_ctfd(app, ctf_name, name, email, password, user_mode)
|
app = setup_ctfd(app, ctf_name, name, email, password, user_mode)
|
||||||
|
|||||||
Reference in New Issue
Block a user