@@ -251,12 +251,11 @@ def test_change_user_passwd(self):
251251 new_password = 'password'
252252 submit = {
253253 'username' : self .user1 .username ,
254- 'password' : old_password ,
255254 'new_password' : new_password ,
256255 }
257256 response = self .client .post (url , json .dumps (submit ), content_type = 'application/json' ,
258257 HTTP_AUTHORIZATION = 'token {}' .format (self .admin_token ))
259- self .assertEqual (response .status_code , 400 )
258+ self .assertEqual (response .status_code , 200 )
260259 # test login with old password
261260 url = '/v1/auth/login/'
262261 payload = urllib .urlencode ({'username' : self .user1 .username , 'password' : old_password })
@@ -268,16 +267,22 @@ def test_change_user_passwd(self):
268267 response = self .client .post (url , data = payload ,
269268 content_type = 'application/x-www-form-urlencoded' )
270269 self .assertEqual (response .status_code , 200 )
271- # try to change back password with a regular user
272- submit ['password' ], submit ['new_password' ] = submit ['new_password' ], submit [ 'password' ]
270+ # Non-admins can't change another user's password
271+ submit ['password' ], submit ['new_password' ] = submit ['new_password' ], old_password
273272 url = '/v1/auth/passwd'
274273 response = self .client .post (url , json .dumps (submit ), content_type = 'application/json' ,
275274 HTTP_AUTHORIZATION = 'token {}' .format (self .user2_token ))
276275 self .assertEqual (response .status_code , 403 )
277- # however, targeting yourself should be fine.
276+ # change back password with a regular user
278277 response = self .client .post (url , json .dumps (submit ), content_type = 'application/json' ,
279278 HTTP_AUTHORIZATION = 'token {}' .format (self .user1_token ))
280279 self .assertEqual (response .status_code , 200 )
280+ # test login with new password
281+ url = '/v1/auth/login/'
282+ payload = urllib .urlencode ({'username' : self .user1 .username , 'password' : old_password })
283+ response = self .client .post (url , data = payload ,
284+ content_type = 'application/x-www-form-urlencoded' )
285+ self .assertEqual (response .status_code , 200 )
281286
282287 def test_regenerate (self ):
283288 """ Test that token regeneration works"""
0 commit comments