diff --git a/tests/test_metadata_serialization.py b/tests/test_metadata_serialization.py index 813f82823a..9f228d4c8f 100644 --- a/tests/test_metadata_serialization.py +++ b/tests/test_metadata_serialization.py @@ -141,6 +141,7 @@ def test_invalid_role_serialization(self, test_case_data: Dict[str, str]): valid_roles: DataSet = { "all": '{"keyids": ["keyid"], "threshold": 3}', + "many keyids": '{"keyids": ["a", "b", "c", "d", "e"], "threshold": 1}', "unrecognized field": '{"keyids": ["keyid"], "threshold": 3, "foo": "bar"}', } diff --git a/tuf/api/metadata.py b/tuf/api/metadata.py index e3936697af..a4dcec0974 100644 --- a/tuf/api/metadata.py +++ b/tuf/api/metadata.py @@ -554,7 +554,7 @@ def from_dict(cls, role_dict: Dict[str, Any]) -> "Role": def to_dict(self) -> Dict[str, Any]: """Returns the dictionary representation of self.""" return { - "keyids": list(self.keyids), + "keyids": sorted(self.keyids), "threshold": self.threshold, **self.unrecognized_fields, }