Repository navigation
Metadata API: Do not store a rejected expires value - #3055
Open
BahaaMattar wants to merge 1 commit into
Open
BahaaMattar wants to merge 1 commit into
BahaaMattar wants to merge 1 commit into
Conversation
The Signed.expires setter assigned the new value to self._expires before checking its timezone. When the value was rejected with ValueError (a timezone-aware datetime that is not UTC), the object kept the rejected value: reading expires returned the non-UTC datetime, and to_dict() then serialized its local time with a "Z" suffix, so the stored expiry was off by the UTC offset. Validate first and only assign once the value is known to be valid. Add a test that a rejected value leaves expires, and the serialized expiry, unchanged. Fixes theupdateframework#3054 Signed-off-by: Bahaa Mattar <bahaa.kmattar@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of the changes being introduced by the pull request:
The
Signed.expiressetter normalizes the datetime (drops microseconds, treats a naive value as UTC) and rejects a timezone-aware value that is not UTC withValueError. It stored the value inself._expiresfirst and checked the timezone afterwards, so a rejected value stayed on the object: after theValueError,expiresreturned the non-UTC datetime, andto_dict()/to_bytes()wrote its local time followed byZ(a12:00+02:00value is written as12:00:00Z, two hours later than the real instant).This builds the normalized value in a local variable, validates it, and assigns
self._expiresonly at the end, so a rejected assignment leaves the object unchanged. Accepted values behave exactly as before, including inSigned.__init__, which uses the same setter.The new test
test_signed_expires_setter_invalid_timezonesets a+02:00datetime on aTimestamp, expectsValueError, and checks thatexpiresand the serializedexpiresare unchanged. Without the change it fails on theexpiresassertion.Fixes #3054