@@ -104,7 +104,7 @@ def test_extract_user_identifier_params_use_nameid_missing(self):
104
104
self .assertEqual (lookup_value , None )
105
105
106
106
def test_is_authorized (self ):
107
- self .assertTrue (self .backend .is_authorized ({}, {}, '' ))
107
+ self .assertTrue (self .backend .is_authorized ({}, {}, '' , {} ))
108
108
109
109
def test_clean_attributes (self ):
110
110
attributes = {'random' : 'dummy' , 'value' : 123 }
@@ -333,9 +333,9 @@ def test_deprecations(self):
333
333
class CustomizedBackend (Saml2Backend ):
334
334
""" Override the available methods with some customized implementation to test customization
335
335
"""
336
- def is_authorized (self , attributes , attribute_mapping , idp_entityid : str , ** kwargs ):
336
+ def is_authorized (self , attributes , attribute_mapping , idp_entityid : str , assertion_info , ** kwargs ):
337
337
''' Allow only staff users from the IDP '''
338
- return attributes .get ('is_staff' , (None , ))[0 ] == True
338
+ return attributes .get ('is_staff' , (None , ))[0 ] == True and assertion_info . get ( 'assertion_id' , None ) != None
339
339
340
340
def clean_attributes (self , attributes : dict , idp_entityid : str , ** kwargs ) -> dict :
341
341
''' Keep only age attribute '''
@@ -368,9 +368,15 @@ def test_is_authorized(self):
368
368
'cn' : ('John' , ),
369
369
'sn' : ('Doe' , ),
370
370
}
371
- self .assertFalse (self .backend .is_authorized (attributes , attribute_mapping , '' ))
371
+ assertion_info = {
372
+ 'assertion_id' : None ,
373
+ 'not_on_or_after' : None ,
374
+ }
375
+ self .assertFalse (self .backend .is_authorized (attributes , attribute_mapping , '' , assertion_info ))
372
376
attributes ['is_staff' ] = (True , )
373
- self .assertTrue (self .backend .is_authorized (attributes , attribute_mapping , '' ))
377
+ self .assertFalse (self .backend .is_authorized (attributes , attribute_mapping , '' , assertion_info ))
378
+ assertion_info ['assertion_id' ] = 'abcdefg12345'
379
+ self .assertTrue (self .backend .is_authorized (attributes , attribute_mapping , '' , assertion_info ))
374
380
375
381
def test_clean_attributes (self ):
376
382
attributes = {'random' : 'dummy' , 'value' : 123 , 'age' : '28' }
@@ -396,6 +402,10 @@ def test_authenticate(self):
396
402
'age' : ('28' , ),
397
403
'is_staff' : (True , ),
398
404
}
405
+ assertion_info = {
406
+ 'assertion_id' : 'abcdefg12345' ,
407
+ 'not_on_or_after' : '' ,
408
+ }
399
409
400
410
self .assertEqual (self .user .age , '' )
401
411
self .assertEqual (self .user .is_staff , False )
@@ -409,6 +419,7 @@ def test_authenticate(self):
409
419
None ,
410
420
session_info = {'random' : 'content' },
411
421
attribute_mapping = attribute_mapping ,
422
+ assertion_info = assertion_info ,
412
423
)
413
424
self .assertIsNone (user )
414
425
@@ -417,6 +428,7 @@ def test_authenticate(self):
417
428
None ,
418
429
session_info = {'ava' : attributes , 'issuer' : 'dummy_entity_id' },
419
430
attribute_mapping = attribute_mapping ,
431
+ assertion_info = assertion_info ,
420
432
)
421
433
self .assertIsNone (user )
422
434
@@ -425,6 +437,7 @@ def test_authenticate(self):
425
437
None ,
426
438
session_info = {'ava' : attributes , 'issuer' : 'dummy_entity_id' },
427
439
attribute_mapping = attribute_mapping ,
440
+ assertion_info = assertion_info ,
428
441
)
429
442
self .assertIsNone (user )
430
443
@@ -433,6 +446,7 @@ def test_authenticate(self):
433
446
None ,
434
447
session_info = {'ava' : attributes , 'issuer' : 'dummy_entity_id' },
435
448
attribute_mapping = attribute_mapping ,
449
+ assertion_info = assertion_info ,
436
450
)
437
451
438
452
self .assertEqual (user , self .user )
0 commit comments