-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new API: test containers for zero or more elements #1511
Conversation
458fe73
to
41c661e
Compare
is this really true? 😮 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some potential test cases
- timestamp meta with multiple items
- timestamp meta with no items
- snapshot meta with multiple items
- delegation with multiple roles
- targets targets with multiple items
- targets roles with multiple items
or do I misunderstand the scope of the PR?
426d1ae
to
033e069
Compare
033e069
to
a894495
Compare
for which by the way we are not testing. I included a test. But still, where do you think we should test for that?
I am wrong about those two:
Do you think I should modify my commit message with more info as I did here? |
I think you may be mixing "is this a syntactically valid metadata" with "can this metadata file be used successfully in every part of the update process". I mean when you say things like:
from the perspective of the file format and the containing metadata, keyids and threshold are not related. The spec does not say metadata files can't exist with a role that has less keys than the corresponding threshold. Yes, we happen to know that those keys then can't possibly verify that roles metadata when needed but the metadata that contains this role is still valid. |
For Root roles specifically there is a spec mention (with a weird reference to "key list" but the intent seems clear: roles dictionary must contain these 4 or 5 items):
This we should test for in Root construction time I guess. |
tuf/api/metadata.py
Outdated
@@ -878,20 +878,24 @@ def __init__( | |||
version: int, | |||
spec_version: str, | |||
expires: datetime, | |||
meta: Dict[str, MetaFile], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I noticed we don't do validation on Timestamp.meta
.
According to the spec, the value of Timestamp.meta
called "METAFILES" is:
METAFILES is the same as described for the snapshot.json file.
In the case of the timestamp.json file, this MUST only include a
description of the snapshot.json file.
That's why in order to include validation for meta no matter if we create objects with Timestamp.from_dict()
or with the constructor like Timestamp()
I moved the meta validation and object creation inside __init__
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree with this change.
- it's not in line with all other constructors that do take actual objects and not json-like dicts
- It's going to make the API for creating a new Timestamp from scratch worse (caller feeds in json-like dicts instead of well defined objects).
- It makes annotations useless: we should get rid of all
Any
that we can, not add more
I'm fine with you not doing this validation at all right now: we could just wait for the snapshot_meta discussion to reach a conclusion first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now with the new discussion about snapshot_meta
I agree that we shouldn't hurry and add validation.
Will remove the commit.
66ea522
to
294f0eb
Compare
I had to rebase on top of develop.
After a discussion with @jku about his words
I realized he is right and standalone objects in those cases can exist and are valid, but cannot be verified.
There is a separate issue for that #1516. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (apart from the Timestamp constructor api change which I disagree with), thanks.
some of the targets test data are getting quite big ... but personally I still prefer parsing this sort of multiple lines of json in my head: at least every case is understandable without external context -- opinions may vary though
tuf/api/metadata.py
Outdated
@@ -878,20 +878,24 @@ def __init__( | |||
version: int, | |||
spec_version: str, | |||
expires: datetime, | |||
meta: Dict[str, MetaFile], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree with this change.
- it's not in line with all other constructors that do take actual objects and not json-like dicts
- It's going to make the API for creating a new Timestamp from scratch worse (caller feeds in json-like dicts instead of well defined objects).
- It makes annotations useless: we should get rid of all
Any
that we can, not add more
I'm fine with you not doing this validation at all right now: we could just wait for the snapshot_meta discussion to reach a conclusion first
294f0eb
to
ae3a671
Compare
Test metadata (de)serialization with input data containing containers with zero or more elements. Here is the status for the different use cases: Root keys: - many keys: added Root roles: - many roles: added Root role keyids: - many keids: already added in theupdateframework#1481 MetaFile hashes: - many hashes: already tested - zero hashes: added. Testing as invalid test case. Timestamp meta: - zero elements: already tested - many elements: added Snapshot meta: - zero items: added - many items: added Delegation keys: - many keys: added Delegation role keyids: - many keyids: added Delegation role paths: - many paths: already tested Delegation role path_hash_prefixes: - many path_hash_path_prefixes: already tested Delegation roles: - zero roles: added - multiple roles: added Targets targets: - zero items: already tested - multiple items: added Signed-off-by: Martin Vrachev <[email protected]>
Those tests are needed to cover use cases when syntatcticly as standalone objects the metadata classes and their helper classes defined in tuf/api/metadata.py are valid even if they cannot be verified. An example where an object is valid, but cannot be verified is if we have a Role instance with an empty list of "keyids". This instance is valid and can be created, but cannot be verified because there is a requirement that the threshold should be above 1, meaning that there should be at least 1 element inside the "keyids" list to complete successful threshold verification. The situation is the same for the rest of the tests I am adding to this commit: - Root object without keys - Root object without roles - DelegationRole object with empty "keyids" - DelegationRole object with an empty list of "paths" - DelegationRole object with an empty list of "path_hash_prefixes" all of these objects can be instantiated, but cannot complete successfully threshold verification. Signed-off-by: Martin Vrachev <[email protected]>
ae3a671
to
4c3fd95
Compare
@jku updated the pr by dropping the timestamp meta validation commit and removing multiple metafiles in timestamp test. |
Move the Delegation class serialization tests from "test_api.py" to test_metadata_serialization.py module focused on serialization testing. Additionally, a test for empty keys and roles will be added in my upcomming pr theupdateframework#1511. Signed-off-by: Martin Vrachev <[email protected]>
Move the Delegation class serialization tests from "test_api.py" to test_metadata_serialization.py module focused on serialization testing. Additionally, a test for empty keys and roles will be added in my upcomming pr theupdateframework#1511. Signed-off-by: Martin Vrachev <[email protected]>
Move the Delegation class serialization tests from "test_api.py" to test_metadata_serialization.py module focused on serialization testing. Additionally, a test for empty keys and roles will be added in my upcomming pr theupdateframework#1511. Signed-off-by: Martin Vrachev <[email protected]>
Move the Delegation class serialization tests from "test_api.py" to test_metadata_serialization.py module focused on serialization testing. Additionally, a test for empty keys and roles will be added in my upcomming pr theupdateframework#1511. Signed-off-by: Martin Vrachev <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Move the Delegation class serialization tests from "test_api.py" to test_metadata_serialization.py module focused on serialization testing. Additionally, a test for empty keys and roles will be added in my upcomming pr theupdateframework#1511. Signed-off-by: Martin Vrachev <[email protected]>
Move the Delegation class serialization tests from "test_api.py" to test_metadata_serialization.py module focused on serialization testing. Additionally, a test for empty keys and roles will be added in my upcomming pr theupdateframework#1511. Signed-off-by: Martin Vrachev <[email protected]>
Move the Delegation class serialization tests from "test_api.py" to test_metadata_serialization.py module focused on serialization testing. Additionally, a test for empty keys and roles will be added in my upcomming pr theupdateframework#1511. Signed-off-by: Martin Vrachev <[email protected]>
Move the Delegation class serialization tests from "test_api.py" to test_metadata_serialization.py module focused on serialization testing. Additionally, a test for empty keys and roles will be added in my upcomming pr theupdateframework#1511. Signed-off-by: Martin Vrachev <[email protected]>
Move the Delegation class serialization tests from "test_api.py" to test_metadata_serialization.py module focused on serialization testing. Additionally, a test for empty keys and roles will be added in my upcomming pr theupdateframework#1511. Signed-off-by: Martin Vrachev <[email protected]>
Move the Delegation class serialization tests from "test_api.py" to test_metadata_serialization.py module focused on serialization testing. Additionally, a test for empty keys and roles will be added in my upcomming pr theupdateframework#1511. Signed-off-by: Martin Vrachev <[email protected]>
Move the Delegation class serialization tests from "test_api.py" to test_metadata_serialization.py module focused on serialization testing. Additionally, a test for empty keys and roles will be added in my upcomming pr theupdateframework#1511. Signed-off-by: Martin Vrachev <[email protected]>
Move the Delegation class serialization tests from "test_api.py" to test_metadata_serialization.py module focused on serialization testing. Additionally, a test for empty keys and roles will be added in my upcomming pr theupdateframework#1511. Signed-off-by: Martin Vrachev <[email protected]>
Move the Delegation class serialization tests from "test_api.py" to test_metadata_serialization.py module focused on serialization testing. Additionally, a test for empty keys and roles will be added in my upcomming pr theupdateframework#1511. Signed-off-by: Martin Vrachev <[email protected]>
Move the Delegation class serialization tests from "test_api.py" to test_metadata_serialization.py module focused on serialization testing. Additionally, a test for empty keys and roles will be added in my upcomming pr theupdateframework#1511. Signed-off-by: Martin Vrachev <[email protected]>
Fixes #1485
Description of the changes being introduced by the pull request:
Test metadata (de)serialization with input data containing containers with zero or more elements.
Here is the status for the different use cases:
Root:
Root role keyids:
MetaFile hashes:
Timestamp meta:
Snapshot meta:
Delegation:
Delegation role:
Delegation roles:
Targets targets:
Additional tests are added for containers with 0 or more elements for some specific cases.
Those tests are needed to cover use cases when syntactically as
standalone objects the metadata classes and their helper classes defined
in tuf/api/metadata.py are valid even if they cannot be verified.
An example where an object is valid, but cannot be verified is
if we have a Role instance with an empty list of "keyids".
This instance is valid and can be created, but cannot be verified
because there is a requirement that the threshold should be above
1, meaning that there should be at least 1 element inside the "keyids"
list to complete successful threshold verification.
The situation is the same for the rest of the tests I am adding to this
commit:
all of these objects can be instantiated, but cannot complete successfully
threshold verification.
Signed-off-by: Martin Vrachev [email protected]
Please verify and check that the pull request fulfills the following
requirements: