diff --git a/repository_service_tuf_api/metadata.py b/repository_service_tuf_api/metadata.py index affa2593..26ffef06 100644 --- a/repository_service_tuf_api/metadata.py +++ b/repository_service_tuf_api/metadata.py @@ -309,7 +309,10 @@ def get_metadata_sign() -> MetadataSignGetResponse: if trusted_root and "root" in md_response: md_response["trusted_root"] = trusted_root.to_dict() - if trusted_targets and "targets" in md_response: + if any( + role["signed"]["_type"] == "targets" + for role in md_response.values() + ): md_response["trusted_targets"] = trusted_targets.to_dict() data = {"metadata": md_response} diff --git a/tests/unit/api/test_metadata.py b/tests/unit/api/test_metadata.py index bcb485e3..53d38e48 100644 --- a/tests/unit/api/test_metadata.py +++ b/tests/unit/api/test_metadata.py @@ -598,10 +598,10 @@ def test_get_metadata_sign_with_trusted_targets( } # Change trusted root: - trusted_targets_dict = copy.deepcopy(data["metadata"]["root"]) - trusted_targets_dict["signed"]["version"] = 10 + pending_targets_dict = copy.deepcopy(trusted_targets_dict) + pending_targets_dict["signed"]["version"] = 10 fake_targets_pending_metadata = pretend.stub( - to_dict=pretend.call_recorder(lambda: trusted_targets_dict) + to_dict=pretend.call_recorder(lambda: pending_targets_dict) ) fake_targets_trusted_metadata = pretend.stub( to_dict=pretend.call_recorder(lambda: trusted_targets_dict) @@ -628,7 +628,7 @@ def get_role(setting: str): assert response.json() == { "data": { "metadata": { - "targets": trusted_targets_dict, + "targets": pending_targets_dict, "trusted_targets": trusted_targets_dict, } },