|
15 | 15 | import unittest |
16 | 16 | from copy import copy |
17 | 17 | from datetime import datetime, timedelta |
18 | | -from typing import Any, ClassVar, Dict |
| 18 | +from typing import Any, ClassVar, Dict, Optional |
19 | 19 |
|
20 | 20 | from securesystemslib import exceptions as sslib_exceptions |
21 | 21 | from securesystemslib import hash as sslib_hash |
|
24 | 24 | import_ed25519_publickey_from_file, |
25 | 25 | ) |
26 | 26 | 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 | +) |
28 | 33 |
|
29 | 34 | from tests import utils |
30 | 35 | from tuf.api import exceptions |
@@ -235,16 +240,27 @@ def test_sign_verify(self) -> None: |
235 | 240 |
|
236 | 241 | def test_sign_failures(self) -> None: |
237 | 242 | # Test throwing UnsignedMetadataError because of signing problems |
238 | | - # related to bad information in the signer. |
239 | 243 | md = Metadata.from_file( |
240 | 244 | os.path.join(self.repo_dir, "metadata", "snapshot.json") |
241 | 245 | ) |
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 | + |
246 | 262 | with self.assertRaises(exceptions.UnsignedMetadataError): |
247 | | - md.sign(sslib_signer) |
| 263 | + md.sign(failing_signer) |
248 | 264 |
|
249 | 265 | def test_key_verify_failures(self) -> None: |
250 | 266 | root_path = os.path.join(self.repo_dir, "metadata", "root.json") |
|
0 commit comments