api/metadata input validation: length and hashes#1451
api/metadata input validation: length and hashes#1451jku merged 3 commits intotheupdateframework:developfrom
Conversation
| unrecognized_fields: Optional[Mapping[str, Any]] = None, | ||
| ) -> None: | ||
|
|
||
| if version <= 0: |
There was a problem hiding this comment.
Nit: these days I had a thought that it's probably easier to read if we use if version < 1 when doing this check.
What do you think?
There was a problem hiding this comment.
I find <= 0 very readable
|
Even though we don't want to focus on validating the semantic behind |
I've started to agree with type checks in this situation:
The last point feels quite wrong so maybe we should check that they are str at object intialization |
b5be7e8 to
033f10a
Compare
|
Rebased on develop and added type checks for the dictionary key-values based on your suggestions. |
jku
left a comment
There was a problem hiding this comment.
looks fine to me. Left a comment about a check that isn't strictly necessary anymore but if you want to keep it, that's fine too.
tuf/api/metadata.py
Outdated
| if not isinstance(hashes, dict): | ||
| raise TypeError(f"Hashes must be a dictionary, got {type(hashes)}") |
There was a problem hiding this comment.
This check could now be dropped -- the error we get from calling hashes.items() on something that isn't a dict is not as good but it does raise an exception without extra code...
There was a problem hiding this comment.
I dropped it and force pushed, we raise build-in errors anyway.
- valid length: greater than zero - valid hashes: a non-empty dictionary of type Dict[str, str] Checking the validity of hash algorithms is not part of the metadata input validation and is done by securesystemslib during hash verification. Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
The check for an empty hash dictionary is now part of the hash validation function. Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
A trailing comma makes any element a one-item tuple. Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
033f10a to
328f637
Compare
Fixes #1441
Description of the changes being introduced by the pull request:
Draft since it is dependent on #1437
Adds input validation checks to
MetaFileandTargetFilecommon fields:Checking the validity of hash algorithms is not part of the metadata input validation and is done
by
securesystemslibduring hash verification.Please verify and check that the pull request fulfills the following
requirements: