21
21
from django .core .exceptions import ImproperlyConfigured
22
22
from django .test import TestCase , override_settings
23
23
from djangosaml2 .backends import Saml2Backend , set_attribute
24
- from saml2 .saml import Assertion
25
24
26
25
from testprofiles .models import TestUser
27
26
@@ -105,7 +104,7 @@ def test_extract_user_identifier_params_use_nameid_missing(self):
105
104
self .assertEqual (lookup_value , None )
106
105
107
106
def test_is_authorized (self ):
108
- self .assertTrue (self .backend .is_authorized ({}, {}, '' , None ))
107
+ self .assertTrue (self .backend .is_authorized ({}, {}, '' , {} ))
109
108
110
109
def test_clean_attributes (self ):
111
110
attributes = {'random' : 'dummy' , 'value' : 123 }
@@ -334,9 +333,9 @@ def test_deprecations(self):
334
333
class CustomizedBackend (Saml2Backend ):
335
334
""" Override the available methods with some customized implementation to test customization
336
335
"""
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 ):
338
337
''' 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
340
339
341
340
def clean_attributes (self , attributes : dict , idp_entityid : str , ** kwargs ) -> dict :
342
341
''' Keep only age attribute '''
@@ -369,12 +368,15 @@ def test_is_authorized(self):
369
368
'cn' : ('John' , ),
370
369
'sn' : ('Doe' , ),
371
370
}
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 ))
374
376
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 ))
378
380
379
381
def test_clean_attributes (self ):
380
382
attributes = {'random' : 'dummy' , 'value' : 123 , 'age' : '28' }
@@ -400,7 +402,10 @@ def test_authenticate(self):
400
402
'age' : ('28' , ),
401
403
'is_staff' : (True , ),
402
404
}
403
- assertion = Assertion (id = 'abcdefg12345' )
405
+ assertion_info = {
406
+ 'assertion_id' : 'abcdefg12345' ,
407
+ 'not_on_or_after' : '' ,
408
+ }
404
409
405
410
self .assertEqual (self .user .age , '' )
406
411
self .assertEqual (self .user .is_staff , False )
@@ -414,7 +419,7 @@ def test_authenticate(self):
414
419
None ,
415
420
session_info = {'random' : 'content' },
416
421
attribute_mapping = attribute_mapping ,
417
- assertion = assertion ,
422
+ assertion_info = assertion_info ,
418
423
)
419
424
self .assertIsNone (user )
420
425
@@ -423,7 +428,7 @@ def test_authenticate(self):
423
428
None ,
424
429
session_info = {'ava' : attributes , 'issuer' : 'dummy_entity_id' },
425
430
attribute_mapping = attribute_mapping ,
426
- assertion = assertion ,
431
+ assertion_info = assertion_info ,
427
432
)
428
433
self .assertIsNone (user )
429
434
@@ -432,7 +437,7 @@ def test_authenticate(self):
432
437
None ,
433
438
session_info = {'ava' : attributes , 'issuer' : 'dummy_entity_id' },
434
439
attribute_mapping = attribute_mapping ,
435
- assertion = assertion ,
440
+ assertion_info = assertion_info ,
436
441
)
437
442
self .assertIsNone (user )
438
443
@@ -441,7 +446,7 @@ def test_authenticate(self):
441
446
None ,
442
447
session_info = {'ava' : attributes , 'issuer' : 'dummy_entity_id' },
443
448
attribute_mapping = attribute_mapping ,
444
- assertion = assertion ,
449
+ assertion_info = assertion_info ,
445
450
)
446
451
447
452
self .assertEqual (user , self .user )
0 commit comments