def test_decrypt_error(self): value = encrypt("value", 10) # Manipulate value value = json.loads(value) value['v'] = f"_{value['v']}" value = json.dumps(value) self.assertIsNone(decrypt(value))
def __init__(self, value, level=None): """ Initialize a secure value. If the value is not yet secured, secure it :param value: the secure value :param level: the level to encrypt the value if it is still unencrypted """ if not is_encrypted(value): assert level is not None, "Missing level to encrypt the given value" value = None if value._string is None else str(value) value = encrypt(value, level=level) super().__init__(value)
def test_encrypt_decrypt(self): value = encrypt("value", 10) self.assertEqual(decrypt(value), "value") value = encrypt(None, 10) self.assertIsNone(decrypt(value))
def test_decrypt(self): value = encrypt("value", 10) self.assertEqual(decrypt(value), "value")
def test_encrypt(self): self.assertEqual(json.loads(encrypt("value", 10)), { "i": mock.ANY, "l": 10, "v": mock.ANY })