Exemplo n.º 1
0
    def test_is_secure_type(self):
        authority = Authority('secure catalog', 'any col')

        spec = {"type": "GOB.String"}
        self.assertFalse(authority.is_secure_type(spec))

        spec = {"type": "GOB.SecureString"}
        self.assertTrue(authority.is_secure_type(spec))

        spec = {
            "type": "GOB.JSON",
            "attributes": {
                "attr": {
                    "type": "GOB.String"
                }
            }
        }
        self.assertFalse(authority.is_secure_type(spec))

        spec = {
            "type": "GOB.JSON",
            "attributes": {
                "attr": {
                    "type": "GOB.String"
                },
                "attr": {
                    "type": "GOB.SecureString"
                }
            }
        }
        self.assertTrue(authority.is_secure_type(spec))
Exemplo n.º 2
0
def _to_gob_value(entity, field, spec, resolve_secure=False):
    """
    Transforms a entity field value into a GOB type value

    Attention:
    Resolve secure is normally False as this is all handled by the Authority classes
    For enhanced views however, this is not possible.
    These queries are based upon a view and cannot directly be related to a GOB Model
    If the field names of the view are properly named the decryption will be handled here

    :param entity:
    :param field:
    :param spec:
    :param resolve_secure:
    :return:
    """
    entity_value = getattr(entity, field, None)
    if isinstance(spec, dict):
        gob_type = get_gob_type_from_info(spec)
        if resolve_secure and Authority.is_secure_type(spec):
            # Transform the value into a secure type value
            secure_type = Authority.get_secure_type(gob_type, spec,
                                                    entity_value)
            # Return decrypted value
            return Authority.get_secured_value(secure_type)
        return gob_type.from_value(entity_value, **spec)
    else:
        gob_type = get_gob_type_from_sql_type(spec)
        return gob_type.from_value(entity_value)