Skip to content

Commit

Permalink
Merge pull request #2447 from lukpueh/fix-sslibsigner-test
Browse files Browse the repository at this point in the history
tests: adopt sslib changes in test_sign_failures
  • Loading branch information
jku authored Aug 17, 2023
2 parents 00a6ac7 + d45d655 commit 7924f88
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import unittest
from copy import copy
from datetime import datetime, timedelta
from typing import Any, ClassVar, Dict
from typing import Any, ClassVar, Dict, Optional

from securesystemslib import exceptions as sslib_exceptions
from securesystemslib import hash as sslib_hash
Expand All @@ -24,7 +24,12 @@
import_ed25519_publickey_from_file,
)
from securesystemslib.keys import generate_ed25519_key
from securesystemslib.signer import SSlibKey, SSlibSigner
from securesystemslib.signer import (
SecretsHandler,
Signer,
SSlibKey,
SSlibSigner,
)

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

def test_sign_failures(self) -> None:
# Test throwing UnsignedMetadataError because of signing problems
# related to bad information in the signer.
md = Metadata.from_file(
os.path.join(self.repo_dir, "metadata", "snapshot.json")
)
key_dict = copy(self.keystore[Snapshot.type])
key_dict["keytype"] = "rsa"
key_dict["scheme"] = "bad_scheme"
sslib_signer = SSlibSigner(key_dict)

class FailingSigner(Signer): # pylint: disable=missing-class-docstring
@classmethod
def from_priv_key_uri(
cls,
priv_key_uri: str,
public_key: Key,
secrets_handler: Optional[SecretsHandler] = None,
) -> "Signer":
pass

def sign(self, payload: bytes) -> Signature:
raise RuntimeError("signing failed")

failing_signer = FailingSigner()

with self.assertRaises(exceptions.UnsignedMetadataError):
md.sign(sslib_signer)
md.sign(failing_signer)

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

0 comments on commit 7924f88

Please sign in to comment.