Skip to content

Commit 7924f88

Browse files
authored
Merge pull request #2447 from lukpueh/fix-sslibsigner-test
tests: adopt sslib changes in test_sign_failures
2 parents 00a6ac7 + d45d655 commit 7924f88

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

tests/test_api.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import unittest
1616
from copy import copy
1717
from datetime import datetime, timedelta
18-
from typing import Any, ClassVar, Dict
18+
from typing import Any, ClassVar, Dict, Optional
1919

2020
from securesystemslib import exceptions as sslib_exceptions
2121
from securesystemslib import hash as sslib_hash
@@ -24,7 +24,12 @@
2424
import_ed25519_publickey_from_file,
2525
)
2626
from securesystemslib.keys import generate_ed25519_key
27-
from securesystemslib.signer import SSlibKey, SSlibSigner
27+
from securesystemslib.signer import (
28+
SecretsHandler,
29+
Signer,
30+
SSlibKey,
31+
SSlibSigner,
32+
)
2833

2934
from tests import utils
3035
from tuf.api import exceptions
@@ -235,16 +240,27 @@ def test_sign_verify(self) -> None:
235240

236241
def test_sign_failures(self) -> None:
237242
# Test throwing UnsignedMetadataError because of signing problems
238-
# related to bad information in the signer.
239243
md = Metadata.from_file(
240244
os.path.join(self.repo_dir, "metadata", "snapshot.json")
241245
)
242-
key_dict = copy(self.keystore[Snapshot.type])
243-
key_dict["keytype"] = "rsa"
244-
key_dict["scheme"] = "bad_scheme"
245-
sslib_signer = SSlibSigner(key_dict)
246+
247+
class FailingSigner(Signer): # pylint: disable=missing-class-docstring
248+
@classmethod
249+
def from_priv_key_uri(
250+
cls,
251+
priv_key_uri: str,
252+
public_key: Key,
253+
secrets_handler: Optional[SecretsHandler] = None,
254+
) -> "Signer":
255+
pass
256+
257+
def sign(self, payload: bytes) -> Signature:
258+
raise RuntimeError("signing failed")
259+
260+
failing_signer = FailingSigner()
261+
246262
with self.assertRaises(exceptions.UnsignedMetadataError):
247-
md.sign(sslib_signer)
263+
md.sign(failing_signer)
248264

249265
def test_key_verify_failures(self) -> None:
250266
root_path = os.path.join(self.repo_dir, "metadata", "root.json")

0 commit comments

Comments
 (0)