Merge pull request #1671 from MVrachev/split-test

Tests: test_api split test_sign_verify()
This commit is contained in:
Jussi Kukkonen 2021-11-11 10:32:12 +02:00 committed by GitHub
commit 5a9b3fa963
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -203,21 +203,36 @@ def test_sign_verify(self):
with self.assertRaises(exceptions.UnsignedMetadataError):
targets_key.verify_signature(md_obj)
# Test failure on unknown scheme (securesystemslib UnsupportedAlgorithmError)
def test_verify_failures(self):
root_path = os.path.join(self.repo_dir, "metadata", "root.json")
root = Metadata[Root].from_file(root_path).signed
# Locate the timestamp public key we need from root
timestamp_keyid = next(iter(root.roles["timestamp"].keyids))
timestamp_key = root.keys[timestamp_keyid]
# Load sample metadata (timestamp)
path = os.path.join(self.repo_dir, "metadata", "timestamp.json")
md_obj = Metadata.from_file(path)
# Test failure on unknown scheme (securesystemslib
# UnsupportedAlgorithmError)
scheme = timestamp_key.scheme
timestamp_key.scheme = "foo"
with self.assertRaises(exceptions.UnsignedMetadataError):
timestamp_key.verify_signature(md_obj)
timestamp_key.scheme = scheme
# Test failure on broken public key data (securesystemslib CryptoError)
# Test failure on broken public key data (securesystemslib
# CryptoError)
public = timestamp_key.keyval["public"]
timestamp_key.keyval["public"] = "ffff"
with self.assertRaises(exceptions.UnsignedMetadataError):
timestamp_key.verify_signature(md_obj)
timestamp_key.keyval["public"] = public
# Test failure with invalid signature (securesystemslib FormatError)
# Test failure with invalid signature (securesystemslib
# FormatError)
sig = md_obj.signatures[timestamp_keyid]
correct_sig = sig.signature
sig.signature = "foo"