Fixes wrong schema when adding an expiration that contains microseconds

In the case we want a different expiration date on any role, we are
adviced to do this:

  repo.role.expiration = datetime.datetime(some value).

In the case we want to use a date somewhere in the future, a normal
approach would be to use time deltas:

  repo.role.expiration = datetime.today() + timedelta(weeks=x)

If we use this method we won't be able to set the value since we are
most probably producing a datetime object that contains *microseconds*.
According to the python specification, the timestamp produced will
contain the microseconds value unless it is 0.

The simple fix for this issue is to force the microseconds value to be 0
before working with the datetime object.
This commit is contained in:
Santiago Torres 2014-05-02 19:15:57 -04:00
parent c16b1fdd80
commit 46fbfb3bc2

View file

@ -1141,6 +1141,10 @@ def expiration(self, datetime_object):
message = repr(datetime_object) + ' is not a datetime.datetime() object.'
raise tuf.FormatError(message)
# truncate the microseconds value to produce a correct schema string
# of the form yyyy-mm-ddThh:mm:ssZ
datetime_object = datetime_object.replace(microsecond = 0)
# Ensure the expiration has not already passed.
current_datetime_object = \
tuf.formats.unix_timestamp_to_datetime(int(time.time()))