@@ -451,21 +451,23 @@ def test_delegated_role_class(self):
451
451
with self .assertRaises (ValueError ):
452
452
DelegatedRole .from_dict (role .copy ())
453
453
454
- # Test creating DelegatedRole only with "path_hash_prefixes"
454
+ # Test creating DelegatedRole only with "path_hash_prefixes" (an empty one)
455
455
del role ["paths" ]
456
- DelegatedRole .from_dict (role .copy ())
457
- role ["paths" ] = "foo"
456
+ role ["path_hash_prefixes" ] = []
457
+ role_obj = DelegatedRole .from_dict (role .copy ())
458
+ self .assertEqual (role_obj .to_dict (), role )
458
459
459
- # Test creating DelegatedRole only with "paths"
460
+ # Test creating DelegatedRole only with "paths" (now an empty one)
460
461
del role ["path_hash_prefixes" ]
461
- DelegatedRole .from_dict (role .copy ())
462
- role ["path_hash_prefixes" ] = "foo"
462
+ role ["paths" ] = []
463
+ role_obj = DelegatedRole .from_dict (role .copy ())
464
+ self .assertEqual (role_obj .to_dict (), role )
463
465
464
466
# Test creating DelegatedRole without "paths" and
465
467
# "path_hash_prefixes" set
466
468
del role ["paths" ]
467
- del role [ "path_hash_prefixes" ]
468
- DelegatedRole . from_dict ( role )
469
+ role_obj = DelegatedRole . from_dict ( role . copy ())
470
+ self . assertEqual ( role_obj . to_dict (), role )
469
471
470
472
471
473
def test_delegation_class (self ):
@@ -495,6 +497,21 @@ def test_delegation_class(self):
495
497
delegations = Delegations .from_dict (copy .deepcopy (delegations_dict ))
496
498
self .assertEqual (delegations_dict , delegations .to_dict ())
497
499
500
+ # empty keys and roles
501
+ delegations_dict = {"keys" :{}, "roles" :[]}
502
+ delegations = Delegations .from_dict (delegations_dict .copy ())
503
+ self .assertEqual (delegations_dict , delegations .to_dict ())
504
+
505
+ # Test some basic missing or broken input
506
+ invalid_delegations_dicts = [
507
+ {},
508
+ {"keys" :None , "roles" :None },
509
+ {"keys" :{"foo" :0 }, "roles" :[]},
510
+ {"keys" :{}, "roles" :["foo" ]},
511
+ ]
512
+ for d in invalid_delegations_dicts :
513
+ with self .assertRaises ((KeyError , AttributeError )):
514
+ Delegations .from_dict (d )
498
515
499
516
def test_metadata_targets (self ):
500
517
targets_path = os .path .join (
0 commit comments