Merge "Update crypto unit test coverage."
This commit is contained in:
commit
6cd5448ed9
@ -138,6 +138,16 @@ class WhenTestingNormalizeBeforeEncryptionForText(unittest.TestCase):
|
||||
self.enforce_text_only
|
||||
)
|
||||
|
||||
def test_raises_on_no_payload(self):
|
||||
content_type = 'text/plain; charset=ISO-8859-1'
|
||||
with self.assertRaises(em.CryptoNoPayloadProvidedException):
|
||||
unenc, content = em.normalize_before_encryption(
|
||||
None,
|
||||
content_type,
|
||||
self.content_encoding,
|
||||
self.enforce_text_only
|
||||
)
|
||||
|
||||
|
||||
class WhenTestingAnalyzeBeforeDecryption(unittest.TestCase):
|
||||
|
||||
|
@ -46,6 +46,20 @@ class WhenTestingIsBase64ProcessingNeeded(unittest.TestCase):
|
||||
self.assertFalse(r)
|
||||
|
||||
|
||||
class WhenTestingIsBase64ProcessingSupported(unittest.TestCase):
|
||||
|
||||
def test_is_base64_supported_application_octet_stream(self):
|
||||
r = mime_types.is_base64_encoding_supported('application/octet-stream')
|
||||
self.assertTrue(r)
|
||||
|
||||
def test_is_base64_supported_with_unsupported_values(self):
|
||||
mimes_where_base64_is_not_supported = ['text/plain',
|
||||
'bogus']
|
||||
for mime in mimes_where_base64_is_not_supported:
|
||||
r = mime_types.is_base64_encoding_supported(mime)
|
||||
self.assertFalse(r)
|
||||
|
||||
|
||||
class WhenTestingAugmentFieldsWithContentTypes(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
@ -115,6 +129,11 @@ class WhenTestingNormalizationOfMIMETypes(unittest.TestCase):
|
||||
r = mime_types.normalize_content_type(mime)
|
||||
self.assertEqual(r, mime)
|
||||
|
||||
def test_malformed_charset_in_plain_text_mime(self):
|
||||
mime = 'text/plain; charset is ISO-8859-1'
|
||||
r = mime_types.normalize_content_type(mime)
|
||||
self.assertEqual(r, mime)
|
||||
|
||||
def test_binary_normalization(self):
|
||||
mime = 'application/octet-stream'
|
||||
r = mime_types.normalize_content_type(mime)
|
||||
|
@ -67,6 +67,15 @@ class WhenTestingP11CryptoPlugin(unittest.TestCase):
|
||||
with self.assertRaises(ValueError):
|
||||
p11_crypto.P11CryptoPlugin(m)
|
||||
|
||||
def test_raises_error_with_bad_library_path(self):
|
||||
m = mock.MagicMock()
|
||||
self.pkcs11.lib.C_Initialize.return_value = 12345
|
||||
m.p11_crypto_plugin = mock.MagicMock(library_path="/dev/null")
|
||||
|
||||
# TODO: Really raises PyKCS11.PyKCS11Error
|
||||
with self.assertRaises(Exception):
|
||||
p11_crypto.P11CryptoPlugin(m)
|
||||
|
||||
def test_init_builds_sessions_and_login(self):
|
||||
self.pkcs11.openSession.assert_any_call(1)
|
||||
self.pkcs11.openSession.assert_any_call(1, 'RW')
|
||||
|
@ -143,3 +143,12 @@ class WhenTestingSimpleCryptoPlugin(unittest.TestCase):
|
||||
self.assertFalse(
|
||||
self.plugin.supports("SOMETHING_RANDOM")
|
||||
)
|
||||
|
||||
def test_bind_kek_metadata(self):
|
||||
kek_metadata_dto = MagicMock()
|
||||
kek_metadata_dto = self.plugin.bind_kek_metadata(kek_metadata_dto)
|
||||
|
||||
self.assertEqual(kek_metadata_dto.algorithm, 'aes')
|
||||
self.assertEqual(kek_metadata_dto.bit_length, 128)
|
||||
self.assertEqual(kek_metadata_dto.mode, 'cbc')
|
||||
self.assertIsNone(kek_metadata_dto.plugin_meta)
|
||||
|
Loading…
x
Reference in New Issue
Block a user