Skip to content

Commit

Permalink
tests: Improve verify_signature tests
Browse files Browse the repository at this point in the history
Test unknown signature algorithm/scheme.

Also shorten the incorrect (but syntactically valid) signature a bit.

Signed-off-by: Jussi Kukkonen <[email protected]>
  • Loading branch information
Jussi Kukkonen committed Jun 17, 2021
1 parent 743c440 commit 70aff4c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ def test_sign_verify(self):
with self.assertRaises(exceptions.UnsignedMetadataError):
targets_key.verify_signature(metadata_obj)

# Test failure on unknown scheme (securesystemslib UnsupportedAlgorithmError)
scheme = timestamp_key.scheme
timestamp_key.scheme = "foo"
with self.assertRaises(exceptions.UnsignedMetadataError):
timestamp_key.verify_signature(metadata_obj)
timestamp_key.scheme = scheme

# Test failure on broken public key data (securesystemslib CryptoError)
public = timestamp_key.keyval["public"]
timestamp_key.keyval["public"] = "ffff"
Expand All @@ -220,7 +227,7 @@ def test_sign_verify(self):
timestamp_key.verify_signature(metadata_obj)

# Test failure with valid but incorrect signature
sig.signature = "52af76354db3403242e1437b1fbf1c7edc4e66b81dfd63b3026ff681d57e88e11a697cca78061a376a9dd8d7fde5777b14d4e6d8e75f976101cbc61321642f06"
sig.signature = "ff"*64
with self.assertRaises(exceptions.UnsignedMetadataError):
timestamp_key.verify_signature(metadata_obj)
sig.signature = correct_sig
Expand Down

0 comments on commit 70aff4c

Please sign in to comment.