From 1a3684e16ae4fc9dcf8a1db189ed94316fc6294c Mon Sep 17 00:00:00 2001 From: Jussi Kukkonen Date: Fri, 4 Nov 2022 15:51:09 +0200 Subject: [PATCH] tests: Add basic smoke tests for Key python-tuf has an extensive test suite for Metadata in general: * I don't think python-tuf should stop testing Key just because it's now in securesystemslib * Maybe it's not necessary to copy e.g. all serialization tests here? Still, added a few basic tests for Key. Key is also used in the Signer tests. --- tests/test_signer.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_signer.py b/tests/test_signer.py index b5edcddd8..69a7db753 100644 --- a/tests/test_signer.py +++ b/tests/test_signer.py @@ -26,6 +26,39 @@ SSlibSigner, ) +class TestKey(unittest.TestCase): + """Key tests. See many more tests in python-tuf test suite""" + def test_key_from_to_dict(self): + keydict = { + "keytype": "rsa", + "scheme": "rsassa-pss-sha256", + "extra": "somedata", + "keyval": { + "public": "pubkeyval", + "foo": "bar", + }, + } + + key = Key.from_dict("aa", copy.deepcopy(keydict)) + self.assertDictEqual(keydict, key.to_dict()) + + def test_key_is_verified(self): + sigdict = { + 'keyid': 'e33221e745d40465d1efc0215d6db83e5fdb83ea16e1fb894d09d6d96c456f3b', + 'sig': '3fc91f5411a567d6a7f28b7fbb9ba6d60b1e2a1b64d8af0b119650015d86bb5a55e57c0e2c995a9b4a332b8f435703e934c0e6ce69fe6674a8ce68719394a40b'} + keydict = { + 'keytype': 'ed25519', + 'scheme': 'ed25519', + 'keyval': { + 'public': '8ae43d22b8e0fbf4a48fa3490d31b4d389114f5dc1039c918f075427f4100759', + } + } + key = Key.from_dict("e33221e745d40465d1efc0215d6db83e5fdb83ea16e1fb894d09d6d96c456f3b", keydict) + sig = Signature.from_dict(sigdict) + + self.assertTrue(key.is_verified(sig, b"DATA")) + self.assertFalse(key.is_verified(sig, b"NOTDATA")) + class TestSigner(unittest.TestCase): """Test Signer and SSlibSigner functionality"""