Skip to content

Commit d45d655

Browse files
author
Lukas Puehringer
committed
tests: adopt sslib changes in test_sign_failures
fixes #2444 SSlibSigner was changed recently (secure-stystems-lab/securesystemslib#604) to fail on bad input data (keydict) at init instead of when signing. The patched test used to trigger expects a Signer.sign error from an SSlibSigner, which is no longer possible. To still get the desired error, the test uses a custom signer, which does raise on sign. Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
1 parent 016e16c commit d45d655

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
@@ -234,16 +239,27 @@ def test_sign_verify(self) -> None:
234239

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

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

0 commit comments

Comments
 (0)