Skip to content

Commit 1f3654f

Browse files
authored
Merge pull request #1712 from ivanayov/no_microseconds_in_api_for_signed_expires
Remove microseconds from metadata API Signed.expires
2 parents 2e5ddd3 + c5ace07 commit 1f3654f

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
@@ -407,6 +407,14 @@ class Signed(metaclass=abc.ABCMeta):
407407
def _type(self) -> str:
408408
return self.type
409409

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

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

0 commit comments

Comments
 (0)