@@ -181,6 +181,40 @@ def test_team_size_limit():
181
181
destroy_ctfd (app )
182
182
183
183
184
+ def test_num_teams_limit ():
185
+ """Only num_teams teams can be created"""
186
+ app = create_ctfd (user_mode = "teams" )
187
+ with app .app_context ():
188
+ set_config ("num_teams" , 1 )
189
+
190
+ # Create a team
191
+ gen_team (app .db , member_count = 1 )
192
+
193
+ register_user (app )
194
+ with login_as_user (app ) as client :
195
+ r = client .get ("/teams/new" )
196
+ assert r .status_code == 403
197
+
198
+ # team should be blocked from creation
199
+ with client .session_transaction () as sess :
200
+ data = {
201
+ "name" : "team1" ,
202
+ "password" : "password" ,
203
+ "nonce" : sess .get ("nonce" ),
204
+ }
205
+ r = client .post ("/teams/new" , data = data )
206
+ resp = r .get_data (as_text = True )
207
+ assert Teams .query .count () == 1
208
+ assert "Reached the maximum number of teams" in resp
209
+
210
+ # Can the team be created after the num has been bumped
211
+ set_config ("num_teams" , 2 )
212
+ r = client .post ("/teams/new" , data = data )
213
+ resp = r .get_data (as_text = True )
214
+ assert Teams .query .count () == 2
215
+ destroy_ctfd (app )
216
+
217
+
184
218
def test_team_creation_disable ():
185
219
app = create_ctfd (user_mode = "teams" )
186
220
with app .app_context ():
0 commit comments