Skip to content

ngclient should cope better with broken repos #2195

@jku

Description

@jku
  • a delegation exists in a repository
  • but the delegated roles metadata is not in the repository and not included in the snapshot
  • Updater.get_targetinfo() is called with a path that is delegated to this nonexistent role

this currently leads to following error. We should fail with a RepositoryError of some kind instead.

Traceback (most recent call last):
  File "/home/jkukkonen/src/python-tuf/tuf/ngclient/updater.py", line 381, in _load_targets
    data = self._load_local_metadata(role)
  File "/home/jkukkonen/src/python-tuf/tuf/ngclient/updater.py", line 277, in _load_local_metadata
    with open(os.path.join(self._dir, f"{encoded_name}.json"), "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: '/home/jkukkonen/.local/share/tuf-upload-example/d412c05c/secrole.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  [... unrelated application stack race removed ...]
    updater.get_targetinfo(targetname)
  File "/home/jkukkonen/src/python-tuf/tuf/ngclient/updater.py", line 171, in get_targetinfo
    return self._preorder_depth_first_walk(target_path)
  File "/home/jkukkonen/src/python-tuf/tuf/ngclient/updater.py", line 436, in _preorder_depth_first_walk
    targets = self._load_targets(role_name, parent_role).signed
  File "/home/jkukkonen/src/python-tuf/tuf/ngclient/updater.py", line 392, in _load_targets
    metainfo = self._trusted_set.snapshot.signed.meta[f"{role}.json"]
KeyError: 'secrole.json'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions