From 737c249067a563e5df4e7db311fb4cc0e9d4333b Mon Sep 17 00:00:00 2001 From: Martin Vrachev Date: Fri, 21 May 2021 20:05:48 +0300 Subject: [PATCH] new API: make sure targets in Targets can be empty This change is relevant to the new metadata class Targets. In the specification, when describing the Targets metadata file format and more precisely "TARGETPATH" (or targets containing the actual target files) it's said: "It is allowed to have a TARGETS object with no TARGETPATH elements. This can be used to indicate that no target files are available." If there is no "TARGETPATH" keys for the dictionary "targets", this would mean that "Targets.targets" is {}. Make sure we test for that. See: https://theupdateframework.github.io/specification/latest/#targetpath Signed-off-by: Martin Vrachev --- tests/test_api.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_api.py b/tests/test_api.py index 2a2ebc99..6f7d6155 100755 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -585,6 +585,13 @@ def test_metadata_targets(self): targets.signed.targets[filename].to_dict(), fileinfo.to_dict() ) + # Test from_dict/to_dict Targets with empty targets. + targets_dict = copy.deepcopy(targets.to_dict()) + targets_dict["signed"]["targets"] = {} + tmp_dict = copy.deepcopy(targets_dict["signed"]) + targets_obj = Targets.from_dict(tmp_dict) + self.assertEqual(targets_dict["signed"], targets_obj.to_dict()) + # Test from_dict/to_dict Targets without delegations targets_dict = targets.to_dict() del targets_dict["signed"]["delegations"]