Пример #1
0
    def test_groups_from_users(self):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Node
        from kotti.security import list_groups
        from kotti.security import set_groups

        self.make_bob()
        root = get_root()
        child = root[u'child'] = Node()
        DBSession.flush()

        self.assertEqual(list_groups('bob', root), ['group:bobsgroup'])

        set_groups('group:bobsgroup', root, ['role:editor'])
        set_groups('role:editor', child, ['group:foogroup'])

        self.assertEqual(
            set(list_groups('bob', root)),
            set(['group:bobsgroup', 'role:editor'])
            )
        self.assertEqual(
            set(list_groups('bob', child)),
            set(['group:bobsgroup', 'role:editor', 'group:foogroup'])
            )
Пример #2
0
    def test_apply(self, extra_principals, root):
        from kotti.security import list_groups
        from kotti.security import set_groups
        from kotti.views.users import share_node

        request = DummyRequest()

        request.params['apply'] = ''
        share_node(root, request)
        assert (request.session.pop_flash('info') == ['No changes were made.'])
        assert list_groups('bob', root) == []
        set_groups('bob', root, ['role:special'])

        request.params['role::bob::role:owner'] = '1'
        request.params['role::bob::role:editor'] = '1'
        request.params['orig-role::bob::role:owner'] = ''
        request.params['orig-role::bob::role:editor'] = ''

        share_node(root, request)
        assert (request.session.pop_flash('success') == [
            'Your changes have been saved.'
        ])
        assert (set(list_groups(
            'bob', root)) == {'role:owner', 'role:editor', 'role:special'})

        # We cannot set a role that's not displayed, even if we forged
        # the request:
        request.params['role::bob::role:admin'] = '1'
        request.params['orig-role::bob::role:admin'] = ''
        with raises(Forbidden):
            share_node(root, request)
        assert (set(list_groups(
            'bob', root)) == {'role:owner', 'role:editor', 'role:special'})
Пример #3
0
    def test_apply(self, extra_principals, root):
        from kotti.security import get_principals
        from kotti.security import list_groups
        from kotti.views.users import UsersManage

        request = DummyRequest()

        bob = get_principals()[u'bob']

        request.params['apply'] = u''
        UsersManage(root, request)()
        assert (request.session.pop_flash('info') == [u'No changes were made.'])
        assert list_groups('bob') == []
        bob.groups = [u'role:special']

        request.params['role::bob::role:owner'] = u'1'
        request.params['role::bob::role:editor'] = u'1'
        request.params['orig-role::bob::role:owner'] = u''
        request.params['orig-role::bob::role:editor'] = u''

        UsersManage(root, request)()
        assert (request.session.pop_flash('success') ==
                [u'Your changes have been saved.'])
        assert (
            set(list_groups('bob')) ==
            {'role:owner', 'role:editor', 'role:special'}
            )
Пример #4
0
    def test_apply(self):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import set_groups
        from kotti.views.users import share_node

        root = get_root()
        request = DummyRequest()
        self.add_some_principals()

        request.params['apply'] = u''
        share_node(root, request)
        self.assertEqual(request.session.pop_flash('info'),
                         [u'No changes made.'])
        self.assertEqual(list_groups('bob', root), [])
        set_groups('bob', root, ['role:special'])

        request.params['role::bob::role:owner'] = u'1'
        request.params['role::bob::role:editor'] = u'1'
        request.params['orig-role::bob::role:owner'] = u''
        request.params['orig-role::bob::role:editor'] = u''

        share_node(root, request)
        self.assertEqual(request.session.pop_flash('success'),
                         [u'Your changes have been saved.'])
        self.assertEqual(set(list_groups('bob', root)),
                         set(['role:owner', 'role:editor', 'role:special']))

        # We cannot set a role that's not displayed, even if we forged
        # the request:
        request.params['role::bob::role:admin'] = u'1'
        request.params['orig-role::bob::role:admin'] = u''
        self.assertRaises(Forbidden, share_node, root, request)
        self.assertEqual(set(list_groups('bob', root)),
                         set(['role:owner', 'role:editor', 'role:special']))
Пример #5
0
    def test_apply(self):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import set_groups
        from kotti.views.users import share_node

        root = get_root()
        request = DummyRequest()
        self.add_some_principals()

        request.params["apply"] = u""
        share_node(root, request)
        self.assertEqual(request.session.pop_flash("info"), [u"No changes made."])
        self.assertEqual(list_groups("bob", root), [])
        set_groups("bob", root, ["role:special"])

        request.params["role::bob::role:owner"] = u"1"
        request.params["role::bob::role:editor"] = u"1"
        request.params["orig-role::bob::role:owner"] = u""
        request.params["orig-role::bob::role:editor"] = u""

        share_node(root, request)
        self.assertEqual(request.session.pop_flash("success"), [u"Your changes have been saved."])
        self.assertEqual(set(list_groups("bob", root)), set(["role:owner", "role:editor", "role:special"]))

        # We cannot set a role that's not displayed, even if we forged
        # the request:
        request.params["role::bob::role:admin"] = u"1"
        request.params["orig-role::bob::role:admin"] = u""
        self.assertRaises(Forbidden, share_node, root, request)
        self.assertEqual(set(list_groups("bob", root)), set(["role:owner", "role:editor", "role:special"]))
Пример #6
0
    def test_inherit(self):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Node
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        root = get_root()
        child = root[u'child'] = Node()
        DBSession.flush()

        self.assertEqual(list_groups('bob', child), [])
        set_groups('bob', root, ['role:editor'])
        self.assertEqual(list_groups('bob', child), ['role:editor'])

        # Groups from the child are added:
        set_groups('bob', child, ['group:somegroup'])
        self.assertEqual(
            set(list_groups('bob', child)),
            set(['group:somegroup', 'role:editor'])
            )

        # We can ask to list only those groups that are defined locally:
        self.assertEqual(
            list_groups_raw(u'bob', child), set(['group:somegroup']))
Пример #7
0
    def test_apply(self):
        from kotti.views.users import share_node
        root = get_root()
        request = DummyRequest()
        self.add_some_principals()

        request.params['apply'] = u''
        share_node(root, request)
        self.assertEqual(
            request.session.pop_flash('notice'), [u'No changes made.'])
        self.assertEqual(list_groups('bob', root), [])
        set_groups('bob', root, ['role:special'])

        request.params['role::bob::role:owner'] = u'1'
        request.params['role::bob::role:editor'] = u'1'
        request.params['orig-role::bob::role:owner'] = u''
        request.params['orig-role::bob::role:editor'] = u''

        share_node(root, request)
        self.assertEqual(
            request.session.pop_flash('success'),
            [u'Your changes have been saved.'])
        self.assertEqual(
            set(list_groups('bob', root)),
            set(['role:owner', 'role:editor', 'role:special']))

        # We cannot set a role that's not displayed, even if we forged
        # the request:
        request.params['role::bob::role:admin'] = u'1'
        request.params['orig-role::bob::role:admin'] = u''
        self.assertRaises(Forbidden, share_node, root, request)
        self.assertEqual(
            set(list_groups('bob', root)),
            set(['role:owner', 'role:editor', 'role:special']))
Пример #8
0
    def test_apply(self):
        from kotti.resources import get_root
        from kotti.security import get_principals
        from kotti.security import list_groups
        from kotti.tests.test_node_views import TestNodeShare
        from kotti.views.users import users_manage

        root = get_root()
        request = DummyRequest()

        TestNodeShare.add_some_principals()
        bob = get_principals()[u'bob']

        request.params['apply'] = u''
        users_manage(root, request)
        self.assertEqual(request.session.pop_flash('info'),
                         [u'No changes made.'])
        self.assertEqual(list_groups('bob'), [])
        bob.groups = [u'role:special']

        request.params['role::bob::role:owner'] = u'1'
        request.params['role::bob::role:editor'] = u'1'
        request.params['orig-role::bob::role:owner'] = u''
        request.params['orig-role::bob::role:editor'] = u''

        users_manage(root, request)
        self.assertEqual(request.session.pop_flash('success'),
                         [u'Your changes have been saved.'])
        self.assertEqual(
            set(list_groups('bob')),
            set(['role:owner', 'role:editor', 'role:special'])
            )
Пример #9
0
    def test_apply(self):
        from kotti.resources import get_root
        from kotti.security import get_principals
        from kotti.security import list_groups
        from kotti.tests.test_node_views import TestNodeShare
        from kotti.views.users import users_manage

        root = get_root()
        request = DummyRequest()

        TestNodeShare.add_some_principals()
        bob = get_principals()[u'bob']

        request.params['apply'] = u''
        users_manage(root, request)
        self.assertEqual(request.session.pop_flash('info'),
                         [u'No changes made.'])
        self.assertEqual(list_groups('bob'), [])
        bob.groups = [u'role:special']

        request.params['role::bob::role:owner'] = u'1'
        request.params['role::bob::role:editor'] = u'1'
        request.params['orig-role::bob::role:owner'] = u''
        request.params['orig-role::bob::role:editor'] = u''

        users_manage(root, request)
        self.assertEqual(request.session.pop_flash('success'),
                         [u'Your changes have been saved.'])
        self.assertEqual(set(list_groups('bob')),
                         set(['role:owner', 'role:editor', 'role:special']))
Пример #10
0
    def test_apply(self, extra_principals, root):
        from kotti.security import get_principals
        from kotti.security import list_groups
        from kotti.views.users import UsersManage

        request = DummyRequest()

        bob = get_principals()['bob']

        request.params['apply'] = ''
        UsersManage(root, request)()
        assert (request.session.pop_flash('info') == ['No changes were made.'])
        assert list_groups('bob') == []
        bob.groups = ['role:special']

        request.params['role::bob::role:owner'] = '1'
        request.params['role::bob::role:editor'] = '1'
        request.params['orig-role::bob::role:owner'] = ''
        request.params['orig-role::bob::role:editor'] = ''

        UsersManage(root, request)()
        assert (request.session.pop_flash('success') == [
            'Your changes have been saved.'
        ])
        assert (set(list_groups('bob')) == {
            'role:owner', 'role:editor', 'role:special'
        })
Пример #11
0
    def test_apply(self, extra_principals):
        from kotti.resources import get_root
        from kotti.security import get_principals
        from kotti.security import list_groups
        from kotti.views.users import users_manage

        root = get_root()
        request = DummyRequest()

        bob = get_principals()[u'bob']

        request.params['apply'] = u''
        users_manage(root, request)
        assert (request.session.pop_flash('info') == [u'No changes made.'])
        assert list_groups('bob') == []
        bob.groups = [u'role:special']

        request.params['role::bob::role:owner'] = u'1'
        request.params['role::bob::role:editor'] = u'1'
        request.params['orig-role::bob::role:owner'] = u''
        request.params['orig-role::bob::role:editor'] = u''

        users_manage(root, request)
        assert (request.session.pop_flash('success') ==
            [u'Your changes have been saved.'])
        assert (
            set(list_groups('bob')) ==
            set(['role:owner', 'role:editor', 'role:special'])
            )
Пример #12
0
    def test_apply(self, extra_principals, root):
        from kotti.security import list_groups
        from kotti.security import set_groups
        from kotti.views.users import share_node

        request = DummyRequest()

        request.params['apply'] = u''
        share_node(root, request)
        assert (request.session.pop_flash('info') == [
            u'No changes were made.'
        ])
        assert list_groups('bob', root) == []
        set_groups('bob', root, ['role:special'])

        request.params['role::bob::role:owner'] = u'1'
        request.params['role::bob::role:editor'] = u'1'
        request.params['orig-role::bob::role:owner'] = u''
        request.params['orig-role::bob::role:editor'] = u''

        share_node(root, request)
        assert (request.session.pop_flash('success') == [
            u'Your changes have been saved.'
        ])
        assert (set(list_groups(
            'bob', root)) == {'role:owner', 'role:editor', 'role:special'})

        # We cannot set a role that's not displayed, even if we forged
        # the request:
        request.params['role::bob::role:admin'] = u'1'
        request.params['orig-role::bob::role:admin'] = u''
        with raises(Forbidden):
            share_node(root, request)
        assert (set(list_groups(
            'bob', root)) == {'role:owner', 'role:editor', 'role:special'})
Пример #13
0
    def test_apply(self, extra_principals, root):
        from kotti.security import get_principals
        from kotti.security import list_groups
        from kotti.views.users import UsersManage

        request = DummyRequest()

        bob = get_principals()["bob"]

        request.params["apply"] = ""
        UsersManage(root, request)()
        assert request.session.pop_flash("info") == ["No changes were made."]
        assert list_groups("bob") == []
        bob.groups = ["role:special"]

        request.params["role::bob::role:owner"] = "1"
        request.params["role::bob::role:editor"] = "1"
        request.params["orig-role::bob::role:owner"] = ""
        request.params["orig-role::bob::role:editor"] = ""

        UsersManage(root, request)()
        assert request.session.pop_flash("success") == [
            "Your changes have been saved."
        ]
        assert set(list_groups("bob")) == {
            "role:owner", "role:editor", "role:special"
        }
Пример #14
0
 def test_simple(self):
     root = get_root()
     set_groups('bob', root, ['role:editor'])
     self.assertEqual(
         list_groups('bob', root), ['role:editor'])
     self.assertEqual(
         list_groups_raw('bob', root), ['role:editor'])
Пример #15
0
    def test_owner(self):
        session = DBSession()
        self.config.testing_securitypolicy(userid=u'bob')
        root = get_root()
        child = root[u'child'] = Content()
        session.flush()
        self.assertEqual(child.owner, u'bob')
        self.assertEqual(list_groups(u'bob', child), [u'role:owner'])

        clear_request_cache()
        # The event listener does not set the role again for subitems:
        grandchild = child[u'grandchild'] = Content()
        session.flush()
        self.assertEqual(grandchild.owner, u'bob')
        self.assertEqual(list_groups(u'bob', grandchild), [u'role:owner'])
        self.assertEqual(len(list_groups_raw(u'bob', grandchild)), 0)
Пример #16
0
    def test_overwrite_and_delete(self, db_session, root):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        set_groups('bob', root, ['role:editor'])
        assert list_groups('bob', root) == ['role:editor']
        assert list_groups_raw(u'bob', root) == {'role:editor'}

        set_groups('bob', root, ['role:admin'])
        assert list_groups('bob', root) == ['role:admin']
        assert list_groups_raw(u'bob', root) == {'role:admin'}

        set_groups('bob', root)
        assert list_groups('bob', root) == []
        assert get_root() is root
Пример #17
0
    def test_simple(self, db_session, root):
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        set_groups('bob', root, ['role:editor'])
        assert list_groups('bob', root) == ['role:editor']
        assert list_groups_raw(u'bob', root) == set(['role:editor'])
Пример #18
0
    def test_root_default(self):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import list_groups_raw

        root = get_root()
        self.assertEqual(list_groups('admin', root), ['role:admin'])
        self.assertEqual(list_groups_raw(u'admin', root), set([]))
Пример #19
0
    def test_root_default(self, db_session):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import list_groups_raw

        root = get_root()
        assert list_groups('admin', root) == ['role:admin']
        assert list_groups_raw(u'admin', root) == set([])
Пример #20
0
    def test_overwrite_and_delete(self, db_session, root):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        set_groups('bob', root, ['role:editor'])
        assert list_groups('bob', root) == ['role:editor']
        assert list_groups_raw(u'bob', root) == set(['role:editor'])

        set_groups('bob', root, ['role:admin'])
        assert list_groups('bob', root) == ['role:admin']
        assert list_groups_raw(u'bob', root) == set(['role:admin'])

        set_groups('bob', root)
        assert list_groups('bob', root) == []
        assert get_root() is root
Пример #21
0
    def test_root_default(self, db_session):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import list_groups_raw

        root = get_root()
        assert list_groups('admin', root) == ['role:admin']
        assert list_groups_raw(u'admin', root) == set([])
Пример #22
0
    def test_overwrite_and_delete(self, db_session, root):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        set_groups("bob", root, ["role:editor"])
        assert list_groups("bob", root) == ["role:editor"]
        assert list_groups_raw("bob", root) == {"role:editor"}

        set_groups("bob", root, ["role:admin"])
        assert list_groups("bob", root) == ["role:admin"]
        assert list_groups_raw("bob", root) == {"role:admin"}

        set_groups("bob", root)
        assert list_groups("bob", root) == []
        assert get_root() is root
Пример #23
0
    def test_simple(self, db_session, root):
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        set_groups("bob", root, ["role:editor"])
        assert list_groups("bob", root) == ["role:editor"]
        assert list_groups_raw("bob", root) == {"role:editor"}
Пример #24
0
    def test_root_default(self):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import list_groups_raw

        root = get_root()
        self.assertEqual(list_groups('admin', root), ['role:admin'])
        self.assertEqual(list_groups_raw(u'admin', root), set([]))
Пример #25
0
    def test_simple(self, db_session, root):
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        set_groups('bob', root, ['role:editor'])
        assert list_groups('bob', root) == ['role:editor']
        assert list_groups_raw(u'bob', root) == {'role:editor'}
Пример #26
0
    def test_inherit(self):
        session = DBSession()
        root = get_root()
        child = root[u'child'] = Node()
        session.flush()

        self.assertEqual(list_groups('bob', child), [])
        set_groups('bob', root, ['role:editor'])
        self.assertEqual(list_groups('bob', child), ['role:editor'])

        # Groups from the child are added:
        set_groups('bob', child, ['group:somegroup'])
        self.assertEqual(
            set(list_groups('bob', child)),
            set(['group:somegroup', 'role:editor']))

        # We can ask to list only those groups that are defined locally:
        self.assertEqual(list_groups_raw('bob', child), ['group:somegroup'])
Пример #27
0
    def test_overwrite_and_delete(self):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        root = get_root()
        set_groups('bob', root, ['role:editor'])
        self.assertEqual(list_groups('bob', root), ['role:editor'])
        self.assertEqual(list_groups_raw(u'bob', root), set(['role:editor']))

        set_groups('bob', root, ['role:admin'])
        self.assertEqual(list_groups('bob', root), ['role:admin'])
        self.assertEqual(list_groups_raw(u'bob', root), set(['role:admin']))

        set_groups('bob', root)
        self.assertEqual(list_groups('bob', root), [])
        self.assertTrue(get_root() is root)
Пример #28
0
    def test_groups_from_users(self, db_session, root):
        from kotti.resources import Node
        from kotti.security import list_groups
        from kotti.security import set_groups

        self.make_bob()
        child = root[u'child'] = Node()
        db_session.flush()

        assert list_groups('bob', root) == ['group:bobsgroup']

        set_groups('group:bobsgroup', root, ['role:editor'])
        set_groups('role:editor', child, ['group:foogroup'])

        assert (set(list_groups('bob', root)) == set(
            ['group:bobsgroup', 'role:editor']))
        assert (set(list_groups('bob', child)) == set(
            ['group:bobsgroup', 'role:editor', 'group:foogroup']))
Пример #29
0
    def test_groups_from_users(self, db_session, root):
        from kotti.resources import Node
        from kotti.security import list_groups
        from kotti.security import set_groups

        self.make_bob()
        child = root[u'child'] = Node()
        db_session.flush()

        assert list_groups('bob', root) == ['group:bobsgroup']

        set_groups('group:bobsgroup', root, ['role:editor'])
        set_groups('role:editor', child, ['group:foogroup'])

        assert (set(list_groups('bob', root)) ==
                set(['group:bobsgroup', 'role:editor']))
        assert (set(list_groups('bob', child)) ==
                set(['group:bobsgroup', 'role:editor', 'group:foogroup']))
Пример #30
0
    def test_simple(self, db_session):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        root = get_root()
        set_groups('bob', root, ['role:editor'])
        assert list_groups('bob', root) == ['role:editor']
        assert list_groups_raw(u'bob', root) == set(['role:editor'])
Пример #31
0
    def test_simple(self, db_session):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        root = get_root()
        set_groups('bob', root, ['role:editor'])
        assert list_groups('bob', root) == ['role:editor']
        assert list_groups_raw(u'bob', root) == set(['role:editor'])
Пример #32
0
    def test_simple(self):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        root = get_root()
        set_groups('bob', root, ['role:editor'])
        self.assertEqual(list_groups('bob', root), ['role:editor'])
        self.assertEqual(list_groups_raw(u'bob', root), set(['role:editor']))
Пример #33
0
    def test_groups_from_users(self):
        self.make_bob()

        session = DBSession()
        root = get_root()
        child = root[u'child'] = Node()
        session.flush()

        self.assertEqual(list_groups('bob', root), ['group:bobsgroup'])

        set_groups('group:bobsgroup', root, ['role:editor'])
        set_groups('role:editor', child, ['group:foogroup'])

        self.assertEqual(
            set(list_groups('bob', root)),
            set(['group:bobsgroup', 'role:editor']))
        self.assertEqual(
            set(list_groups('bob', child)),
            set(['group:bobsgroup', 'role:editor', 'group:foogroup']))
Пример #34
0
    def test_inherit(self, db_session, root):
        from kotti.resources import Node
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        child = root["child"] = Node()
        db_session.flush()

        assert list_groups("bob", child) == []
        set_groups("bob", root, ["role:editor"])
        assert list_groups("bob", child) == ["role:editor"]

        # Groups from the child are added:
        set_groups("bob", child, ["group:somegroup"])
        assert set(list_groups("bob", child)) == {"group:somegroup", "role:editor"}

        # We can ask to list only those groups that are defined locally:
        assert list_groups_raw("bob", child) == {"group:somegroup"}
Пример #35
0
    def test_owner(self, root, db_session, events, dummy_request):
        from kotti.resources import Content
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.util import clear_cache

        child = root['child'] = Content()
        db_session.flush()
        assert child.owner == 'bob'
        assert list_groups('bob', child) == ['role:owner']

        clear_cache()

        # The event listener does not set the role again for subitems:
        grandchild = child['grandchild'] = Content()
        db_session.flush()
        assert grandchild.owner == 'bob'
        assert list_groups('bob', grandchild) == ['role:owner']
        assert len(list_groups_raw('bob', grandchild)) == 0
Пример #36
0
    def test_owner(self, root, db_session, events, dummy_request):
        from kotti.resources import Content
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.util import clear_cache

        child = root[u'child'] = Content()
        db_session.flush()
        assert child.owner == u'bob'
        assert list_groups(u'bob', child) == [u'role:owner']

        clear_cache()

        # The event listener does not set the role again for subitems:
        grandchild = child[u'grandchild'] = Content()
        db_session.flush()
        assert grandchild.owner == u'bob'
        assert list_groups(u'bob', grandchild) == [u'role:owner']
        assert len(list_groups_raw(u'bob', grandchild)) == 0
Пример #37
0
    def test_inherit(self, db_session, root):
        from kotti.resources import Node
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        child = root[u'child'] = Node()
        db_session.flush()

        assert list_groups('bob', child) == []
        set_groups('bob', root, ['role:editor'])
        assert list_groups('bob', child) == ['role:editor']

        # Groups from the child are added:
        set_groups('bob', child, ['group:somegroup'])
        assert (set(list_groups('bob',
                                child)) == {'group:somegroup', 'role:editor'})

        # We can ask to list only those groups that are defined locally:
        assert list_groups_raw(u'bob', child) == {'group:somegroup'}
Пример #38
0
    def test_groups_from_users(self, db_session, root):
        from kotti.resources import Node
        from kotti.security import list_groups
        from kotti.security import set_groups

        self.make_bob()
        child = root["child"] = Node()
        db_session.flush()

        assert list_groups("bob", root) == ["group:bobsgroup"]

        set_groups("group:bobsgroup", root, ["role:editor"])
        set_groups("role:editor", child, ["group:foogroup"])

        assert set(list_groups("bob", root)) == {"group:bobsgroup", "role:editor"}
        assert set(list_groups("bob", child)) == {
            "group:bobsgroup",
            "role:editor",
            "group:foogroup",
        }
Пример #39
0
def set_owner(event):
    obj, request = event.object, event.request
    if request is not None and isinstance(obj, Node) and obj.owner is None:
        userid = authenticated_userid(request)
        if userid is not None:
            # Set owner metadata:
            obj.owner = userid
            # Add owner role for userid if it's not inherited already:
            if u'role:owner' not in list_groups(userid, obj):
                groups = list_groups_raw(userid, obj) | set([u'role:owner'])
                set_groups(userid, obj, groups)
Пример #40
0
    def test_owner(self, root, db_session, events, dummy_request):
        from kotti.resources import Content
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.util import clear_cache

        with patch('kotti.events.authenticated_userid', return_value='bob'):
            child = root[u'child'] = Content()
            db_session.flush()
        assert child.owner == u'bob'
        assert list_groups(u'bob', child) == [u'role:owner']

        clear_cache()
        # The event listener does not set the role again for subitems:
        with patch('kotti.events.authenticated_userid', return_value='bob'):
            grandchild = child[u'grandchild'] = Content()
            db_session.flush()
        assert grandchild.owner == u'bob'
        assert list_groups(u'bob', grandchild) == [u'role:owner']
        assert len(list_groups_raw(u'bob', grandchild)) == 0
Пример #41
0
def set_owner(event):
    obj, request = event.object, event.request
    if request is not None and isinstance(obj, Node) and obj.owner is None:
        userid = authenticated_userid(request)
        if userid is not None:
            userid = unicode(userid)
            # Set owner metadata:
            obj.owner = userid
            # Add owner role for userid if it's not inherited already:
            if u'role:owner' not in list_groups(userid, obj):
                groups = list_groups_raw(userid, obj) | set([u'role:owner'])
                set_groups(userid, obj, groups)
Пример #42
0
    def test_simple(self):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        root = get_root()
        set_groups('bob', root, ['role:editor'])
        self.assertEqual(
            list_groups('bob', root), ['role:editor'])
        self.assertEqual(
            list_groups_raw(u'bob', root), set(['role:editor']))
Пример #43
0
    def test_inherit(self, db_session, root):
        from kotti.resources import Node
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        child = root[u'child'] = Node()
        db_session.flush()

        assert list_groups('bob', child) == []
        set_groups('bob', root, ['role:editor'])
        assert list_groups('bob', child) == ['role:editor']

        # Groups from the child are added:
        set_groups('bob', child, ['group:somegroup'])
        assert (
            set(list_groups('bob', child)) ==
            set(['group:somegroup', 'role:editor'])
            )

        # We can ask to list only those groups that are defined locally:
        assert list_groups_raw(u'bob', child) == set(['group:somegroup'])
Пример #44
0
    def test_groups_from_users(self):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Node
        from kotti.security import list_groups
        from kotti.security import set_groups

        self.make_bob()
        root = get_root()
        child = root[u'child'] = Node()
        DBSession.flush()

        self.assertEqual(list_groups('bob', root), ['group:bobsgroup'])

        set_groups('group:bobsgroup', root, ['role:editor'])
        set_groups('role:editor', child, ['group:foogroup'])

        self.assertEqual(set(list_groups('bob', root)),
                         set(['group:bobsgroup', 'role:editor']))
        self.assertEqual(
            set(list_groups('bob', child)),
            set(['group:bobsgroup', 'role:editor', 'group:foogroup']))
Пример #45
0
    def test_apply(self, extra_principals, root):
        from kotti.security import list_groups
        from kotti.security import set_groups
        from kotti.views.users import share_node

        request = DummyRequest()

        request.params["apply"] = ""
        request.params["csrf_token"] = request.session.get_csrf_token()
        share_node(root, request)
        assert request.session.pop_flash("info") == ["No changes were made."]
        assert list_groups("bob", root) == []
        set_groups("bob", root, ["role:special"])

        request.params["role::bob::role:owner"] = "1"
        request.params["role::bob::role:editor"] = "1"
        request.params["orig-role::bob::role:owner"] = ""
        request.params["orig-role::bob::role:editor"] = ""

        share_node(root, request)
        assert request.session.pop_flash("success") == ["Your changes have been saved."]
        assert set(list_groups("bob", root)) == {
            "role:owner",
            "role:editor",
            "role:special",
        }

        # We cannot set a role that's not displayed, even if we forged
        # the request:
        request.params["role::bob::role:admin"] = "1"
        request.params["orig-role::bob::role:admin"] = ""
        with raises(Forbidden):
            share_node(root, request)
        assert set(list_groups("bob", root)) == {
            "role:owner",
            "role:editor",
            "role:special",
        }
Пример #46
0
    def test_apply(self, extra_principals, root):
        from kotti.security import get_principals
        from kotti.security import list_groups
        from kotti.views.users import UsersManage

        request = DummyRequest()

        bob = get_principals()["bob"]

        request.params["apply"] = ""
        UsersManage(root, request)()
        assert request.session.pop_flash("info") == ["No changes were made."]
        assert list_groups("bob") == []
        bob.groups = ["role:special"]

        request.params["role::bob::role:owner"] = "1"
        request.params["role::bob::role:editor"] = "1"
        request.params["orig-role::bob::role:owner"] = ""
        request.params["orig-role::bob::role:editor"] = ""

        UsersManage(root, request)()
        assert request.session.pop_flash("success") == ["Your changes have been saved."]
        assert set(list_groups("bob")) == {"role:owner", "role:editor", "role:special"}
Пример #47
0
    def test_owner(self, get_current_request, authenticated_userid):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Content
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.util import clear_cache

        get_current_request.return_value = not None
        authenticated_userid.return_value = 'bob'
        root = get_root()
        child = root[u'child'] = Content()
        DBSession.flush()
        self.assertEqual(child.owner, u'bob')
        self.assertEqual(list_groups(u'bob', child), [u'role:owner'])

        clear_cache()
        # The event listener does not set the role again for subitems:
        grandchild = child[u'grandchild'] = Content()
        DBSession.flush()
        self.assertEqual(grandchild.owner, u'bob')
        self.assertEqual(list_groups(u'bob', grandchild), [u'role:owner'])
        self.assertEqual(len(list_groups_raw(u'bob', grandchild)), 0)
Пример #48
0
    def test_overwrite_and_delete(self):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        root = get_root()
        set_groups('bob', root, ['role:editor'])
        self.assertEqual(
            list_groups('bob', root), ['role:editor'])
        self.assertEqual(
            list_groups_raw(u'bob', root), set(['role:editor']))

        set_groups('bob', root, ['role:admin'])
        self.assertEqual(
            list_groups('bob', root), ['role:admin'])
        self.assertEqual(
            list_groups_raw(u'bob', root), set(['role:admin']))

        set_groups('bob', root)
        self.assertEqual(
            list_groups('bob', root), [])
        self.assertTrue(get_root() is root)
Пример #49
0
    def test_owner(self, get_current_request, authenticated_userid):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Content
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.util import clear_cache

        get_current_request.return_value = not None
        authenticated_userid.return_value = 'bob'
        root = get_root()
        child = root[u'child'] = Content()
        DBSession.flush()
        self.assertEqual(child.owner, u'bob')
        self.assertEqual(list_groups(u'bob', child), [u'role:owner'])

        clear_cache()
        # The event listener does not set the role again for subitems:
        grandchild = child[u'grandchild'] = Content()
        DBSession.flush()
        self.assertEqual(grandchild.owner, u'bob')
        self.assertEqual(list_groups(u'bob', grandchild), [u'role:owner'])
        self.assertEqual(len(list_groups_raw(u'bob', grandchild)), 0)
Пример #50
0
    def test_owner(self):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Content
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.util import clear_cache

        session = DBSession()
        self.config.testing_securitypolicy(userid='bob')
        root = get_root()
        child = root[u'child'] = Content()
        session.flush()
        self.assertEqual(child.owner, u'bob')
        self.assertEqual(list_groups(u'bob', child), [u'role:owner'])

        clear_cache()
        # The event listener does not set the role again for subitems:
        grandchild = child[u'grandchild'] = Content()
        session.flush()
        self.assertEqual(grandchild.owner, u'bob')
        self.assertEqual(list_groups(u'bob', grandchild), [u'role:owner'])
        self.assertEqual(len(list_groups_raw(u'bob', grandchild)), 0)
Пример #51
0
    def test_owner(self):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Content
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.util import clear_cache

        session = DBSession()
        self.config.testing_securitypolicy(userid='bob')
        root = get_root()
        child = root[u'child'] = Content()
        session.flush()
        self.assertEqual(child.owner, u'bob')
        self.assertEqual(list_groups(u'bob', child), [u'role:owner'])

        clear_cache()
        # The event listener does not set the role again for subitems:
        grandchild = child[u'grandchild'] = Content()
        session.flush()
        self.assertEqual(grandchild.owner, u'bob')
        self.assertEqual(list_groups(u'bob', grandchild), [u'role:owner'])
        self.assertEqual(len(list_groups_raw(u'bob', grandchild)), 0)
Пример #52
0
    def test_owner(self, db_session, events, dummy_request):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Content
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.util import clear_cache

        root = get_root()
        with patch('kotti.events.authenticated_userid', return_value='bob'):
            child = root[u'child'] = Content()
            DBSession.flush()
        assert child.owner == u'bob'
        assert list_groups(u'bob', child) == [u'role:owner']

        clear_cache()
        # The event listener does not set the role again for subitems:
        with patch('kotti.events.authenticated_userid', return_value='bob'):
            grandchild = child[u'grandchild'] = Content()
            DBSession.flush()
        assert grandchild.owner == u'bob'
        assert list_groups(u'bob', grandchild) == [u'role:owner']
        assert len(list_groups_raw(u'bob', grandchild)) == 0
Пример #53
0
    def test_nested_groups(self):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import list_groups_ext

        self.add_some_groups()
        root = get_root()
        child = root[u'child']
        grandchild = child[u'grandchild']

        # Check bob's groups on every level:
        self.assertEqual(list_groups('bob', root), ['group:bobsgroup'])
        self.assertEqual(
            set(list_groups('bob', child)),
            set(['group:bobsgroup', 'group:franksgroup', 'role:editor']))
        self.assertEqual(
            set(list_groups('bob', grandchild)),
            set([
                'group:bobsgroup', 'group:franksgroup', 'role:editor',
                'role:owner'
            ]))

        # Check group:franksgroup groups on every level:
        self.assertEqual(set(list_groups('frank', root)),
                         set(['group:franksgroup', 'role:editor']))
        self.assertEqual(set(list_groups('frank', child)),
                         set(['group:franksgroup', 'role:editor']))
        self.assertEqual(
            set(list_groups('frank', grandchild)),
            set([
                'group:franksgroup', 'role:editor', 'role:owner',
                'group:bobsgroup'
            ]))

        # Sometimes it's useful to know which of the groups were
        # inherited, that's what 'list_groups_ext' is for:
        groups, inherited = list_groups_ext('bob', root)
        self.assertEqual(groups, ['group:bobsgroup'])
        self.assertEqual(inherited, [])

        groups, inherited = list_groups_ext('bob', child)
        self.assertEqual(
            set(groups),
            set(['group:bobsgroup', 'group:franksgroup', 'role:editor']))
        self.assertEqual(
            set(inherited),
            set(['group:bobsgroup', 'group:franksgroup', 'role:editor']))

        groups, inherited = list_groups_ext('group:bobsgroup', child)
        self.assertEqual(set(groups), set(['group:franksgroup',
                                           'role:editor']))
        self.assertEqual(inherited, ['role:editor'])

        groups, inherited = list_groups_ext('group:franksgroup', grandchild)
        self.assertEqual(set(groups),
                         set(['group:bobsgroup', 'role:owner', 'role:editor']))
        self.assertEqual(inherited, ['role:editor'])
Пример #54
0
    def test_inherit(self):
        from kotti import DBSession
        from kotti.resources import get_root
        from kotti.resources import Node
        from kotti.security import list_groups
        from kotti.security import list_groups_raw
        from kotti.security import set_groups

        root = get_root()
        child = root[u'child'] = Node()
        DBSession.flush()

        self.assertEqual(list_groups('bob', child), [])
        set_groups('bob', root, ['role:editor'])
        self.assertEqual(list_groups('bob', child), ['role:editor'])

        # Groups from the child are added:
        set_groups('bob', child, ['group:somegroup'])
        self.assertEqual(set(list_groups('bob', child)),
                         set(['group:somegroup', 'role:editor']))

        # We can ask to list only those groups that are defined locally:
        self.assertEqual(list_groups_raw(u'bob', child),
                         set(['group:somegroup']))
Пример #55
0
    def test_nested_groups(self):
        self.add_some_groups()
        root = get_root()
        child = root[u'child']
        grandchild = child[u'grandchild']

        # Check bob's groups on every level:
        self.assertEqual(list_groups('bob', root), ['group:bobsgroup'])
        self.assertEqual(
            set(list_groups('bob', child)),
            set(['group:bobsgroup', 'group:franksgroup', 'role:editor']))
        self.assertEqual(
            set(list_groups('bob', grandchild)),
            set([
                'group:bobsgroup', 'group:franksgroup', 'role:editor',
                'role:owner'
            ]))

        # Check group:franksgroup groups on every level:
        self.assertEqual(
            set(list_groups('frank', root)),
            set(['group:franksgroup', 'role:editor']))
        self.assertEqual(
            set(list_groups('frank', child)),
            set(['group:franksgroup', 'role:editor']))
        self.assertEqual(
            set(list_groups('frank', grandchild)),
            set([
                'group:franksgroup', 'role:editor', 'role:owner',
                'group:bobsgroup'
            ]))

        # Sometimes it's useful to know which of the groups were
        # inherited, that's what 'list_groups_ext' is for:
        groups, inherited = list_groups_ext('bob', root)
        self.assertEqual(groups, ['group:bobsgroup'])
        self.assertEqual(inherited, [])

        groups, inherited = list_groups_ext('bob', child)
        self.assertEqual(
            set(groups),
            set(['group:bobsgroup', 'group:franksgroup', 'role:editor']))
        self.assertEqual(
            set(inherited),
            set(['group:bobsgroup', 'group:franksgroup', 'role:editor']))

        groups, inherited = list_groups_ext('group:bobsgroup', child)
        self.assertEqual(
            set(groups), set(['group:franksgroup', 'role:editor']))
        self.assertEqual(inherited, ['role:editor'])

        groups, inherited = list_groups_ext('group:franksgroup', grandchild)
        self.assertEqual(
            set(groups), set(['group:bobsgroup', 'role:owner', 'role:editor']))
        self.assertEqual(inherited, ['role:editor'])
Пример #56
0
    def test_nested_groups(self, db_session, root):
        from kotti.security import list_groups
        from kotti.security import list_groups_ext

        self.add_some_groups(db_session, root)
        child = root["child"]
        grandchild = child["grandchild"]

        # Check bob's groups on every level:
        assert list_groups("bob", root) == ["group:bobsgroup"]
        assert set(list_groups("bob", child)) == {
            "group:bobsgroup",
            "group:franksgroup",
            "role:editor",
        }
        assert set(list_groups("bob", grandchild)) == {
            "group:bobsgroup",
            "group:franksgroup",
            "role:editor",
            "role:owner",
        }

        # Check group:franksgroup groups on every level:
        assert set(list_groups("frank",
                               root)) == {"group:franksgroup", "role:editor"}
        assert set(list_groups("frank",
                               child)) == {"group:franksgroup", "role:editor"}
        assert set(list_groups("frank", grandchild)) == {
            "group:franksgroup",
            "role:editor",
            "role:owner",
            "group:bobsgroup",
        }

        # Sometimes it's useful to know which of the groups were
        # inherited, that's what 'list_groups_ext' is for:
        groups, inherited = list_groups_ext("bob", root)
        assert groups == ["group:bobsgroup"]
        assert inherited == []

        groups, inherited = list_groups_ext("bob", child)
        assert set(groups) == {
            "group:bobsgroup", "group:franksgroup", "role:editor"
        }
        assert set(inherited) == {
            "group:bobsgroup", "group:franksgroup", "role:editor"
        }

        groups, inherited = list_groups_ext("group:bobsgroup", child)
        assert set(groups) == {"group:franksgroup", "role:editor"}
        assert inherited == ["role:editor"]

        groups, inherited = list_groups_ext("group:franksgroup", grandchild)
        assert set(groups) == {"group:bobsgroup", "role:owner", "role:editor"}
        assert inherited == ["role:editor"]
Пример #57
0
def set_owner(event):
    """Set ``owner`` of the object that triggered the event.

    :param event: event that trigerred this handler.
    :type event: :class:`ObjectInsert`
    """

    obj, request = event.object, event.request
    if request is not None and isinstance(obj, Node) and obj.owner is None:
        userid = request.authenticated_userid
        if userid is not None:
            userid = unicode(userid)
            # Set owner metadata:
            obj.owner = userid
            # Add owner role for userid if it's not inherited already:
            if u'role:owner' not in list_groups(userid, obj):
                groups = list_groups_raw(userid, obj) | set([u'role:owner'])
                set_groups(userid, obj, groups)
Пример #58
0
def set_owner(event):
    """Set ``owner`` of the object that triggered the event.

    :param event: event that trigerred this handler.
    :type event: :class:`ObjectInsert`
    """

    obj, request = event.object, event.request
    if request is not None and isinstance(obj, Node) and obj.owner is None:
        userid = request.authenticated_userid
        if userid is not None:
            userid = unicode(userid)
            # Set owner metadata:
            obj.owner = userid
            # Add owner role for userid if it's not inherited already:
            if u'role:owner' not in list_groups(userid, obj):
                groups = list_groups_raw(userid, obj) | set([u'role:owner'])
                set_groups(userid, obj, groups)
Пример #59
0
    def test_nested_groups(self, db_session):
        from kotti.resources import get_root
        from kotti.security import list_groups
        from kotti.security import list_groups_ext

        self.add_some_groups()
        root = get_root()
        child = root[u'child']
        grandchild = child[u'grandchild']

        # Check bob's groups on every level:
        assert list_groups('bob', root) == ['group:bobsgroup']
        assert (set(list_groups('bob', child)) ==
            set(['group:bobsgroup', 'group:franksgroup', 'role:editor']))
        assert (set(list_groups('bob', grandchild)) ==
            set(['group:bobsgroup', 'group:franksgroup', 'role:editor',
                 'role:owner']))

        # Check group:franksgroup groups on every level:
        assert (set(list_groups('frank', root)) ==
            set(['group:franksgroup', 'role:editor']))
        assert (set(list_groups('frank', child)) ==
            set(['group:franksgroup', 'role:editor']))
        assert (set(list_groups('frank', grandchild)) ==
            set(['group:franksgroup', 'role:editor', 'role:owner',
                 'group:bobsgroup']))

        # Sometimes it's useful to know which of the groups were
        # inherited, that's what 'list_groups_ext' is for:
        groups, inherited = list_groups_ext('bob', root)
        assert groups == ['group:bobsgroup']
        assert inherited == []

        groups, inherited = list_groups_ext('bob', child)
        assert (set(groups) ==
            set(['group:bobsgroup', 'group:franksgroup', 'role:editor']))
        assert (set(inherited) ==
            set(['group:bobsgroup', 'group:franksgroup', 'role:editor']))

        groups, inherited = list_groups_ext('group:bobsgroup', child)
        assert set(groups) == set(['group:franksgroup', 'role:editor'])
        assert inherited == ['role:editor']

        groups, inherited = list_groups_ext('group:franksgroup', grandchild)
        assert (set(groups) ==
            set(['group:bobsgroup', 'role:owner', 'role:editor']))
        assert inherited == ['role:editor']