diff options
author | Rob Austein <sra@hactrn.net> | 2017-05-04 17:12:27 -0400 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2017-05-04 17:12:27 -0400 |
commit | 89f03d199f820f3de967ee2a72b7d9a4cf21ea7f (patch) | |
tree | d7267e751defec099de7d1e11e4381db644a6014 | |
parent | f452e1e4767e2b0ad312ce62125a49e4f137a537 (diff) |
Regression tests for today's C_FindObjects() bugfixes.
-rw-r--r-- | unit_tests.py | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/unit_tests.py b/unit_tests.py index 1a7470d..fe96207 100644 --- a/unit_tests.py +++ b/unit_tests.py @@ -187,14 +187,25 @@ class TestDevice(TestCase): self.assertIsInstance(random, str) self.assertEqual(len(random), n) - def test_findObjects(self): - "Test basic C_FindObjects*() behavior" + def test_findObjects_operation_state(self): + "Test C_FindObjects*() CKR_OPERATION_* behavior" session = p11.C_OpenSession(args.slot) + + with self.assertRaises(CKR_OPERATION_NOT_INITIALIZED): + for handle in p11.C_FindObjects(session): + self.assertIsInstance(handle, (int, long)) + + with self.assertRaises(CKR_OPERATION_NOT_INITIALIZED): + p11.C_FindObjectsFinal(session) + p11.C_FindObjectsInit(session, CKA_CLASS = CKO_PUBLIC_KEY) + with self.assertRaises(CKR_OPERATION_ACTIVE): p11.C_FindObjectsInit(session, CKA_CLASS = CKO_PRIVATE_KEY) + for handle in p11.C_FindObjects(session): self.assertIsInstance(handle, (int, long)) + p11.C_FindObjectsFinal(session) @@ -573,6 +584,31 @@ class TestKeys(TestCase): p11.C_VerifyUpdate(self.session, tbs) p11.C_VerifyFinal(self.session, sig) + def _find_objects(self, chunk_size = 10, template = None, **kwargs): + p11.C_FindObjectsInit(self.session, template, **kwargs) + for handle in p11.C_FindObjects(self.session, chunk_size): + self.assertIsInstance(handle, (int, long)) + p11.C_FindObjectsFinal(self.session) + + @unittest.skipUnless(pycrypto_loaded, "requires PyCrypto") + def test_findObjects(self): + self._load_rsa_keypair(rsa_1024_pem, "RSA-1024") + self._load_rsa_keypair(rsa_2048_pem, "RSA-2048") + self._load_rsa_keypair(rsa_3416_pem, "RSA-3416") + self._find_objects(chunk_size = 1, CKA_CLASS = CKO_PUBLIC_KEY) + self._find_objects(chunk_size = 1, CKA_CLASS = CKO_PRIVATE_KEY) + self._find_objects(chunk_size = 10, CKA_CLASS = CKO_PUBLIC_KEY) + self._find_objects(chunk_size = 10, CKA_CLASS = CKO_PRIVATE_KEY) + self._find_objects(chunk_size = 100, CKA_CLASS = CKO_PUBLIC_KEY) + self._find_objects(chunk_size = 100, CKA_CLASS = CKO_PRIVATE_KEY) + self._find_objects(chunk_size = 1) + self._find_objects(chunk_size = 1) + self._find_objects(chunk_size = 10) + self._find_objects(chunk_size = 10) + self._find_objects(chunk_size = 100) + self._find_objects(chunk_size = 100) + + # Keys for preload tests, here rather than inline because they're # bulky. These are in PKCS #8 format, see PyCrypto or the "pkey" and # "genpkey" commands to OpenSSL's command line tool. |