mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 14:04:20 +01:00
Fixes unstyled Setup UI (#291)
* Changing /static to /themes * Adding test to make sure setup behavior works
This commit is contained in:
@@ -118,7 +118,7 @@ def init_utils(app):
|
|||||||
|
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def needs_setup():
|
def needs_setup():
|
||||||
if request.path == '/setup' or request.path.startswith('/static'):
|
if request.path == '/setup' or request.path.startswith('/themes'):
|
||||||
return
|
return
|
||||||
if not is_setup():
|
if not is_setup():
|
||||||
return redirect(url_for('views.setup'))
|
return redirect(url_for('views.setup'))
|
||||||
|
|||||||
@@ -13,14 +13,6 @@ from CTFd import utils
|
|||||||
views = Blueprint('views', __name__)
|
views = Blueprint('views', __name__)
|
||||||
|
|
||||||
|
|
||||||
@views.before_request
|
|
||||||
def redirect_setup():
|
|
||||||
if request.path.startswith("/static"):
|
|
||||||
return
|
|
||||||
if not utils.is_setup() and request.path != "/setup":
|
|
||||||
return redirect(url_for('views.setup'))
|
|
||||||
|
|
||||||
|
|
||||||
@views.route('/setup', methods=['GET', 'POST'])
|
@views.route('/setup', methods=['GET', 'POST'])
|
||||||
def setup():
|
def setup():
|
||||||
# with app.app_context():
|
# with app.app_context():
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from sqlalchemy_utils import database_exists, create_database, drop_database
|
|||||||
from sqlalchemy.engine.url import make_url
|
from sqlalchemy.engine.url import make_url
|
||||||
|
|
||||||
|
|
||||||
def create_ctfd(ctf_name="CTFd", name="admin", email="admin@ctfd.io", password="password"):
|
def create_ctfd(ctf_name="CTFd", name="admin", email="admin@ctfd.io", password="password", setup=True):
|
||||||
app = create_app('CTFd.config.TestingConfig')
|
app = create_app('CTFd.config.TestingConfig')
|
||||||
|
|
||||||
url = make_url(app.config['SQLALCHEMY_DATABASE_URI'])
|
url = make_url(app.config['SQLALCHEMY_DATABASE_URI'])
|
||||||
@@ -17,6 +17,7 @@ def create_ctfd(ctf_name="CTFd", name="admin", email="admin@ctfd.io", password="
|
|||||||
with app.app_context():
|
with app.app_context():
|
||||||
app.db.create_all()
|
app.db.create_all()
|
||||||
|
|
||||||
|
if setup:
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
with app.test_client() as client:
|
with app.test_client() as client:
|
||||||
data = {}
|
data = {}
|
||||||
|
|||||||
@@ -298,3 +298,17 @@ def test_themes_handler():
|
|||||||
assert r.status_code == 404
|
assert r.status_code == 404
|
||||||
r = client.get('/themes/original/static/../../../utils.py')
|
r = client.get('/themes/original/static/../../../utils.py')
|
||||||
assert r.status_code == 404
|
assert r.status_code == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_ctfd_setup_redirect():
|
||||||
|
"""Test that a fresh CTFd instance redirects to /setup"""
|
||||||
|
app = create_ctfd(setup=False)
|
||||||
|
with app.app_context():
|
||||||
|
with app.test_client() as client:
|
||||||
|
r = client.get('/teams')
|
||||||
|
assert r.status_code == 302
|
||||||
|
assert r.location == "http://localhost/setup"
|
||||||
|
|
||||||
|
# Files in /themes load properly
|
||||||
|
r = client.get('/themes/original/static/css/style.css')
|
||||||
|
assert r.status_code == 200
|
||||||
|
|||||||
Reference in New Issue
Block a user