Merge "Gracefully handle request for binary data as plain"

This commit is contained in:
Jenkins 2013-11-12 18:37:40 +00:00 committed by Gerrit Code Review
commit 0905323ccd
2 changed files with 11 additions and 1 deletions

View File

@ -202,7 +202,10 @@ def denormalize_after_decryption(unencrypted, content_type):
# Process plain-text type.
if content_type in mime_types.PLAIN_TEXT:
# normalize text to binary string
unencrypted = unencrypted.decode('utf-8')
try:
unencrypted = unencrypted.decode('utf-8')
except UnicodeDecodeError:
raise CryptoAcceptNotSupportedException(content_type)
# Process binary type.
elif content_type not in mime_types.BINARY:

View File

@ -175,6 +175,13 @@ class WhenTestingDenormalizeAfterDecryption(unittest.TestCase):
em.denormalize_after_decryption(self.unencrypted,
self.content_type)
def test_decrypt_fail_binary_as_plain(self):
self.unencrypted = '\xff'
self.content_type = 'text/plain'
with self.assertRaises(em.CryptoAcceptNotSupportedException):
em.denormalize_after_decryption(self.unencrypted,
self.content_type)
class WhenTestingCryptoExtensionManager(unittest.TestCase):