Merge "Gracefully handle request for binary data as plain"
This commit is contained in:
commit
0905323ccd
@ -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:
|
||||
|
@ -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):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user