Limit total number of teams (#1867)

* Adds support for a total teams limit
This commit is contained in:
Chris Frohoff
2021-06-25 20:00:40 -07:00
committed by GitHub
parent df27d0e7a9
commit dd05f57b6a
9 changed files with 110 additions and 1 deletions

View File

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