Skip to content

Commit

Permalink
Fix admin cannot modify verified status in Edit User (CTFd#777)
Browse files Browse the repository at this point in the history
* Grant admin write access to verified field in UserSchema.
* Add test admin can view and modify verified status
* Add test for creating users with settings
* Add codecov threshold for test failures
  • Loading branch information
Raihan Ramadistra authored and ColdHeat committed Dec 4, 2018
1 parent 809e4df commit 64b96d9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
coverage:
status:
project:
default:
# Fail the status if coverage drops by >= 1%
threshold: 1
patch:
default:
threshold: 1
3 changes: 2 additions & 1 deletion CTFd/schemas/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ def validate_password_confirmation(self, data):
'id',
'oauth_id',
'password',
'type'
'type',
'verified'
]
}

Expand Down
33 changes: 31 additions & 2 deletions tests/api/v1/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,32 @@ def test_api_users_post_admin():
destroy_ctfd(app)


def test_api_users_post_admin_with_attributes():
"""Can a user post /api/v1/users with user settings"""
app = create_ctfd()
with app.app_context():
with login_as_user(app, 'admin') as client:
# Create user
r = client.post('/api/v1/users', json={
"name": "user",
"email": "[email protected]",
"password": "password",
"banned": True,
"hidden": True,
"verified": True
})
assert r.status_code == 200

# Make sure password was hashed properly
user = Users.query.filter_by(email='[email protected]').first()
assert user
assert verify_password('password', user.password)
assert user.banned
assert user.hidden
assert user.verified
destroy_ctfd(app)


def test_api_team_get_public():
"""Can a user get /api/v1/team/<user_id> if users are public"""
app = create_ctfd()
Expand Down Expand Up @@ -168,10 +194,13 @@ def test_api_user_patch_admin():
"name": "user",
"email": "[email protected]",
"password": "password",
"country": "US"
"country": "US",
"verified": True
})
assert r.status_code == 200
assert r.get_json()['data'][0]['country'] == 'US'
user_data = r.get_json()['data'][0]
assert user_data['country'] == 'US'
assert user_data['verified'] is True
destroy_ctfd(app)


Expand Down

0 comments on commit 64b96d9

Please sign in to comment.