mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 14:04:20 +01:00
Fix deleting chals when they have a hint (#601)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
from CTFd.plugins import register_plugin_assets_directory
|
from CTFd.plugins import register_plugin_assets_directory
|
||||||
from CTFd.plugins.keys import get_key_class
|
from CTFd.plugins.keys import get_key_class
|
||||||
from CTFd.models import db, Solves, WrongKeys, Keys, Challenges, Files, Tags
|
from CTFd.models import db, Solves, WrongKeys, Keys, Challenges, Files, Tags, Hints
|
||||||
from CTFd import utils
|
from CTFd import utils
|
||||||
|
|
||||||
|
|
||||||
@@ -128,6 +128,7 @@ class CTFdStandardChallenge(BaseChallenge):
|
|||||||
utils.delete_file(f.id)
|
utils.delete_file(f.id)
|
||||||
Files.query.filter_by(chal=challenge.id).delete()
|
Files.query.filter_by(chal=challenge.id).delete()
|
||||||
Tags.query.filter_by(chal=challenge.id).delete()
|
Tags.query.filter_by(chal=challenge.id).delete()
|
||||||
|
Hints.query.filter_by(chal=challenge.id).delete()
|
||||||
Challenges.query.filter_by(id=challenge.id).delete()
|
Challenges.query.filter_by(id=challenge.id).delete()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|||||||
@@ -202,6 +202,31 @@ def test_admins_can_delete_challenges():
|
|||||||
destroy_ctfd(app)
|
destroy_ctfd(app)
|
||||||
|
|
||||||
|
|
||||||
|
def test_admins_can_delete_challenges_with_extras():
|
||||||
|
""""Test that admins can delete challenges that have a hint"""
|
||||||
|
app = create_ctfd()
|
||||||
|
with app.app_context():
|
||||||
|
client = login_as_user(app, name="admin", password="password")
|
||||||
|
|
||||||
|
chal = gen_challenge(app.db)
|
||||||
|
chal_id = chal.id
|
||||||
|
|
||||||
|
hint = gen_hint(app.db, chal_id)
|
||||||
|
|
||||||
|
assert Challenges.query.count() == 1
|
||||||
|
|
||||||
|
with client.session_transaction() as sess:
|
||||||
|
data = {
|
||||||
|
'id': chal_id,
|
||||||
|
'nonce': sess.get('nonce'),
|
||||||
|
}
|
||||||
|
r = client.post('/admin/chal/delete', data=data)
|
||||||
|
assert r.get_data(as_text=True) == '1'
|
||||||
|
|
||||||
|
assert Challenges.query.count() == 0
|
||||||
|
destroy_ctfd(app)
|
||||||
|
|
||||||
|
|
||||||
def test_admin_chal_detail_returns_proper_data():
|
def test_admin_chal_detail_returns_proper_data():
|
||||||
"""Test that the /admin/chals/<int:chalid> endpoint returns the proper data"""
|
"""Test that the /admin/chals/<int:chalid> endpoint returns the proper data"""
|
||||||
app = create_ctfd()
|
app = create_ctfd()
|
||||||
|
|||||||
Reference in New Issue
Block a user