def test_it_returns_True_if_url_matches_one_or_more_scopes(
         self, scope_lists, url, in_origin, in_path, in_other):
     assert scope_util.url_in_scope(url,
                                    scope_lists["origin_only"]) == in_origin
     assert scope_util.url_in_scope(url,
                                    scope_lists["with_path"]) == in_path
     assert scope_util.url_in_scope(url,
                                    scope_lists["with_other"]) == in_other
Example #2
0
def _validate_group_scope(group, target_uri):
    # If no scopes are present, or if the group is configured to allow
    # annotations outside of its scope, there's nothing to do here
    if not group.scopes or group.enforce_scope is False:
        return
    # The target URI must match at least one
    # of a group's defined scopes, if the group has any
    group_scopes = [scope.scope for scope in group.scopes]
    if not url_in_scope(target_uri, group_scopes):
        raise schemas.ValidationError("group scope: " +
                                      _("Annotations for this target URI "
                                        "are not allowed in this group"))
Example #3
0
def _validate_group_scope(group, target_uri):
    # If no scopes are present, or if the group is configured to allow
    # annotations outside of its scope, there's nothing to do here
    if not group.scopes or group.enforce_scope is False:
        return
    # The target URI must match at least one
    # of a group's defined scopes, if the group has any
    group_scopes = [scope.scope for scope in group.scopes]
    if not url_in_scope(target_uri, group_scopes):
        raise schemas.ValidationError(
            "group scope: "
            + _("Annotations for this target URI " "are not allowed in this group")
        )
Example #4
0
    def fetch_by_scope(self, url):
        """Return GroupScope records that match the given URL

        :arg url: URL to find matching scopes for
        :type url: str
        :rtype: list(:class:`~h.models.group_scope.GroupScope`)
        """
        origin = scope_util.parse_origin(url)
        if not origin:
            return []
        origin_scopes = (self._session.query(GroupScope).filter(
            GroupScope.origin == origin).all())
        return [
            scope for scope in origin_scopes
            if scope_util.url_in_scope(url, [scope.scope])
        ]
Example #5
0
 def test_it_returns_True_if_url_matches_one_or_more_scopes(
     self, scope_lists, url, in_origin, in_path, in_other
 ):
     assert scope_util.url_in_scope(url, scope_lists["origin_only"]) == in_origin
     assert scope_util.url_in_scope(url, scope_lists["with_path"]) == in_path
     assert scope_util.url_in_scope(url, scope_lists["with_other"]) == in_other