Properly load schemas specified as strings (#943)

* Properly load schemas specified by their key string
* Add test for UserSchema 
* Prevent users without teams from interacting with challenges if the CTF is in Team Mode
This commit is contained in:
Kevin Chung
2019-04-08 01:47:26 -04:00
committed by GitHub
parent 7c60c697ee
commit c0a32a836b
16 changed files with 111 additions and 24 deletions

View File

@@ -480,3 +480,37 @@ def test_api_accessing_hidden_banned_users():
assert client.get('/api/v1/teams/2/fails').status_code == 200
assert client.get('/api/v1/teams/2/awards').status_code == 200
destroy_ctfd(app)
def test_api_user_without_team_challenge_interaction():
"""Can a user interact with challenges without having joined a team?"""
app = create_ctfd(user_mode="teams")
with app.app_context():
register_user(app)
gen_challenge(app.db)
gen_flag(app.db, 1)
with login_as_user(app) as client:
assert client.get('/api/v1/challenges').status_code == 403
assert client.get('/api/v1/challenges/1').status_code == 403
assert client.post('/api/v1/challenges/attempt', json={
"challenge_id": 1,
"submission": "wrong_flag"
}).status_code == 403
# Create a user with a team
user = gen_user(app.db, email='user_name@ctfd.io')
team = gen_team(app.db)
team.members.append(user)
user.team_id = team.id
app.db.session.commit()
# Test if user with team can interact with challenges
with login_as_user(app, name="user_name") as client:
assert client.get('/api/v1/challenges').status_code == 200
assert client.get('/api/v1/challenges/1').status_code == 200
assert client.post('/api/v1/challenges/attempt', json={
"challenge_id": 1,
"submission": "flag"
}).status_code == 200
destroy_ctfd(app)