Skip to content

Commit

Permalink
fix: get signing (#695)
Browse files Browse the repository at this point in the history
* fix: get signing

fix the conditional about showing the metadata trusted_*

Signed-off-by: Kairo Araujo <[email protected]>

* Fix unit tests

Signed-off-by: Martin Vrachev <[email protected]>

---------

Signed-off-by: Kairo Araujo <[email protected]>
Signed-off-by: Martin Vrachev <[email protected]>
Co-authored-by: Martin Vrachev <[email protected]>
  • Loading branch information
kairoaraujo and MVrachev authored Sep 16, 2024
1 parent 7ed9b72 commit 44a6542
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion repository_service_tuf_api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/api/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
}
},
Expand Down

0 comments on commit 44a6542

Please sign in to comment.