Skip to content

Commit 8df82ba

Browse files
committed
fix: Verify error gets raised
1 parent 7b075af commit 8df82ba

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/test_unit_tests.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,40 @@ def test_sign_file_overloads(self):
10171017
# Clean up the temporary directory
10181018
shutil.rmtree(temp_dir)
10191019

1020+
def test_sign_file_callback_signer_reports_error(self):
1021+
"""Test signing a file using the sign_file method with a callback that reports an error."""
1022+
1023+
temp_dir = tempfile.mkdtemp()
1024+
1025+
try:
1026+
output_path = os.path.join(temp_dir, "signed_output.jpg")
1027+
1028+
# Use the sign_file method
1029+
builder = Builder(self.manifestDefinition)
1030+
1031+
# Define a callback that always returns -1 to simulate an error
1032+
def error_callback_signer(data: bytes) -> bytes:
1033+
# Return -1 to indicate an error condition
1034+
return -1
1035+
1036+
# Create signer with error callback using create_signer function
1037+
signer = create_signer(
1038+
callback=error_callback_signer,
1039+
alg=SigningAlg.ES256,
1040+
certs=self.certs.decode('utf-8'),
1041+
tsa_url="http://timestamp.digicert.com"
1042+
)
1043+
1044+
# The signing operation should fail due to the error callback
1045+
with self.assertRaises(Error):
1046+
result, manifest_bytes = builder.sign_file(
1047+
source_path=self.testPath,
1048+
dest_path=output_path,
1049+
signer=signer
1050+
)
1051+
1052+
finally:
1053+
shutil.rmtree(temp_dir)
10201054

10211055
class TestStream(unittest.TestCase):
10221056
def setUp(self):

0 commit comments

Comments
 (0)