Skip to content

Commit

Permalink
Metadata API: METAPATHs != top level roles
Browse files Browse the repository at this point in the history
Add a sanity check that METAPATs are not allowed to be one of the top
level metadata roles.

For more context read:
https://theupdateframework.github.io/specification/latest/#snapshot-metapath

Signed-off-by: Martin Vrachev <[email protected]>
  • Loading branch information
MVrachev committed Nov 9, 2021
1 parent 07b40d5 commit 8b21020
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/test_metadata_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ def test_timestamp_serialization(self, test_case_data: str):
"no metafile": '{ "_type": "snapshot", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z"}',
"meta path empty string": '{ "_type": "snapshot", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
"meta": { "": {"hashes": {"sha256" : "abc"}, "version": 1} }}',
"meta path as top level role": '{ "_type": "snapshot", "spec_version": "1.0.0", "version": 1, "expires": "2030-01-01T00:00:00Z", \
"meta": { "root": {"hashes": {"sha256" : "abc"}, "version": 1} }}',
}

@utils.run_sub_tests_with_dataset(invalid_snapshots)
Expand Down
2 changes: 2 additions & 0 deletions tuf/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,8 @@ def __init__(
super().__init__(version, spec_version, expires, unrecognized_fields)
if any(meta_path == "" for meta_path in meta):
raise ValueError("All meta paths must be non-empty strings")
if any(meta_path in TOP_LEVEL_ROLE_NAMES for meta_path in meta):
raise ValueError("Meta paths must not be top-level metadata roles")
self.meta = meta

@classmethod
Expand Down

0 comments on commit 8b21020

Please sign in to comment.