Redirect users to team creation before event start (#2185)

* Redirect users to the team creation page if they access a during_ctf_time_only page before the CTF starts
This commit is contained in:
Janos Bonic
2022-09-23 05:35:43 +01:00
committed by GitHub
parent 04de6c0b4f
commit 02c08f50cc
2 changed files with 44 additions and 2 deletions

View File

@@ -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

View File

@@ -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()