From 44a6542cb68054f6d6b3cb9cb196e697cb198ac9 Mon Sep 17 00:00:00 2001 From: Kairo Araujo Date: Tue, 17 Sep 2024 00:14:29 +0200 Subject: [PATCH] fix: get signing (#695) * fix: get signing fix the conditional about showing the metadata trusted_* Signed-off-by: Kairo Araujo * Fix unit tests Signed-off-by: Martin Vrachev --------- Signed-off-by: Kairo Araujo Signed-off-by: Martin Vrachev Co-authored-by: Martin Vrachev --- repository_service_tuf_api/metadata.py | 5 ++++- tests/unit/api/test_metadata.py | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) 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, } },