Make assertValidFernetKey assertion more robust

This assertion was a bit misleading in that it seemed to validate
one key at a time. But the implementation of the assertion actually
assumes it is given a list of string values. This commit fixes the
name of the assertion to be more clear and it also makes the
assertion iterate all values given, which ensures each key in the
list is valid, not just the first one.

Change-Id: Ifc9542e4e7f57f54d473183c97f616f92cb0961b
This commit is contained in:
Lance Bragstad 2018-02-22 22:10:59 +00:00
parent 1175a356fc
commit 70dea443c1
1 changed files with 6 additions and 4 deletions

View File

@ -695,9 +695,11 @@ class TestFernetKeyRotation(unit.TestCase):
class TestLoadKeys(unit.TestCase):
def assertValidFernetKey(self, keys):
self.assertGreater(len(keys[0]), 0)
self.assertIsInstance(keys[0], str)
def assertValidFernetKeys(self, keys):
# Make sure each key is a non-empty string
for key in keys:
self.assertGreater(len(key), 0)
self.assertIsInstance(key, str)
def test_non_numeric_files(self):
self.useFixture(
@ -717,4 +719,4 @@ class TestLoadKeys(unit.TestCase):
)
keys = key_utils.load_keys()
self.assertEqual(2, len(keys))
self.assertValidFernetKey(keys)
self.assertValidFernetKeys(keys)