Skip to content

Commit

Permalink
Metadata API: Fix role lookup for succinct delegation
Browse files Browse the repository at this point in the history
get_delegated_role() should not return a Role if the rolename is not
a delegated role. This is already true for "normal" DelegatedRole but
was not actually verified for SuccinctRoles.

Signed-off-by: Jussi Kukkonen <[email protected]>
  • Loading branch information
jku committed Feb 15, 2024
1 parent 929174c commit 77cb66b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tuf/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2044,10 +2044,13 @@ def get_delegated_role(self, delegated_role: str) -> Role:
if self.delegations is None:
raise ValueError("No delegations found")

role: Optional[Role] = None
if self.delegations.roles is not None:
role: Optional[Role] = self.delegations.roles.get(delegated_role)
else:
role = self.delegations.succinct_roles
role = self.delegations.roles.get(delegated_role)
elif self.delegations.succinct_roles is not None:
succinct = self.delegations.succinct_roles
if succinct.is_delegated_role(delegated_role):
role = succinct

if not role:
raise ValueError(f"Delegated role {delegated_role} not found")
Expand Down

0 comments on commit 77cb66b

Please sign in to comment.