2121from django .core .exceptions import ImproperlyConfigured
2222from django .test import TestCase , override_settings
2323from djangosaml2 .backends import Saml2Backend , set_attribute
24- from saml2 .saml import Assertion
2524
2625from testprofiles .models import TestUser
2726
@@ -105,7 +104,7 @@ def test_extract_user_identifier_params_use_nameid_missing(self):
105104 self .assertEqual (lookup_value , None )
106105
107106 def test_is_authorized (self ):
108- self .assertTrue (self .backend .is_authorized ({}, {}, '' , None ))
107+ self .assertTrue (self .backend .is_authorized ({}, {}, '' , {} ))
109108
110109 def test_clean_attributes (self ):
111110 attributes = {'random' : 'dummy' , 'value' : 123 }
@@ -334,9 +333,9 @@ def test_deprecations(self):
334333class CustomizedBackend (Saml2Backend ):
335334 """ Override the available methods with some customized implementation to test customization
336335 """
337- def is_authorized (self , attributes , attribute_mapping , idp_entityid : str , assertion , ** kwargs ):
336+ def is_authorized (self , attributes , attribute_mapping , idp_entityid : str , assertion_info , ** kwargs ):
338337 ''' Allow only staff users from the IDP '''
339- return attributes .get ('is_staff' , (None , ))[0 ] == True and getattr ( assertion , 'id ' , None ) != None
338+ return attributes .get ('is_staff' , (None , ))[0 ] == True and assertion_info . get ( 'assertion_id ' , None ) != None
340339
341340 def clean_attributes (self , attributes : dict , idp_entityid : str , ** kwargs ) -> dict :
342341 ''' Keep only age attribute '''
@@ -369,12 +368,15 @@ def test_is_authorized(self):
369368 'cn' : ('John' , ),
370369 'sn' : ('Doe' , ),
371370 }
372- assertion = Assertion ()
373- self .assertFalse (self .backend .is_authorized (attributes , attribute_mapping , '' , assertion ))
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 ))
374376 attributes ['is_staff' ] = (True , )
375- self .assertFalse (self .backend .is_authorized (attributes , attribute_mapping , '' , assertion ))
376- assertion . id = 'abcdefg12345'
377- self .assertTrue (self .backend .is_authorized (attributes , attribute_mapping , '' , assertion ))
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 ))
378380
379381 def test_clean_attributes (self ):
380382 attributes = {'random' : 'dummy' , 'value' : 123 , 'age' : '28' }
@@ -400,7 +402,10 @@ def test_authenticate(self):
400402 'age' : ('28' , ),
401403 'is_staff' : (True , ),
402404 }
403- assertion = Assertion (id = 'abcdefg12345' )
405+ assertion_info = {
406+ 'assertion_id' : 'abcdefg12345' ,
407+ 'not_on_or_after' : '' ,
408+ }
404409
405410 self .assertEqual (self .user .age , '' )
406411 self .assertEqual (self .user .is_staff , False )
@@ -414,7 +419,7 @@ def test_authenticate(self):
414419 None ,
415420 session_info = {'random' : 'content' },
416421 attribute_mapping = attribute_mapping ,
417- assertion = assertion ,
422+ assertion_info = assertion_info ,
418423 )
419424 self .assertIsNone (user )
420425
@@ -423,7 +428,7 @@ def test_authenticate(self):
423428 None ,
424429 session_info = {'ava' : attributes , 'issuer' : 'dummy_entity_id' },
425430 attribute_mapping = attribute_mapping ,
426- assertion = assertion ,
431+ assertion_info = assertion_info ,
427432 )
428433 self .assertIsNone (user )
429434
@@ -432,7 +437,7 @@ def test_authenticate(self):
432437 None ,
433438 session_info = {'ava' : attributes , 'issuer' : 'dummy_entity_id' },
434439 attribute_mapping = attribute_mapping ,
435- assertion = assertion ,
440+ assertion_info = assertion_info ,
436441 )
437442 self .assertIsNone (user )
438443
@@ -441,7 +446,7 @@ def test_authenticate(self):
441446 None ,
442447 session_info = {'ava' : attributes , 'issuer' : 'dummy_entity_id' },
443448 attribute_mapping = attribute_mapping ,
444- assertion = assertion ,
449+ assertion_info = assertion_info ,
445450 )
446451
447452 self .assertEqual (user , self .user )
0 commit comments