Merge "Removed dead code and updated tests to cover 100% for crypto"

This commit is contained in:
Jenkins
2014-01-31 18:35:47 +00:00
committed by Gerrit Code Review
5 changed files with 33 additions and 5 deletions
+1 -4
View File
@@ -169,7 +169,7 @@ def normalize_before_encryption(unencrypted, content_type, content_encoding,
unencrypted = unencrypted.encode('utf-8')
# Process binary type.
elif normalized_mime in mime_types.BINARY:
else:
# payload has to be decoded
if mime_types.is_base64_processing_needed(content_type,
content_encoding):
@@ -185,9 +185,6 @@ def normalize_before_encryption(unencrypted, content_type, content_encoding,
# Unsupported content-encoding request.
raise CryptoContentEncodingNotSupportedException(content_encoding)
else:
raise CryptoContentTypeNotSupportedException(content_type)
return unencrypted, normalized_mime
+1 -1
View File
@@ -76,7 +76,7 @@ class P11CryptoPlugin(plugin.CryptoPluginBase):
return keys[0]
elif len(keys) == 0:
return None
elif len(keys) > 1:
else:
raise P11CryptoPluginKeyException()
def _generate_iv(self):
+5
View File
@@ -100,6 +100,7 @@ class CryptoPluginBase(object):
outside of the plugins)
"""
raise NotImplementedError # pragma: no cover
@abc.abstractmethod
def decrypt(self, encrypted, kek_meta_dto, kek_meta_extended, keystone_id):
@@ -113,6 +114,7 @@ class CryptoPluginBase(object):
:returns: str -- unencrypted byte data
"""
raise NotImplementedError # pragma: no cover
@abc.abstractmethod
def bind_kek_metadata(self, kek_meta_dto):
@@ -134,10 +136,12 @@ class CryptoPluginBase(object):
:returns: kek_meta_dto: Returns the specified DTO, after
modifications.
"""
raise NotImplementedError # pragma: no cover
@abc.abstractmethod
def create(self, bit_length, type_enum, algorithm=None, mode=None):
"""Create a new key."""
raise NotImplementedError # pragma: no cover
@abc.abstractmethod
def supports(self, type_enum, algorithm=None, mode=None):
@@ -146,6 +150,7 @@ class CryptoPluginBase(object):
:param type_enum: Enumeration from PluginSupportsType class
:param algorithm: String algorithm name if needed
"""
raise NotImplementedError # pragma: no cover
class SimpleCryptoPlugin(CryptoPluginBase):
@@ -246,6 +246,22 @@ class WhenTestingCryptoExtensionManager(unittest.TestCase):
mock.MagicMock()
)
def test_decrypt_no_supported_plugin_found(self):
""" Similar to test_decrypt_no_plugin_found, but in this case
no plugin can be found that supports the specified secret's
encrypted data.
"""
fake_secret = mock.MagicMock()
fake_datum = mock.MagicMock()
fake_datum.kek_meta_tenant = mock.MagicMock()
fake_secret.encrypted_data = [fake_datum]
with self.assertRaises(em.CryptoPluginNotFound):
self.manager.decrypt(
'text/plain',
fake_secret,
mock.MagicMock()
)
def test_generate_data_encryption_key_no_plugin_found(self):
self.manager.extensions = []
with self.assertRaises(em.CryptoPluginNotFound):
+10
View File
@@ -40,6 +40,11 @@ class WhenTestingIsBase64ProcessingNeeded(unittest.TestCase):
None)
self.assertFalse(r)
def test_not_base64_needed_invalid_content_type(self):
r = mime_types.is_base64_processing_needed('bababooey',
'base64')
self.assertFalse(r)
def test_not_base64_needed_text(self):
r = mime_types.is_base64_processing_needed('text/plain',
'base64')
@@ -93,6 +98,11 @@ class WhenTestingAugmentFieldsWithContentTypes(unittest.TestCase):
for ct in mime_types.SUPPORTED:
self._test_secret_and_datum_for_content_type(ct)
def test_secret_with_non_matching_datum(self):
self.datum.content_type = "bababooey"
fields = mime_types.augment_fields_with_content_types(self.secret)
self.assertNotIn("bababooey", fields)
def _test_secret_and_datum_for_content_type(self, content_type):
self.assertIn(content_type, mime_types.INTERNAL_CTYPES)
self.datum.content_type = mime_types.INTERNAL_CTYPES[content_type]