diff --git a/CTFd/utils/decorators/__init__.py b/CTFd/utils/decorators/__init__.py index 4824797c..f5cf1d1b 100644 --- a/CTFd/utils/decorators/__init__.py +++ b/CTFd/utils/decorators/__init__.py @@ -29,8 +29,11 @@ def during_ctf_time_only(f): error = "{} has ended".format(config.ctf_name()) abort(403, description=error) if ctf_started() is False: - error = "{} has not started yet".format(config.ctf_name()) - abort(403, description=error) + if is_teams_mode() and get_current_team() is None: + return redirect(url_for("teams.private", next=request.full_path)) + else: + error = "{} has not started yet".format(config.ctf_name()) + abort(403, description=error) return during_ctf_time_only_wrapper diff --git a/tests/utils/test_ctftime.py b/tests/utils/test_ctftime.py index 3884c87e..81e1abcc 100644 --- a/tests/utils/test_ctftime.py +++ b/tests/utils/test_ctftime.py @@ -1,11 +1,13 @@ from CTFd.models import Solves from CTFd.utils.dates import ctf_ended, ctf_started +from CTFd.utils.modes import TEAMS_MODE from tests.helpers import ( create_ctfd, ctftime, destroy_ctfd, gen_challenge, gen_flag, + gen_team, login_as_user, register_user, ) @@ -36,6 +38,43 @@ def test_ctftime_prevents_accessing_challenges_before_ctf(): destroy_ctfd(app) +def test_ctftime_redirects_to_teams_page_in_teams_mode_before_ctf(): + """ + Test that the ctftime function redirects users to the team creation page in teams mode before the ctf if the user + has no team yet. + """ + app = create_ctfd(user_mode=TEAMS_MODE) + with app.app_context(): + with ctftime.init(): + register_user(app) + chal = gen_challenge(app.db) + gen_flag(app.db, challenge_id=chal.id, content=u"flag") + + with ctftime.not_started(): + client = login_as_user(app) + r = client.get("/challenges") + assert r.status_code == 302 + + gen_team(app.db, name="test", password="password") + with login_as_user(app) as client: + r = client.get("/teams/join") + assert r.status_code == 200 + with client.session_transaction() as sess: + data = { + "name": "test", + "password": "password", + "nonce": sess.get("nonce"), + } + r = client.post("/teams/join", data=data) + assert r.status_code == 302 + + with ctftime.not_started(): + client = login_as_user(app) + r = client.get("/challenges") + assert r.status_code == 403 + destroy_ctfd(app) + + def test_ctftime_allows_accessing_challenges_during_ctf(): """Test that the ctftime function allows accessing challenges during the ctf""" app = create_ctfd()