|
11 | 11 | gen_flag,
|
12 | 12 | gen_user,
|
13 | 13 | gen_team,
|
14 |
| - gen_solve) |
| 14 | + gen_solve, |
| 15 | + gen_fail) |
15 | 16 | from freezegun import freeze_time
|
16 | 17 |
|
17 | 18 |
|
@@ -308,19 +309,56 @@ def test_api_challenge_attempt_post_private():
|
308 | 309 | """Can an private user post /api/v1/challenges/attempt"""
|
309 | 310 | app = create_ctfd()
|
310 | 311 | with app.app_context():
|
311 |
| - gen_challenge(app.db) |
312 |
| - gen_flag(app.db, 1) |
| 312 | + challenge_id = gen_challenge(app.db).id |
| 313 | + gen_flag(app.db, challenge_id) |
313 | 314 | register_user(app)
|
314 | 315 | with login_as_user(app) as client:
|
315 |
| - r = client.post('/api/v1/challenges/attempt', json={"challenge_id": 1, "submission": "wrong_flag"}) |
| 316 | + r = client.post('/api/v1/challenges/attempt', json={"challenge_id": challenge_id, "submission": "wrong_flag"}) |
316 | 317 | assert r.status_code == 200
|
317 | 318 | assert r.get_json()['data']['status'] == 'incorrect'
|
318 |
| - r = client.post('/api/v1/challenges/attempt', json={"challenge_id": 1, "submission": "flag"}) |
| 319 | + r = client.post('/api/v1/challenges/attempt', json={"challenge_id": challenge_id, "submission": "flag"}) |
319 | 320 | assert r.status_code == 200
|
320 | 321 | assert r.get_json()['data']['status'] == 'correct'
|
321 |
| - r = client.post('/api/v1/challenges/attempt', json={"challenge_id": 1, "submission": "flag"}) |
| 322 | + r = client.post('/api/v1/challenges/attempt', json={"challenge_id": challenge_id, "submission": "flag"}) |
322 | 323 | assert r.status_code == 200
|
323 | 324 | assert r.get_json()['data']['status'] == 'already_solved'
|
| 325 | + challenge_id = gen_challenge(app.db).id |
| 326 | + gen_flag(app.db, challenge_id) |
| 327 | + with login_as_user(app) as client: |
| 328 | + for i in range(10): |
| 329 | + gen_fail(app.db, user_id=2, challenge_id=challenge_id) |
| 330 | + r = client.post('/api/v1/challenges/attempt', json={"challenge_id": challenge_id, "submission": "flag"}) |
| 331 | + assert r.status_code == 429 |
| 332 | + assert r.get_json()['data']['status'] == 'ratelimited' |
| 333 | + destroy_ctfd(app) |
| 334 | + |
| 335 | + app = create_ctfd(user_mode="teams") |
| 336 | + with app.app_context(): |
| 337 | + challenge_id = gen_challenge(app.db).id |
| 338 | + gen_flag(app.db, challenge_id) |
| 339 | + register_user(app) |
| 340 | + team_id = gen_team(app.db).id |
| 341 | + user = Users.query.filter_by(id=2).first() |
| 342 | + user.team_id = team_id |
| 343 | + app.db.session.commit() |
| 344 | + with login_as_user(app) as client: |
| 345 | + r = client.post('/api/v1/challenges/attempt', json={"challenge_id": challenge_id, "submission": "wrong_flag"}) |
| 346 | + assert r.status_code == 200 |
| 347 | + assert r.get_json()['data']['status'] == 'incorrect' |
| 348 | + r = client.post('/api/v1/challenges/attempt', json={"challenge_id": challenge_id, "submission": "flag"}) |
| 349 | + assert r.status_code == 200 |
| 350 | + assert r.get_json()['data']['status'] == 'correct' |
| 351 | + r = client.post('/api/v1/challenges/attempt', json={"challenge_id": challenge_id, "submission": "flag"}) |
| 352 | + assert r.status_code == 200 |
| 353 | + assert r.get_json()['data']['status'] == 'already_solved' |
| 354 | + challenge_id = gen_challenge(app.db).id |
| 355 | + gen_flag(app.db, challenge_id) |
| 356 | + with login_as_user(app) as client: |
| 357 | + for i in range(10): |
| 358 | + gen_fail(app.db, user_id=2, team_id=team_id, challenge_id=challenge_id) |
| 359 | + r = client.post('/api/v1/challenges/attempt', json={"challenge_id": challenge_id, "submission": "flag"}) |
| 360 | + assert r.status_code == 429 |
| 361 | + assert r.get_json()['data']['status'] == 'ratelimited' |
324 | 362 | destroy_ctfd(app)
|
325 | 363 |
|
326 | 364 |
|
|
0 commit comments