Skip to content

Commit

Permalink
Add Delegation/DelegationRole specific tests
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
  • Loading branch information
MVrachev committed Apr 29, 2021
1 parent 78e5323 commit 2f56b8e
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
Timestamp,
Targets,
Key,
Role
Role,
Delegations,
DelegationRole,
)

from tuf.api.serialization import (
Expand Down Expand Up @@ -302,7 +304,7 @@ def test_key_class(self):
"public": "edcd0a32a07dce33f7c7873aaffbff36d20ea30787574ead335eefd337e4dacd"
},
"scheme": "ed25519"
},
},
}
for key_dict in keys.values():
# Testing that the workflow of deserializing and serializing
Expand Down Expand Up @@ -394,6 +396,66 @@ def test_metadata_root(self):
self.assertNotIn(keyid, root.signed.keys)


def test_delegation_role_class(self):
roles = [
{
"keyids": [
"c8022fa1e9b9cb239a6b362bbdffa9649e61ad2cb699d2e4bc4fdf7930a0e64a"
],
"name": "role1",
"paths": [
"file3.txt"
],
"terminating": False,
"threshold": 1
}
]
for role in roles:
# Testing that the workflow of deserializing and serializing
# a delegation role dictionary doesn't change the content.
key_obj = DelegationRole.from_dict(role.copy())
self.assertEqual(role, key_obj.to_dict())

# Test creating a DelegationRole object with both "paths" and
# "path_hash_prefixes" set.
role["path_hash_prefixes"] = "foo"
with self.assertRaises(ValueError):
DelegationRole.from_dict(role.copy())

# Test creating DelegationRole without "paths" and
# "path_hash_prefixes" set
del role["paths"]
del role["path_hash_prefixes"]
DelegationRole.from_dict(role)


def test_delegation_class(self):
roles = [
{
"keyids": [
"c8022fa1e9b9cb239a6b362bbdffa9649e61ad2cb699d2e4bc4fdf7930a0e64a"
],
"name": "role1",
"paths": [
"file3.txt"
],
"terminating": False,
"threshold": 1
}
]
keys = {
"59a4df8af818e9ed7abe0764c0b47b4240952aa0d179b5b78346c470ac30278d":{
"keytype": "ed25519",
"keyval": {
"public": "edcd0a32a07dce33f7c7873aaffbff36d20ea30787574ead335eefd337e4dacd"
},
"scheme": "ed25519"
},
}
delegations_dict = {"keys": keys, "roles": roles}
delegations = Delegations.from_dict(copy.deepcopy(delegations_dict))
self.assertEqual(delegations_dict, delegations.to_dict())


def test_metadata_targets(self):
targets_path = os.path.join(
Expand Down

0 comments on commit 2f56b8e

Please sign in to comment.