-
Notifications
You must be signed in to change notification settings - Fork 276
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
Remove microseconds from metadata API Signed.expires #1712
Remove microseconds from metadata API Signed.expires #1712
Conversation
Pull Request Test Coverage Report for Build 1563947545Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
We'll want think this through for all the different cases: deserialization, users calling the api , serialization... it's a little detail but could make life difficult in the future
|
It think that spec-compliant should mean spec-compliant with no exception, so if metadata is not in the correct form, we should throw an error.
I think it's fine, when it comes to preventing a bug, coming not from the metadata, but from the implementation (and in this case - python specific) as we guarantee that it won't break the deserialisation. But we should guarantee that the metadata is correct at the same time. |
I agree with @jku that we need to be careful here. This is what I think about the different cases:
|
I think I lean in the same direction (EDIT: I wrote this before seeing lukas' last message :) )
so possibly
I'm not 100% sure of this yet, but that's my thinking... |
I agree with the overall direction...
This makes sense, and we might need to revise existing data validation in
I guess we can do that, but we need to to be careful that there's no unexpected behavior, above all upon serialization, if the expires field is modified outside of the constructor |
Yes, and should consider buggy code as well (obviously we'd never write bugs but just theoretically speaking): we should ensure we rather fail than persist metadata that is invalid. #1696 has some discussion on this |
00ac638
to
ba59ae3
Compare
In the latest update I stick to:
|
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.
To test your code (lazily), I used the tests/metadata_api_tests/test_metadata_serialization.py
and I added an invalid expire date entry to this data set
invalid_roots: utils.DataSet = { |
"invalid expire date": '{"_type": "root", "spec_version": "1.0.0", "version": 1, \
"expires": "2021-11-16T12:00:00.123456Z", "consistent_snapshot": false, \
"keys": { \
"keyid1" : {"keytype": "rsa", "scheme": "rsassa-pss-sha256", "keyval": {"public": "foo"}}, \
"keyid2" : {"keytype": "ed25519", "scheme": "ed25519", "keyval": {"public": "bar"}}}, \
"roles": { \
"root": {"keyids": ["keyid1"], "threshold": 1}, \
"timestamp": {"keyids": ["keyid2"], "threshold": 1}, \
"targets": {"keyids": ["keyid1"], "threshold": 1}, \
"snapshot": {"keyids": ["keyid2"], "threshold": 1}} \
}',
It gave me the expected raise:
File "/Users/kdearaujo/devel/TUF/python-tuf/tuf/api/metadata.py", line 476, in _common_fields_from_dict
raise exceptions.InvalidConfigurationError(
tuf.exceptions.InvalidConfigurationError:
Role root should have "expires" metadata of the format
"yyyy-mm-ddThh:mm:ssZ" but got 2021-11-16T12:00:00.123456Z instead
But I am not sure if the right to a place to add the test or even we want to test it there. I noticed that we don't test these custom exceptions in tests_metadata_serialization.py
Maybe some maintainer could comment :)
Thanks for working on this @ivanayov. I think it's a fair approach for the first two use cases discussed above. We still need to figure out what to do for the 3rd use case, that is do we allow serialisation of invalid metadata. But maybe we don't have to do this here. Would you mind adding a test for what you have so far? |
ba59ae3
to
6210b54
Compare
@lukpueh @kairoaraujo Just pushed an update with latest comments. |
6210b54
to
c3887a2
Compare
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 left some comments, I think the core of this PR is the new API (set_expiry()
) which allows both construction of new metadata and modifications to existing expiry to be done safely: I think this is the correct direction but new API needs to to be polished (include API documentation and so on).
The big question is, do we need to solve the related #1727 at the same time (at least on paper)?
Martin opened #1696 about this relevant question in general: maybe we can continue there (the issue is big enough to maybe have a chat as well, to discuss some possible ways to deal with it) |
oh a new idea: since one of the problems here is that our expiry is a datetime but most datetimes are not valid expiries (because microseconds), how about we hide the variable and make |
c3887a2
to
e3f2ce1
Compare
This change removes microseconds from expiry in order to fit TUF specification Fixes theupdateframework#1678 Signed-off-by: Ivana Atanasova <iyovcheva@vmware.com>
e3f2ce1
to
c5ace07
Compare
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.
This feels like the correct solution, thank you.
- API user just provides a datetime, we make sure it's valid (removing microseconds)
- the Metadata object always matches the serialized output (since the microseconds are never stored in the object)
- type "enforcement" is about as good as it gets with python (static checks will catch wrong types and we use the datetime API in the setter so even without static checks things will break on type mismatches)
Looks good to me, leaving open for @lukpueh to see as well
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.
Seconding Jussi's assessment. Thanks for the clean fix, @ivanayov!
Remove `bump_expiration()` method, which is unlikely to be used as is, i.e. bump to "current expiration date plus delta". A more realistic use case is to bump to "now plus delta" (see theupdateframework#1727 for details). Moreover, bump_expiration can either way easily be replaced by a one-liner expression using the 'datetime' module. A corresponding code snippet is added to the `expires` property's docstring. Note: `expires` became a property with a millisec-removing setter (for spec conformance) in theupdateframework#1712, which further reduces the need for a convenience bump_expiration method. This patch also removes a related unit test and updates another one. Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
This change removes microseconds from expiry in order to fit TUF
specification
Fixes #1678