mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 22:14:25 +01:00
Limit total number of teams (#1867)
* Adds support for a total teams limit
This commit is contained in:
@@ -181,6 +181,40 @@ def test_team_size_limit():
|
||||
destroy_ctfd(app)
|
||||
|
||||
|
||||
def test_num_teams_limit():
|
||||
"""Only num_teams teams can be created"""
|
||||
app = create_ctfd(user_mode="teams")
|
||||
with app.app_context():
|
||||
set_config("num_teams", 1)
|
||||
|
||||
# Create a team
|
||||
gen_team(app.db, member_count=1)
|
||||
|
||||
register_user(app)
|
||||
with login_as_user(app) as client:
|
||||
r = client.get("/teams/new")
|
||||
assert r.status_code == 403
|
||||
|
||||
# team should be blocked from creation
|
||||
with client.session_transaction() as sess:
|
||||
data = {
|
||||
"name": "team1",
|
||||
"password": "password",
|
||||
"nonce": sess.get("nonce"),
|
||||
}
|
||||
r = client.post("/teams/new", data=data)
|
||||
resp = r.get_data(as_text=True)
|
||||
assert Teams.query.count() == 1
|
||||
assert "Reached the maximum number of teams" in resp
|
||||
|
||||
# Can the team be created after the num has been bumped
|
||||
set_config("num_teams", 2)
|
||||
r = client.post("/teams/new", data=data)
|
||||
resp = r.get_data(as_text=True)
|
||||
assert Teams.query.count() == 2
|
||||
destroy_ctfd(app)
|
||||
|
||||
|
||||
def test_team_creation_disable():
|
||||
app = create_ctfd(user_mode="teams")
|
||||
with app.app_context():
|
||||
|
||||
Reference in New Issue
Block a user