13
13
# See the License for the specific language governing permissions and
14
14
# limitations under the License.
15
15
16
- from typing import List , Union
16
+ from typing import Union
17
17
18
18
from twisted .internet .defer import succeed
19
19
@@ -177,13 +177,8 @@ def create_resource_dict(self):
177
177
def prepare (self , reactor , clock , hs ):
178
178
self .user_pass = "pass"
179
179
self .user = self .register_user ("test" , self .user_pass )
180
- self .user_tok = self .login ("test" , self .user_pass )
181
-
182
- def get_device_ids (self , access_token : str ) -> List [str ]:
183
- # Get the list of devices so one can be deleted.
184
- channel = self .make_request ("GET" , "devices" , access_token = access_token ,)
185
- self .assertEqual (channel .code , 200 )
186
- return [d ["device_id" ] for d in channel .json_body ["devices" ]]
180
+ self .device_id = "dev1"
181
+ self .user_tok = self .login ("test" , self .user_pass , self .device_id )
187
182
188
183
def delete_device (
189
184
self ,
@@ -219,11 +214,9 @@ def test_ui_auth(self):
219
214
"""
220
215
Test user interactive authentication outside of registration.
221
216
"""
222
- device_id = self .get_device_ids (self .user_tok )[0 ]
223
-
224
217
# Attempt to delete this device.
225
218
# Returns a 401 as per the spec
226
- channel = self .delete_device (self .user_tok , device_id , 401 )
219
+ channel = self .delete_device (self .user_tok , self . device_id , 401 )
227
220
228
221
# Grab the session
229
222
session = channel .json_body ["session" ]
@@ -233,7 +226,7 @@ def test_ui_auth(self):
233
226
# Make another request providing the UI auth flow.
234
227
self .delete_device (
235
228
self .user_tok ,
236
- device_id ,
229
+ self . device_id ,
237
230
200 ,
238
231
{
239
232
"auth" : {
@@ -252,14 +245,13 @@ def test_grandfathered_identifier(self):
252
245
UIA - check that still works.
253
246
"""
254
247
255
- device_id = self .get_device_ids (self .user_tok )[0 ]
256
- channel = self .delete_device (self .user_tok , device_id , 401 )
248
+ channel = self .delete_device (self .user_tok , self .device_id , 401 )
257
249
session = channel .json_body ["session" ]
258
250
259
251
# Make another request providing the UI auth flow.
260
252
self .delete_device (
261
253
self .user_tok ,
262
- device_id ,
254
+ self . device_id ,
263
255
200 ,
264
256
{
265
257
"auth" : {
@@ -282,14 +274,11 @@ def test_can_change_body(self):
282
274
session ID should be rejected.
283
275
"""
284
276
# Create a second login.
285
- self .login ("test" , self .user_pass )
286
-
287
- device_ids = self .get_device_ids (self .user_tok )
288
- self .assertEqual (len (device_ids ), 2 )
277
+ self .login ("test" , self .user_pass , "dev2" )
289
278
290
279
# Attempt to delete the first device.
291
280
# Returns a 401 as per the spec
292
- channel = self .delete_devices (401 , {"devices" : [device_ids [ 0 ] ]})
281
+ channel = self .delete_devices (401 , {"devices" : [self . device_id ]})
293
282
294
283
# Grab the session
295
284
session = channel .json_body ["session" ]
@@ -301,7 +290,7 @@ def test_can_change_body(self):
301
290
self .delete_devices (
302
291
200 ,
303
292
{
304
- "devices" : [device_ids [ 1 ] ],
293
+ "devices" : ["dev2" ],
305
294
"auth" : {
306
295
"type" : "m.login.password" ,
307
296
"identifier" : {"type" : "m.id.user" , "user" : self .user },
@@ -316,14 +305,11 @@ def test_cannot_change_uri(self):
316
305
The initial requested URI cannot be modified during the user interactive authentication session.
317
306
"""
318
307
# Create a second login.
319
- self .login ("test" , self .user_pass )
320
-
321
- device_ids = self .get_device_ids (self .user_tok )
322
- self .assertEqual (len (device_ids ), 2 )
308
+ self .login ("test" , self .user_pass , "dev2" )
323
309
324
310
# Attempt to delete the first device.
325
311
# Returns a 401 as per the spec
326
- channel = self .delete_device (self .user_tok , device_ids [ 0 ] , 401 )
312
+ channel = self .delete_device (self .user_tok , self . device_id , 401 )
327
313
328
314
# Grab the session
329
315
session = channel .json_body ["session" ]
@@ -334,7 +320,7 @@ def test_cannot_change_uri(self):
334
320
# second device. This results in an error.
335
321
self .delete_device (
336
322
self .user_tok ,
337
- device_ids [ 1 ] ,
323
+ "dev2" ,
338
324
403 ,
339
325
{
340
326
"auth" : {
@@ -361,8 +347,7 @@ def test_does_not_offer_password_for_sso_user(self):
361
347
def test_does_not_offer_sso_for_password_user (self ):
362
348
# now call the device deletion API: we should get the option to auth with SSO
363
349
# and not password.
364
- device_ids = self .get_device_ids (self .user_tok )
365
- channel = self .delete_device (self .user_tok , device_ids [0 ], 401 )
350
+ channel = self .delete_device (self .user_tok , self .device_id , 401 )
366
351
367
352
flows = channel .json_body ["flows" ]
368
353
self .assertEqual (flows , [{"stages" : ["m.login.password" ]}])
@@ -373,8 +358,7 @@ def test_offers_both_flows_for_upgraded_user(self):
373
358
login_resp = self .helper .login_via_oidc (UserID .from_string (self .user ).localpart )
374
359
self .assertEqual (login_resp ["user_id" ], self .user )
375
360
376
- device_ids = self .get_device_ids (self .user_tok )
377
- channel = self .delete_device (self .user_tok , device_ids [0 ], 401 )
361
+ channel = self .delete_device (self .user_tok , self .device_id , 401 )
378
362
379
363
flows = channel .json_body ["flows" ]
380
364
# we have no particular expectations of ordering here
0 commit comments