|
27 | 27 | Timestamp,
|
28 | 28 | Targets,
|
29 | 29 | Key,
|
30 |
| - Role |
| 30 | + Role, |
| 31 | + Delegations, |
| 32 | + DelegationRole, |
31 | 33 | )
|
32 | 34 |
|
33 | 35 | from tuf.api.serialization import (
|
@@ -302,7 +304,7 @@ def test_key_class(self):
|
302 | 304 | "public": "edcd0a32a07dce33f7c7873aaffbff36d20ea30787574ead335eefd337e4dacd"
|
303 | 305 | },
|
304 | 306 | "scheme": "ed25519"
|
305 |
| - }, |
| 307 | + }, |
306 | 308 | }
|
307 | 309 | for key_dict in keys.values():
|
308 | 310 | # Testing that the workflow of deserializing and serializing
|
@@ -394,6 +396,66 @@ def test_metadata_root(self):
|
394 | 396 | self.assertNotIn(keyid, root.signed.keys)
|
395 | 397 |
|
396 | 398 |
|
| 399 | + def test_delegation_role_class(self): |
| 400 | + roles = [ |
| 401 | + { |
| 402 | + "keyids": [ |
| 403 | + "c8022fa1e9b9cb239a6b362bbdffa9649e61ad2cb699d2e4bc4fdf7930a0e64a" |
| 404 | + ], |
| 405 | + "name": "role1", |
| 406 | + "paths": [ |
| 407 | + "file3.txt" |
| 408 | + ], |
| 409 | + "terminating": False, |
| 410 | + "threshold": 1 |
| 411 | + } |
| 412 | + ] |
| 413 | + for role in roles: |
| 414 | + # Testing that the workflow of deserializing and serializing |
| 415 | + # a delegation role dictionary doesn't change the content. |
| 416 | + key_obj = DelegationRole.from_dict(role.copy()) |
| 417 | + self.assertEqual(role, key_obj.to_dict()) |
| 418 | + |
| 419 | + # Test creating a DelegationRole object with both "paths" and |
| 420 | + # "path_hash_prefixes" set. |
| 421 | + role["path_hash_prefixes"] = "foo" |
| 422 | + with self.assertRaises(ValueError): |
| 423 | + DelegationRole.from_dict(role.copy()) |
| 424 | + |
| 425 | + # Test creating DelegationRole without "paths" and |
| 426 | + # "path_hash_prefixes" set |
| 427 | + del role["paths"] |
| 428 | + del role["path_hash_prefixes"] |
| 429 | + DelegationRole.from_dict(role) |
| 430 | + |
| 431 | + |
| 432 | + def test_delegation_class(self): |
| 433 | + roles = [ |
| 434 | + { |
| 435 | + "keyids": [ |
| 436 | + "c8022fa1e9b9cb239a6b362bbdffa9649e61ad2cb699d2e4bc4fdf7930a0e64a" |
| 437 | + ], |
| 438 | + "name": "role1", |
| 439 | + "paths": [ |
| 440 | + "file3.txt" |
| 441 | + ], |
| 442 | + "terminating": False, |
| 443 | + "threshold": 1 |
| 444 | + } |
| 445 | + ] |
| 446 | + keys = { |
| 447 | + "59a4df8af818e9ed7abe0764c0b47b4240952aa0d179b5b78346c470ac30278d":{ |
| 448 | + "keytype": "ed25519", |
| 449 | + "keyval": { |
| 450 | + "public": "edcd0a32a07dce33f7c7873aaffbff36d20ea30787574ead335eefd337e4dacd" |
| 451 | + }, |
| 452 | + "scheme": "ed25519" |
| 453 | + }, |
| 454 | + } |
| 455 | + delegations_dict = {"keys": keys, "roles": roles} |
| 456 | + delegations = Delegations.from_dict(copy.deepcopy(delegations_dict)) |
| 457 | + self.assertEqual(delegations_dict, delegations.to_dict()) |
| 458 | + |
397 | 459 |
|
398 | 460 | def test_metadata_targets(self):
|
399 | 461 | targets_path = os.path.join(
|
|
0 commit comments