Skip to content

Commit c5ace07

Browse files
committed
Remove miscroseconds from metadata API Signed.expires
This change removes microseconds from expiry in order to fit TUF specification Fixes #1678 Signed-off-by: Ivana Atanasova <[email protected]>
1 parent bdf1cbb commit c5ace07

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

tests/test_metadata_serialization.py

+3
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ def test_root_serialization(self, test_case_data: str) -> None:
200200
"snapshot": {"keyids": ["keyid2"], "threshold": 1}, \
201201
"foo": {"keyids": ["keyid2"], "threshold": 1}} \
202202
}',
203+
"invalid expiry with microsecond s": '{"_type": "root", "spec_version": "1.0.0", "version": 1, \
204+
"expires": "2030-01-01T12:00:00.123456Z", "consistent_snapshot": false, \
205+
"keys": {}, "roles": {"root": {}, "timestamp": {}, "targets": {}, "snapshot": {}}}',
203206
}
204207

205208
@utils.run_sub_tests_with_dataset(invalid_roots)

tuf/api/metadata.py

+9
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@ class Signed(metaclass=abc.ABCMeta):
408408
def _type(self) -> str:
409409
return self.type
410410

411+
@property
412+
def expires(self) -> datetime:
413+
return self._expires
414+
415+
@expires.setter
416+
def expires(self, value: datetime) -> None:
417+
self._expires = value.replace(microsecond=0)
418+
411419
# NOTE: Signed is a stupid name, because this might not be signed yet, but
412420
# we keep it to match spec terminology (I often refer to this as "payload",
413421
# or "inner metadata")
@@ -469,6 +477,7 @@ def _common_fields_from_dict(
469477
# what the constructor expects and what we store. The inverse operation
470478
# is implemented in '_common_fields_to_dict'.
471479
expires = datetime.strptime(expires_str, "%Y-%m-%dT%H:%M:%SZ")
480+
472481
return version, spec_version, expires
473482

474483
def _common_fields_to_dict(self) -> Dict[str, Any]:

0 commit comments

Comments
 (0)