Skip to content

Commit

Permalink
Address Lukas comments - add ed25519key_dict to test
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
  • Loading branch information
MVrachev committed Feb 11, 2021
1 parent 726cbe3 commit f753e78
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions tests/test_signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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)
Expand All @@ -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):
Expand Down

0 comments on commit f753e78

Please sign in to comment.