Skip to content

Commit 64b96d9

Browse files
Raihan RamadistraColdHeat
Raihan Ramadistra
authored andcommitted
Fix admin cannot modify verified status in Edit User (CTFd#777)
* 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
1 parent 809e4df commit 64b96d9

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

.codecov.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
# Fail the status if coverage drops by >= 1%
6+
threshold: 1
7+
patch:
8+
default:
9+
threshold: 1

CTFd/schemas/users.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ def validate_password_confirmation(self, data):
152152
'id',
153153
'oauth_id',
154154
'password',
155-
'type'
155+
'type',
156+
'verified'
156157
]
157158
}
158159

tests/api/v1/test_users.py

+31-2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,32 @@ def test_api_users_post_admin():
9292
destroy_ctfd(app)
9393

9494

95+
def test_api_users_post_admin_with_attributes():
96+
"""Can a user post /api/v1/users with user settings"""
97+
app = create_ctfd()
98+
with app.app_context():
99+
with login_as_user(app, 'admin') as client:
100+
# Create user
101+
r = client.post('/api/v1/users', json={
102+
"name": "user",
103+
"email": "[email protected]",
104+
"password": "password",
105+
"banned": True,
106+
"hidden": True,
107+
"verified": True
108+
})
109+
assert r.status_code == 200
110+
111+
# Make sure password was hashed properly
112+
user = Users.query.filter_by(email='[email protected]').first()
113+
assert user
114+
assert verify_password('password', user.password)
115+
assert user.banned
116+
assert user.hidden
117+
assert user.verified
118+
destroy_ctfd(app)
119+
120+
95121
def test_api_team_get_public():
96122
"""Can a user get /api/v1/team/<user_id> if users are public"""
97123
app = create_ctfd()
@@ -168,10 +194,13 @@ def test_api_user_patch_admin():
168194
"name": "user",
169195
"email": "[email protected]",
170196
"password": "password",
171-
"country": "US"
197+
"country": "US",
198+
"verified": True
172199
})
173200
assert r.status_code == 200
174-
assert r.get_json()['data'][0]['country'] == 'US'
201+
user_data = r.get_json()['data'][0]
202+
assert user_data['country'] == 'US'
203+
assert user_data['verified'] is True
175204
destroy_ctfd(app)
176205

177206

0 commit comments

Comments
 (0)