From dbd68c5747a406f20444a781552d6754297e3ef1 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Mon, 4 Dec 2017 11:45:07 -0500 Subject: [PATCH] encryption tests around the contract with survey functionality --- awx/main/tests/unit/utils/test_encryption.py | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/awx/main/tests/unit/utils/test_encryption.py b/awx/main/tests/unit/utils/test_encryption.py index 29b68cc56b..b269c42b27 100644 --- a/awx/main/tests/unit/utils/test_encryption.py +++ b/awx/main/tests/unit/utils/test_encryption.py @@ -51,3 +51,24 @@ def test_encrypt_field_with_ask(): def test_encrypt_field_with_empty_value(): encrypted = encryption.encrypt_field(Setting(value=None), 'value') assert encrypted is None + + +class TestSurveyReversibilityValue: + ''' + Tests to enforce the contract with survey password question encrypted values + ''' + _key = encryption.get_encryption_key('value', None) + + def test_encrypt_empty_string(self): + assert encryption.encrypt_value('') == '' + # the reverse, decryption, does not work + + def test_encrypt_encryption_key(self): + assert encryption.encrypt_value('$encrypted$') == '$encrypted$' + # the reverse, decryption, does not work + + def test_encrypt_empty_string_twice(self): + # Encryption is idempotent + val = encryption.encrypt_value('foobar') + val2 = encryption.encrypt_value(val) + assert encryption.decrypt_value(self._key, val2) == 'foobar'