diff --git a/CTFd/plugins/challenges/__init__.py b/CTFd/plugins/challenges/__init__.py index ce3af7a4..e06faea3 100644 --- a/CTFd/plugins/challenges/__init__.py +++ b/CTFd/plugins/challenges/__init__.py @@ -1,6 +1,6 @@ from CTFd.plugins import register_plugin_assets_directory 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 @@ -128,6 +128,7 @@ class CTFdStandardChallenge(BaseChallenge): utils.delete_file(f.id) Files.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() db.session.commit() diff --git a/tests/admin/test_admin_facing.py b/tests/admin/test_admin_facing.py index f3b738c2..826e9d92 100644 --- a/tests/admin/test_admin_facing.py +++ b/tests/admin/test_admin_facing.py @@ -202,6 +202,31 @@ def test_admins_can_delete_challenges(): 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(): """Test that the /admin/chals/ endpoint returns the proper data""" app = create_ctfd()