From 3c5e312e602b54a48ccbc36e06d698bac199cafb Mon Sep 17 00:00:00 2001 From: Teodora Sechkova Date: Fri, 3 Jul 2020 18:04:43 +0300 Subject: [PATCH] WIP added tuf.api keys tests Signed-off-by: Teodora Sechkova --- tests/test_tuf_api.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/test_tuf_api.py b/tests/test_tuf_api.py index 41170414..c4f15a15 100644 --- a/tests/test_tuf_api.py +++ b/tests/test_tuf_api.py @@ -166,3 +166,44 @@ def test_metadata_timestamp(self): # timestamp.sign() # timestamp.write_to_json() + +def test_Threshold(self): + # test default values + keys.Threshold() + # test correct arguments + keys.Threshold(min_=4, max_=5) + + # test incorrect input + # TODO raise sslib.FormatError or ValueError instead of AssertionErrors + self.assertRaises(AssertionError, keys.Threshold, 5, 4) + self.assertRaises(AssertionError, keys.Threshold, 0, 5) + self.assertRaises(AssertionError, keys.Threshold, 5, 0) + + +def test_KeyRing(self): + key_list = [] + root_key = keys.read_key(os.path.join(self.keystore_dir, 'root_key'), + 'RSA', 'password') + root_key2 = keys.read_key(os.path.join(self.keystore_dir, 'root_key2'), + 'ED25519', 'password') + key_list.append(root_key) + key_list.append(root_key2) + threshold = keys.Threshold() + keyring = keys.KeyRing(threshold, key_list) + self.assertEqual(keyring.threshold, threshold) + self.assertEqual(keyring.keys, key_list) + + +def test_read_key(self): + filename = os.path.join(self.keystore_dir, 'root_key') + algorithm = 'RSA' + passphrase = 'password' + + self.assertTrue(isinstance(keys.read_key(filename, algorithm, passphrase), keys.RAMKey)) + +# TODO: +# def test_RAMKey(self): + +# Run unit test. +if __name__ == '__main__': + unittest.main()