Skip to content

Commit 2f56b8e

Browse files
committed
Add Delegation/DelegationRole specific tests
Signed-off-by: Martin Vrachev <[email protected]>
1 parent 78e5323 commit 2f56b8e

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

tests/test_api.py

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
Timestamp,
2828
Targets,
2929
Key,
30-
Role
30+
Role,
31+
Delegations,
32+
DelegationRole,
3133
)
3234

3335
from tuf.api.serialization import (
@@ -302,7 +304,7 @@ def test_key_class(self):
302304
"public": "edcd0a32a07dce33f7c7873aaffbff36d20ea30787574ead335eefd337e4dacd"
303305
},
304306
"scheme": "ed25519"
305-
},
307+
},
306308
}
307309
for key_dict in keys.values():
308310
# Testing that the workflow of deserializing and serializing
@@ -394,6 +396,66 @@ def test_metadata_root(self):
394396
self.assertNotIn(keyid, root.signed.keys)
395397

396398

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+
397459

398460
def test_metadata_targets(self):
399461
targets_path = os.path.join(

0 commit comments

Comments
 (0)