Skip to content

Commit

Permalink
Fail when signature contains error
Browse files Browse the repository at this point in the history
Signed-off-by: Jindrich Luza <[email protected]>
  • Loading branch information
midnightercz committed Jan 28, 2025
1 parent 6679ba1 commit 7069089
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/pubtools/_quay/signer_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def _sign_containers(
)
if signed["signer_result"]["status"] != "ok":
raise SigningError(signed["signer_result"]["error_message"])

for sign_entry in sign_entries:
LOG.info(
"Signed %s(%s) with %s in %s",
Expand Down Expand Up @@ -314,9 +315,16 @@ def _run_store_signed(self, signed_results: Dict[str, Any]) -> None:
LOG.info("Sending new signatures to Pyxis")

signatures: List[Dict[str, Any]] = []
error = False

for reference, op_res in zip(
signed_results["operation"]["references"], signed_results["operation_results"]
):
if op_res[0]["msg"]["errors"]:
LOG.error(f"Error signing {reference}: {op_res[0]['msg']['errors']}")
error = True
continue

signatures.append(
{
"manifest_digest": op_res[0]["msg"]["manifest_digest"],
Expand All @@ -326,6 +334,8 @@ def _run_store_signed(self, signed_results: Dict[str, Any]) -> None:
"signature_data": op_res[0]["msg"]["signed_claim"],
}
)
if error:
raise SigningError("Error signing some references")

for sig in signatures:
LOG.debug(
Expand Down
26 changes: 26 additions & 0 deletions tests/test_msg_signer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

from pubtools._quay.signer_wrapper import MsgSignerWrapper, SigningError


def test_store_error_signatures(msg_signer_settings, fake_cert_key_paths, dest_manifest_list):
msg_signer = MsgSignerWrapper(config_file="fake-config-file", settings=msg_signer_settings)
with pytest.raises(SigningError):
msg_signer._store_signed(
{
"operation": {"references": ["fake-reference"]},
"operation_results": [
(
{
"msg": {
"errors": ["simulated error"],
"manifest_digest": "fake-digest",
"reference": "fake-reference",
"repository": "fake-repo",
}
},
None,
)
],
}
)

0 comments on commit 7069089

Please sign in to comment.