Skip to content

Commit

Permalink
tests: Add test for Targets.get_delegated_role()
Browse files Browse the repository at this point in the history
This test currently fails for SuccinctRoles.

Signed-off-by: Jussi Kukkonen <[email protected]>
  • Loading branch information
jku committed Feb 15, 2024
1 parent f04dc71 commit 929174c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,33 @@ def test_get_roles_in_succinct_roles(self) -> None:
expected_bin_suffix = f"{bin_numer:0{expected_suffix_length}x}"
self.assertEqual(role_name, f"bin-{expected_bin_suffix}")

def test_delegations_get_delegated_role(self) -> None:
delegations = Delegations({}, {})
targets = Targets(delegations=delegations)

with self.assertRaises(ValueError):
targets.get_delegated_role("abc")

# test "normal" delegated role (path or path_hash_prefix)
role = DelegatedRole("delegated", [], 1, False, [])
delegations.roles = {"delegated": role}
with self.assertRaises(ValueError):
targets.get_delegated_role("not-delegated")
self.assertEqual(targets.get_delegated_role("delegated"), role)
delegations.roles = None

# test succinct delegation
bit_len = 3
role2 = SuccinctRoles([], 1, bit_len, "prefix")
delegations.succinct_roles = role2
for name in ["prefix-", "prefix--1", f"prefix-{2**bit_len:0x}"]:
with self.assertRaises(ValueError, msg=f"role name '{name}'"):
targets.get_delegated_role(name)
for i in range(0, 2**bit_len):
self.assertEqual(
targets.get_delegated_role(f"prefix-{i:0x}"), role2
)


# Run unit test.
if __name__ == "__main__":
Expand Down

0 comments on commit 929174c

Please sign in to comment.