aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2017-04-23 18:30:05 -0400
committerRob Austein <sra@hactrn.net>2017-04-23 18:30:05 -0400
commitf502844d18282c928cf5fedb483514c1fcfd0b92 (patch)
tree5a24c154a9fff1fc53879c13874f6b988683f26c
parentffe5b3ad0ace1bda0a50373b4fc30bd702a62ec7 (diff)
Handle error conditions when deleting keys by UUID.
-rw-r--r--unit-tests.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/unit-tests.py b/unit-tests.py
index 2cdc663..10aa810 100644
--- a/unit-tests.py
+++ b/unit-tests.py
@@ -563,11 +563,19 @@ class TestPKeyMatch(TestCaseLoggedIn):
exportable = HAL_KEY_FLAG_EXPORTABLE)
return ", ".join(sorted(k for k, v in names.iteritems() if (flags & v) != 0))
+ @staticmethod
+ def cleanup_key(uuid):
+ try:
+ with hsm.pkey_open(uuid) as pkey:
+ pkey.delete()
+ except Exception as e:
+ logger.debug("Problem deleting key %s: %s", uuid, e)
+
def load_keys(self, flags):
uuids = set()
for obj in PreloadedKey.db.itervalues():
with hsm.pkey_load(obj.der, flags) as k:
- self.addCleanup(lambda uuid: hsm.pkey_open(uuid).delete(), k.uuid)
+ self.addCleanup(self.cleanup_key, k.uuid)
uuids.add(k.uuid)
#print k.uuid, k.key_type, k.key_curve, self.key_flag_names(k.key_flags)
k.set_attributes(dict((i, a) for i, a in enumerate((str(obj.keytype), str(obj.fn2)))))
@@ -637,13 +645,21 @@ class TestPKeyAttribute(TestCaseLoggedIn):
Attribute creation/lookup/deletion tests.
"""
+ @staticmethod
+ def cleanup_key(uuid):
+ try:
+ with hsm.pkey_open(uuid) as pkey:
+ pkey.delete()
+ except:
+ logger.debug("Problem deleting key %s: %s", uuid, e)
+
def load_and_fill(self, flags, n_keys = 1, n_attrs = 2, n_fill = 0):
pinwheel = Pinwheel()
for i in xrange(n_keys):
for obj in PreloadedKey.db.itervalues():
with hsm.pkey_load(obj.der, flags) as k:
pinwheel()
- self.addCleanup(lambda uuid: hsm.pkey_open(uuid).delete(), k.uuid)
+ self.addCleanup(self.cleanup_key, k.uuid)
k.set_attributes(dict((j, "Attribute {}{}".format(j, "*" * n_fill))
for j in xrange(n_attrs)))
pinwheel()