@@ -104,7 +104,7 @@ def test_extract_user_identifier_params_use_nameid_missing(self):
104104 self .assertEqual (lookup_value , None )
105105
106106 def test_is_authorized (self ):
107- self .assertTrue (self .backend .is_authorized ({}, {}, '' ))
107+ self .assertTrue (self .backend .is_authorized ({}, {}, '' , {} ))
108108
109109 def test_clean_attributes (self ):
110110 attributes = {'random' : 'dummy' , 'value' : 123 }
@@ -333,9 +333,9 @@ def test_deprecations(self):
333333class CustomizedBackend (Saml2Backend ):
334334 """ Override the available methods with some customized implementation to test customization
335335 """
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 ):
337337 ''' 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
339339
340340 def clean_attributes (self , attributes : dict , idp_entityid : str , ** kwargs ) -> dict :
341341 ''' Keep only age attribute '''
@@ -368,9 +368,15 @@ def test_is_authorized(self):
368368 'cn' : ('John' , ),
369369 'sn' : ('Doe' , ),
370370 }
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 ))
372376 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 ))
374380
375381 def test_clean_attributes (self ):
376382 attributes = {'random' : 'dummy' , 'value' : 123 , 'age' : '28' }
@@ -396,6 +402,10 @@ def test_authenticate(self):
396402 'age' : ('28' , ),
397403 'is_staff' : (True , ),
398404 }
405+ assertion_info = {
406+ 'assertion_id' : 'abcdefg12345' ,
407+ 'not_on_or_after' : '' ,
408+ }
399409
400410 self .assertEqual (self .user .age , '' )
401411 self .assertEqual (self .user .is_staff , False )
@@ -409,6 +419,7 @@ def test_authenticate(self):
409419 None ,
410420 session_info = {'random' : 'content' },
411421 attribute_mapping = attribute_mapping ,
422+ assertion_info = assertion_info ,
412423 )
413424 self .assertIsNone (user )
414425
@@ -417,6 +428,7 @@ def test_authenticate(self):
417428 None ,
418429 session_info = {'ava' : attributes , 'issuer' : 'dummy_entity_id' },
419430 attribute_mapping = attribute_mapping ,
431+ assertion_info = assertion_info ,
420432 )
421433 self .assertIsNone (user )
422434
@@ -425,6 +437,7 @@ def test_authenticate(self):
425437 None ,
426438 session_info = {'ava' : attributes , 'issuer' : 'dummy_entity_id' },
427439 attribute_mapping = attribute_mapping ,
440+ assertion_info = assertion_info ,
428441 )
429442 self .assertIsNone (user )
430443
@@ -433,6 +446,7 @@ def test_authenticate(self):
433446 None ,
434447 session_info = {'ava' : attributes , 'issuer' : 'dummy_entity_id' },
435448 attribute_mapping = attribute_mapping ,
449+ assertion_info = assertion_info ,
436450 )
437451
438452 self .assertEqual (user , self .user )
0 commit comments