Skip to content

Commit 737c249

Browse files
committed
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 <[email protected]>
1 parent f935ea3 commit 737c249

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tests/test_api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,13 @@ def test_metadata_targets(self):
585585
targets.signed.targets[filename].to_dict(), fileinfo.to_dict()
586586
)
587587

588+
# Test from_dict/to_dict Targets with empty targets.
589+
targets_dict = copy.deepcopy(targets.to_dict())
590+
targets_dict["signed"]["targets"] = {}
591+
tmp_dict = copy.deepcopy(targets_dict["signed"])
592+
targets_obj = Targets.from_dict(tmp_dict)
593+
self.assertEqual(targets_dict["signed"], targets_obj.to_dict())
594+
588595
# Test from_dict/to_dict Targets without delegations
589596
targets_dict = targets.to_dict()
590597
del targets_dict["signed"]["delegations"]

0 commit comments

Comments
 (0)