mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 14:04:20 +01:00
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:
@@ -29,6 +29,9 @@ def during_ctf_time_only(f):
|
|||||||
error = "{} has ended".format(config.ctf_name())
|
error = "{} has ended".format(config.ctf_name())
|
||||||
abort(403, description=error)
|
abort(403, description=error)
|
||||||
if ctf_started() is False:
|
if ctf_started() is False:
|
||||||
|
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())
|
error = "{} has not started yet".format(config.ctf_name())
|
||||||
abort(403, description=error)
|
abort(403, description=error)
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
from CTFd.models import Solves
|
from CTFd.models import Solves
|
||||||
from CTFd.utils.dates import ctf_ended, ctf_started
|
from CTFd.utils.dates import ctf_ended, ctf_started
|
||||||
|
from CTFd.utils.modes import TEAMS_MODE
|
||||||
from tests.helpers import (
|
from tests.helpers import (
|
||||||
create_ctfd,
|
create_ctfd,
|
||||||
ctftime,
|
ctftime,
|
||||||
destroy_ctfd,
|
destroy_ctfd,
|
||||||
gen_challenge,
|
gen_challenge,
|
||||||
gen_flag,
|
gen_flag,
|
||||||
|
gen_team,
|
||||||
login_as_user,
|
login_as_user,
|
||||||
register_user,
|
register_user,
|
||||||
)
|
)
|
||||||
@@ -36,6 +38,43 @@ def test_ctftime_prevents_accessing_challenges_before_ctf():
|
|||||||
destroy_ctfd(app)
|
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():
|
def test_ctftime_allows_accessing_challenges_during_ctf():
|
||||||
"""Test that the ctftime function allows accessing challenges during the ctf"""
|
"""Test that the ctftime function allows accessing challenges during the ctf"""
|
||||||
app = create_ctfd()
|
app = create_ctfd()
|
||||||
|
|||||||
Reference in New Issue
Block a user