Skip to content

Commit

Permalink
tests: Add basic smoke tests for Key
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jku committed Nov 4, 2022
1 parent bfeda3c commit 61f1774
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/test_signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,45 @@
)


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"""

Expand Down

0 comments on commit 61f1774

Please sign in to comment.