From f753e781c4798b08276500c4232b054e5583d2d5 Mon Sep 17 00:00:00 2001 From: Martin Vrachev Date: Thu, 11 Feb 2021 21:37:48 +0200 Subject: [PATCH] Address Lukas comments - add ed25519key_dict to test Signed-off-by: Martin Vrachev --- tests/test_signer.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/test_signer.py b/tests/test_signer.py index bae7b506..918ecb7f 100644 --- a/tests/test_signer.py +++ b/tests/test_signer.py @@ -21,7 +21,7 @@ import securesystemslib.formats import securesystemslib.keys as KEYS from securesystemslib.signer import Signature, SSlibSigner -import securesystemslib.exceptions as exceptions +from securesystemslib.exceptions import FormatError, UnsupportedAlgorithmError class TestSSlibSigner(unittest.TestCase): @@ -33,12 +33,11 @@ def setUpClass(cls): cls.DATA_STR = 'SOME DATA REQUIRING AUTHENTICITY.' cls.DATA = securesystemslib.formats.encode_canonical(cls.DATA_STR).encode( 'utf-8') - cls.FORMAT_ERROR_MSG = 'securesystemslib.exceptions.FormatError was raised!' + \ - ' Check object\'s format.' def test_sslib_sign(self): - for scheme_dict in [self.rsakey_dict, self.ecdsakey_dict]: + dicts_list = [self.rsakey_dict, self.ecdsakey_dict, self.ed25519key_dict] + for scheme_dict in dicts_list: # Test generation of signatures. sslib_signer = SSlibSigner(scheme_dict) sig_obj = sslib_signer.sign(self.DATA) @@ -52,24 +51,25 @@ def test_sslib_sign(self): scheme_dict['keyval']['private'] = '' sslib_signer.key_dict = scheme_dict - with self.assertRaises(ValueError): + with self.assertRaises((ValueError, FormatError)): sslib_signer.sign(self.DATA) scheme_dict['keyval']['private'] = private + # Test for invalid signature scheme. + valid_scheme = scheme_dict['scheme'] + scheme_dict['scheme'] = 'invalid_scheme' + sslib_signer = SSlibSigner(scheme_dict) + + with self.assertRaises((UnsupportedAlgorithmError, FormatError)): + sslib_signer.sign(self.DATA) + + scheme_dict['scheme'] = valid_scheme + # Supplying an incorrect number of arguments. with self.assertRaises(TypeError): sslib_signer.sign() - # Test for invalid signature scheme. - valid_scheme = self.rsakey_dict['scheme'] - self.rsakey_dict['scheme'] = 'invalid_scheme' - sslib_signer = SSlibSigner(self.rsakey_dict) - - with self.assertRaises(exceptions.UnsupportedAlgorithmError): - sslib_signer.sign(self.DATA) - - self.rsakey_dict['scheme'] = valid_scheme def test_signature_from_to_json(self):