Skip to content

Commit 929174c

Browse files
committed
tests: Add test for Targets.get_delegated_role()
This test currently fails for SuccinctRoles. Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent f04dc71 commit 929174c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/test_api.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,33 @@ def test_get_roles_in_succinct_roles(self) -> None:
10081008
expected_bin_suffix = f"{bin_numer:0{expected_suffix_length}x}"
10091009
self.assertEqual(role_name, f"bin-{expected_bin_suffix}")
10101010

1011+
def test_delegations_get_delegated_role(self) -> None:
1012+
delegations = Delegations({}, {})
1013+
targets = Targets(delegations=delegations)
1014+
1015+
with self.assertRaises(ValueError):
1016+
targets.get_delegated_role("abc")
1017+
1018+
# test "normal" delegated role (path or path_hash_prefix)
1019+
role = DelegatedRole("delegated", [], 1, False, [])
1020+
delegations.roles = {"delegated": role}
1021+
with self.assertRaises(ValueError):
1022+
targets.get_delegated_role("not-delegated")
1023+
self.assertEqual(targets.get_delegated_role("delegated"), role)
1024+
delegations.roles = None
1025+
1026+
# test succinct delegation
1027+
bit_len = 3
1028+
role2 = SuccinctRoles([], 1, bit_len, "prefix")
1029+
delegations.succinct_roles = role2
1030+
for name in ["prefix-", "prefix--1", f"prefix-{2**bit_len:0x}"]:
1031+
with self.assertRaises(ValueError, msg=f"role name '{name}'"):
1032+
targets.get_delegated_role(name)
1033+
for i in range(0, 2**bit_len):
1034+
self.assertEqual(
1035+
targets.get_delegated_role(f"prefix-{i:0x}"), role2
1036+
)
1037+
10111038

10121039
# Run unit test.
10131040
if __name__ == "__main__":

0 commit comments

Comments
 (0)