@@ -170,21 +170,31 @@ def test_cancel(self):
170170 """Test that a registered user can cancel her account."""
171171 # test registration workflow
172172 username , password = 'newuser' , 'password'
173- first_name , last_name = 'Otto' , 'Test'
174- email = 'autotest@deis.io'
175173 submit = {
176174 'username' : username ,
177175 'password' : password ,
178- 'first_name' : first_name ,
179- 'last_name' : last_name ,
180- 'email' : email ,
176+ 'first_name' : 'Otto' ,
177+ 'last_name' : 'Test' ,
178+ 'email' : 'autotest@deis.io' ,
181179 # try to abuse superuser/staff level perms
182180 'is_superuser' : True ,
183181 'is_staff' : True ,
184182 }
183+
184+ other_username , other_password = 'newuser2' , 'password'
185+ other_submit = {
186+ 'username' : other_username ,
187+ 'password' : other_password ,
188+ 'first_name' : 'Test' ,
189+ 'last_name' : 'Tester' ,
190+ 'email' : 'autotest-2@deis.io' ,
191+ 'is_superuser' : False ,
192+ 'is_staff' : False ,
193+ }
185194 url = '/v1/auth/register'
186195 response = self .client .post (url , json .dumps (submit ), content_type = 'application/json' )
187196 self .assertEqual (response .status_code , 201 )
197+
188198 # cancel the account
189199 url = '/v1/auth/cancel'
190200 user = User .objects .get (username = username )
@@ -193,6 +203,25 @@ def test_cancel(self):
193203 HTTP_AUTHORIZATION = 'token {}' .format (token ))
194204 self .assertEqual (response .status_code , 204 )
195205
206+ url = '/v1/auth/register'
207+ response = self .client .post (url , json .dumps (other_submit ), content_type = 'application/json' )
208+ self .assertEqual (response .status_code , 201 )
209+
210+ # normal user can't delete another user
211+ url = '/v1/auth/cancel'
212+ other_user = User .objects .get (username = other_username )
213+ other_token = Token .objects .get (user = other_user ).key
214+ response = self .client .delete (url , json .dumps ({'username' : self .admin .username }),
215+ content_type = 'application/json' ,
216+ HTTP_AUTHORIZATION = 'token {}' .format (other_token ))
217+ self .assertEqual (response .status_code , 403 )
218+
219+ # admin can delete another user
220+ response = self .client .delete (url , json .dumps ({'username' : other_username }),
221+ content_type = 'application/json' ,
222+ HTTP_AUTHORIZATION = 'token {}' .format (self .admin_token ))
223+ self .assertEqual (response .status_code , 204 )
224+
196225 def test_passwd (self ):
197226 """Test that a registered user can change the password."""
198227 # test registration workflow
0 commit comments