|
28 | 28 | Timestamp, |
29 | 29 | Targets, |
30 | 30 | Key, |
31 | | - Role |
| 31 | + Role, |
| 32 | + Delegations, |
| 33 | + DelegatedRole, |
32 | 34 | ) |
33 | 35 |
|
34 | 36 | from tuf.api.serialization import ( |
@@ -328,7 +330,7 @@ def test_key_class(self): |
328 | 330 | "public": "edcd0a32a07dce33f7c7873aaffbff36d20ea30787574ead335eefd337e4dacd" |
329 | 331 | }, |
330 | 332 | "scheme": "ed25519" |
331 | | - }, |
| 333 | + }, |
332 | 334 | } |
333 | 335 | for key_dict in keys.values(): |
334 | 336 | # Testing that the workflow of deserializing and serializing |
@@ -422,6 +424,76 @@ def test_metadata_root(self): |
422 | 424 | with self.assertRaises(KeyError): |
423 | 425 | root.signed.remove_key('root', 'nosuchkey') |
424 | 426 |
|
| 427 | + def test_delegated_role_class(self): |
| 428 | + roles = [ |
| 429 | + { |
| 430 | + "keyids": [ |
| 431 | + "c8022fa1e9b9cb239a6b362bbdffa9649e61ad2cb699d2e4bc4fdf7930a0e64a" |
| 432 | + ], |
| 433 | + "name": "role1", |
| 434 | + "paths": [ |
| 435 | + "file3.txt" |
| 436 | + ], |
| 437 | + "terminating": False, |
| 438 | + "threshold": 1 |
| 439 | + } |
| 440 | + ] |
| 441 | + for role in roles: |
| 442 | + # Testing that the workflow of deserializing and serializing |
| 443 | + # a delegation role dictionary doesn't change the content. |
| 444 | + key_obj = DelegatedRole.from_dict(role.copy()) |
| 445 | + self.assertEqual(role, key_obj.to_dict()) |
| 446 | + |
| 447 | + # Test creating a DelegatedRole object with both "paths" and |
| 448 | + # "path_hash_prefixes" set. |
| 449 | + role["path_hash_prefixes"] = "foo" |
| 450 | + with self.assertRaises(ValueError): |
| 451 | + DelegatedRole.from_dict(role.copy()) |
| 452 | + |
| 453 | + # Test creating DelegatedRole only with "path_hash_prefixes" |
| 454 | + del role["paths"] |
| 455 | + DelegatedRole.from_dict(role.copy()) |
| 456 | + role["paths"] = "foo" |
| 457 | + |
| 458 | + # Test creating DelegatedRole only with "paths" |
| 459 | + del role["path_hash_prefixes"] |
| 460 | + DelegatedRole.from_dict(role.copy()) |
| 461 | + role["path_hash_prefixes"] = "foo" |
| 462 | + |
| 463 | + # Test creating DelegatedRole without "paths" and |
| 464 | + # "path_hash_prefixes" set |
| 465 | + del role["paths"] |
| 466 | + del role["path_hash_prefixes"] |
| 467 | + DelegatedRole.from_dict(role) |
| 468 | + |
| 469 | + |
| 470 | + def test_delegation_class(self): |
| 471 | + roles = [ |
| 472 | + { |
| 473 | + "keyids": [ |
| 474 | + "c8022fa1e9b9cb239a6b362bbdffa9649e61ad2cb699d2e4bc4fdf7930a0e64a" |
| 475 | + ], |
| 476 | + "name": "role1", |
| 477 | + "paths": [ |
| 478 | + "file3.txt" |
| 479 | + ], |
| 480 | + "terminating": False, |
| 481 | + "threshold": 1 |
| 482 | + } |
| 483 | + ] |
| 484 | + keys = { |
| 485 | + "59a4df8af818e9ed7abe0764c0b47b4240952aa0d179b5b78346c470ac30278d":{ |
| 486 | + "keytype": "ed25519", |
| 487 | + "keyval": { |
| 488 | + "public": "edcd0a32a07dce33f7c7873aaffbff36d20ea30787574ead335eefd337e4dacd" |
| 489 | + }, |
| 490 | + "scheme": "ed25519" |
| 491 | + }, |
| 492 | + } |
| 493 | + delegations_dict = {"keys": keys, "roles": roles} |
| 494 | + delegations = Delegations.from_dict(copy.deepcopy(delegations_dict)) |
| 495 | + self.assertEqual(delegations_dict, delegations.to_dict()) |
| 496 | + |
425 | 497 |
|
426 | 498 | def test_metadata_targets(self): |
427 | 499 | targets_path = os.path.join( |
|
0 commit comments