From d50ded73955f2c556c8a7c21822666f35cf4fb15 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Thu, 23 May 2019 12:00:13 -0400 Subject: [PATCH] Fix intermittent error in test_decrypt_dict_invalid_key Sometimes decryption with the wrong key works but produces garbage data. This is annoying because it occasionally fails the gate at random. Change-Id: I1563962aca8efa30773f03792f7cfd6b7774443d Task: 33482 --- heat/common/crypt.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/heat/common/crypt.py b/heat/common/crypt.py index b3afc77614..1da762b496 100644 --- a/heat/common/crypt.py +++ b/heat/common/crypt.py @@ -125,7 +125,12 @@ def decrypted_dict(data, encryption_key=None): return return_data for prop_name, prop_value in data.items(): method, value = prop_value - decrypted_value = decrypt(method, value, encryption_key) + try: + decrypted_value = decrypt(method, value, encryption_key) + except UnicodeDecodeError: + # The dict contained valid JSON on the way in, so if what comes + # out is garbage then the key was incorrect. + raise exception.InvalidEncryptionKey() prop_string = jsonutils.loads(decrypted_value) return_data[prop_name] = prop_string return return_data