Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/test_metadata_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ def test_delegated_role_serialization(self, test_case_data: str) -> None:
"terminating": false, "threshold": 1}',
"invalid path_hash_prefixes type": '{"keyids": ["keyid"], "name": "a", "path_hash_prefixes": [1,2,3], \
"terminating": false, "threshold": 1}',
"paths is a string": '{"keyids": ["keyid"], "name": "a", "paths": "fn1", \
"terminating": false, "threshold": 1}',
"path_hash_prefixes is a string": '{"keyids": ["keyid"], "name": "a", "path_hash_prefixes": "h1", \
"terminating": false, "threshold": 1}',
}

@utils.run_sub_tests_with_dataset(invalid_delegated_roles)
Expand Down
16 changes: 11 additions & 5 deletions tuf/api/_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,12 +1099,18 @@ def __init__( # noqa: PLR0917
"Only one of (paths, path_hash_prefixes) must be set"
)

if paths is not None and any(not isinstance(p, str) for p in paths):
raise ValueError("Paths must be strings")
if path_hash_prefixes is not None and any(
not isinstance(p, str) for p in path_hash_prefixes
# A str is iterable too, so it needs to be rejected explicitly: its
# characters would otherwise be used as separate patterns/prefixes
if paths is not None and (
not isinstance(paths, list)
or any(not isinstance(p, str) for p in paths)
):
raise ValueError("Path_hash_prefixes must be strings")
raise ValueError("Paths must be a list of strings")
if path_hash_prefixes is not None and (
not isinstance(path_hash_prefixes, list)
or any(not isinstance(p, str) for p in path_hash_prefixes)
):
raise ValueError("Path_hash_prefixes must be a list of strings")

self.paths = paths
self.path_hash_prefixes = path_hash_prefixes
Expand Down
Loading