Exemple #1
0
 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))
Exemple #2
0
    def get_value(self, user=None):
        """
        Get the value from a secure datatype.

        Access to the value is protected by checking the user authorization levels.
        Only if the authorization level meets the requirements for the given value,
        its value will be returned.

        Otherwise a no-access value will be returned
        :param user:
        :return:
        """
        if user is None:
            has_access = False
        else:
            value = self._string
            has_access = user.has_access_to(value)

        if has_access:
            value = decrypt(value)
            return None if value is None else self.get_typed_value(value)
        else:
            return None
Exemple #3
0
    def test_encrypt_decrypt(self):
        value = encrypt("value", 10)
        self.assertEqual(decrypt(value), "value")

        value = encrypt(None, 10)
        self.assertIsNone(decrypt(value))
Exemple #4
0
 def test_decrypt(self):
     value = encrypt("value", 10)
     self.assertEqual(decrypt(value), "value")