mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 14:04:20 +01:00
Fix issue with previewing certain pages (#1571)
* Fix previewing pages when page attributes are set
This commit is contained in:
@@ -24,7 +24,9 @@ def pages_new():
|
|||||||
@admin.route("/admin/pages/preview", methods=["POST"])
|
@admin.route("/admin/pages/preview", methods=["POST"])
|
||||||
@admins_only
|
@admins_only
|
||||||
def pages_preview():
|
def pages_preview():
|
||||||
data = request.form.to_dict()
|
# We only care about content.
|
||||||
|
# Loading other attributes improperly will cause Marshmallow to incorrectly return a dict
|
||||||
|
data = {"content": request.form.get("content")}
|
||||||
schema = PageSchema()
|
schema = PageSchema()
|
||||||
page = schema.load(data)
|
page = schema.load(data)
|
||||||
return render_template("page.html", content=build_html(page.data.content))
|
return render_template("page.html", content=build_html(page.data.content))
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
from tests.helpers import create_ctfd, destroy_ctfd, login_as_user
|
||||||
|
|
||||||
|
|
||||||
|
def test_previewing_pages_works():
|
||||||
|
"""Test that pages can be previewed properly"""
|
||||||
|
app = create_ctfd()
|
||||||
|
with app.app_context():
|
||||||
|
client = login_as_user(app, name="admin", password="password")
|
||||||
|
|
||||||
|
with client.session_transaction() as sess:
|
||||||
|
data = {
|
||||||
|
"title": "title",
|
||||||
|
"route": "route",
|
||||||
|
"content": "content_testing",
|
||||||
|
"nonce": sess.get("nonce"),
|
||||||
|
"draft": "y",
|
||||||
|
"hidden": "y",
|
||||||
|
"auth_required": "y",
|
||||||
|
}
|
||||||
|
|
||||||
|
r = client.post("/admin/pages/preview", data=data)
|
||||||
|
assert r.status_code == 200
|
||||||
|
resp = r.get_data(as_text=True)
|
||||||
|
assert "content_testing" in resp
|
||||||
|
|
||||||
|
destroy_ctfd(app)
|
||||||
|
|||||||
Reference in New Issue
Block a user