Add a way to access the challenge plugin class from the Challenges model (#1925)

* Add a way to access the challenge plugin class from the Challenges model
   * Allows templates to access the plugin class more easily
   * Allows plugins to access the plugin class without having to load the class explicitly
* Closes #1879
This commit is contained in:
Kevin Chung
2021-06-26 15:03:18 -04:00
committed by GitHub
parent ff6e093fa6
commit 31e8261bad
2 changed files with 27 additions and 1 deletions

View File

@@ -14,7 +14,13 @@ from CTFd.plugins import (
register_plugin_script,
register_user_page_menu_bar,
)
from tests.helpers import create_ctfd, destroy_ctfd, login_as_user, setup_ctfd
from tests.helpers import (
create_ctfd,
destroy_ctfd,
gen_challenge,
login_as_user,
setup_ctfd,
)
def test_register_plugin_asset():
@@ -204,3 +210,17 @@ def test_bypass_csrf_protection():
assert r.status_code == 200
assert output == "Success"
destroy_ctfd(app)
def test_challenges_model_access_plugin_class():
"""
Test that the Challenges model can access its plugin class
"""
app = create_ctfd()
with app.app_context():
from CTFd.plugins.challenges import get_chal_class
chal = gen_challenge(app.db)
assert chal.plugin_class == get_chal_class("standard")
destroy_ctfd(app)