Пример #1
0
    def test_permissions(self):
        coll = Collection.find("test_root")

        User.create(username="******",
                    password="******",
                    email="*****@*****.**",
                    quick=True)
        User.create(username="******",
                    password="******",
                    email="*****@*****.**",
                    quick=True)
        owning_user = User.find("protected_test_owner")
        reading_user = User.find("protected_reader")
        assert owning_user
        assert reading_user

        group = Group.create(name="protected_group", owner=owning_user.id)
        Collection.create(name="protected",
                          parent=coll.id,
                          read_access=[group.id])

        c = Collection.find("protected")
        res_count = SearchIndex.index(c, ['name', 'metadata'])
        assert res_count == 1

        results = SearchIndex.find(["protected"], reading_user)
        assert len(results) == 0, results
Пример #2
0
def do_ingest(cfg, args):
    if not args.user or not args.group or not args.folder:
        msg = "Group, User and Folder are all required for ingesting data"
        logger.error(msg)
        print msg
        sys.exit(1)

    # Check validity of the arguments (do user/group and folder)
    # actually exist.
    user = User.find(args.user)
    if not user:
        msg = u"User '{}' not found".format(args.user)
        logger.error(msg)
        print msg
        sys.exit(1)

    group = Group.find(args.group)
    if not group:
        msg = u"Group '{}' not found".format(args.group)
        logger.error(msg)
        print msg
        sys.exit(1)

    path = os.path.abspath(args.folder)
    if not os.path.exists(path):
        msg = u"Could not find path {}".format(path)
        logger.error(msg)
        print msg

    local_ip = args.local_ip
    skip_import = args.no_import

    ingester = Ingester(user, group, path, local_ip, skip_import)
    ingester.start()
Пример #3
0
    def test_perms_for_collection_success_collection_no_group(self):
        User.create(username="******",
                    password="******",
                    email="*****@*****.**",
                    groups=[],
                    quick=True)
        user = User.find("test_coll3")

        root = Collection.find("test_root")
        coll = Collection.create(name="perm_check3",
                                 parent=str(root.id),
                                 read_access=[])

        # User can read collection coll if user is in a group also in coll's read_access
        assert coll.user_can(user, "read") == True
Пример #4
0
    def test_perms_for_collection(self):
        User.create(username="******",
                    password="******",
                    email="*****@*****.**",
                    groups=[],
                    quick=True)
        user = User.find("test_coll")
        group = Group.create(name="test_group_coll", owner=user.id)
        user.update(groups=[group.id])

        root = Collection.find("test_root")
        coll = Collection.create(name="perm_check",
                                 parent=str(root.id),
                                 read_access=[group.id])

        # User can read collection coll if user is in a group also in coll's read_access
        assert coll.user_can(user, "read") == True
Пример #5
0
    def test_group_membership(self):
        user = User.create(username="******",
                           password="******",
                           email="*****@*****.**",
                           groups=[],
                           quick=True)
        assert user
        group = Group.create(name="test_group_1", owner=user.id)
        user.update(groups=[group.id])

        # Refetch the user
        user = User.find("test_group")
        assert group.id in user.groups

        groups = Group.find_by_ids(user.groups)
        assert [g.id for g in groups] == user.groups

        users = group.get_users()
        assert users[0].id == user.id
Пример #6
0
    def test_index(self):
        coll = Collection.create(name="test_root", parent=None, path="/")

        res_count = SearchIndex.index(coll, ['name'])
        assert res_count == 2, res_count

        User.create(username="******",
                    password="******",
                    email="*****@*****.**",
                    quick=True)
        user = User.find("test_index_user")

        results = SearchIndex.find(["test", "root"], user)
        assert len(results) == 1
        assert results[0]["id"] == coll.id
        assert results[0]["hit_count"] == 2

        SearchIndex.reset(coll.id)

        results = SearchIndex.find(["test", "root"], user)
        assert len(results) == 0