示例#1
0
    def test_enumerateRoles_no_criteria(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zrm = self._makeOne(id='no_crit').__of__(root)

        ID_LIST = ('foo', 'bar', 'baz', 'bam')

        for id in ID_LIST:

            zrm.addRole(id, 'Role %s' % id, 'This is role, %s' % id)

        info_list = zrm.enumerateRoles()

        self.assertEqual(len(info_list), len(ID_LIST))

        sorted = list(ID_LIST)
        sorted.sort()

        for i in range(len(sorted)):

            self.assertEqual(info_list[i]['id'], sorted[i])
            self.assertEqual(info_list[i]['pluginid'], 'no_crit')
            self.assertEqual(info_list[i]['properties_url'],
                             'no_crit/manage_roles?role_id=%s' % sorted[i])
            self.assertEqual(
                info_list[i]['members_url'],
                'no_crit/manage_roles?role_id=%s&assign=1' % sorted[i])
示例#2
0
    def test_enumerateGroups_multiple(self):
        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zrm = self._makeOne(id='partial').__of__(root)

        ID_LIST = ('foo', 'bar', 'baz', 'bam')

        for id in ID_LIST:
            zrm.addGroup(id, 'Group %s' % id, 'This is group, %s' % id)

        info_list = zrm.enumerateGroups(id=ID_LIST, exact_match=False)

        self.assertEqual(len(info_list), len(ID_LIST))

        for info in info_list:
            self.failUnless(info['id'] in ID_LIST)

        SUBSET = ID_LIST[:3]

        info_list = zrm.enumerateGroups(id=SUBSET, exact_match=False)

        self.assertEqual(len(info_list), len(SUBSET))

        for info in info_list:
            self.failUnless(info['id'] in SUBSET)
    def test_enumerateGroups_exact_one( self ):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        dpg = self._makeOne( 'enumerating' ).__of__( root )

        dpg.addGroup( 'everyone', 'python:True', 'Everyone', '', True )
        dpg.addGroup( 'noone', 'python:False', active=True )
        dpg.addGroup( 'hohum', 'nothing', active=True )

        info_list = dpg.enumerateGroups( id='noone', exact_match=True )

        self.assertEqual( len( info_list ), 1 )
        info = info_list[ 0 ]

        self.assertEqual( info[ 'id' ], 'noone' )
        self.assertEqual( info[ 'title' ], '' )
        self.assertEqual( info[ 'description' ], '' )
        self.assertEqual( info[ 'active' ], True )
        self.assertEqual( info[ 'predicate' ], 'python:False' )
        self.assertEqual( info[ 'pluginid' ], 'enumerating' )

        # Because teher is no proper REQUEST, the properties_url will be incorrect
        # It should normally be  '/enumerating/noone/manage_propertiesForm'
        # But it will be '//noone/manage_propertiesForm'
        URL = '//noone/manage_propertiesForm'
        self.assertEqual( info[ 'properties_url' ], URL )
        self.assertEqual( info[ 'members_url' ], URL )
    def test_enumerateRoles_multiple(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zrm = self._makeOne(id='partial').__of__(root)

        ID_LIST = ('foo', 'bar', 'baz', 'bam')

        for id in ID_LIST:

            zrm.addRole(id, 'Role %s' % id, 'This is role, %s' % id)

        info_list = zrm.enumerateRoles(id=ID_LIST)

        self.assertEqual(len(info_list), len(ID_LIST))

        for info in info_list:
            self.assertTrue(info['id'] in ID_LIST)

        SUBSET = ID_LIST[:3]

        info_list = zrm.enumerateRoles(id=SUBSET)

        self.assertEqual(len(info_list), len(SUBSET))

        for info in info_list:
            self.assertTrue(info['id'] in SUBSET)
    def test_assignRoleToPrincipal_user(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zrm = self._makeOne(id='assign_user').__of__(root)
        zrm.addRole('test1')
        zrm.addRole('test2')
        user = DummyUser('foo')

        roles = zrm.getRolesForPrincipal(user)
        self.assertEqual(len(roles), 0)

        zrm.assignRoleToPrincipal('test1', 'foo')

        roles = zrm.getRolesForPrincipal(user)
        self.assertEqual(len(roles), 1)
        self.assertTrue('test1' in roles)

        zrm.assignRoleToPrincipal('test2', 'foo')

        roles = zrm.getRolesForPrincipal(user)
        self.assertEqual(len(roles), 2)
        self.assertTrue('test1' in roles)
        self.assertTrue('test2' in roles)
    def test_enumerateRoles_partial(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zrm = self._makeOne(id='partial').__of__(root)

        ID_LIST = ('foo', 'bar', 'baz', 'bam')

        for id in ID_LIST:

            zrm.addRole(id, 'Role %s' % id, 'This is role, %s' % id)

        info_list = zrm.enumerateRoles(id='ba', exact_match=False)

        self.assertEqual(len(info_list), len(ID_LIST) - 1)  # no 'foo'

        sorted = list(ID_LIST)
        sorted.sort()

        for i in range(len(sorted) - 1):

            self.assertEqual(info_list[i]['id'], sorted[i])
            self.assertEqual(info_list[i]['pluginid'], 'partial')
            self.assertEqual(info_list[i]['properties_url'],
                             'partial/manage_roles?role_id=%s' % sorted[i])
            self.assertEqual(
                info_list[i]['members_url'],
                'partial/manage_roles?role_id=%s&assign=1' % sorted[i])
            self.assertEqual(info_list[i]['title'], 'Role %s' % sorted[i])
            self.assertEqual(info_list[i]['description'],
                             'This is role, %s' % sorted[i])
    def test_enumerateRoles_exact(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zrm = self._makeOne(id='exact').__of__(root)

        ID_LIST = ('foo', 'bar', 'baz', 'bam')

        for id in ID_LIST:

            zrm.addRole(id, 'Role %s' % id, 'This is role, %s' % id)

        info_list = zrm.enumerateRoles(id='bar', exact_match=True)

        self.assertEqual(len(info_list), 1)
        info = info_list[0]

        self.assertEqual(info['id'], 'bar')
        self.assertEqual(info['pluginid'], 'exact')
        self.assertEqual(info['properties_url'],
                         'exact/manage_roles?role_id=bar')
        self.assertEqual(info['members_url'],
                         'exact/manage_roles?role_id=bar&assign=1')
        self.assertEqual(info['title'], 'Role bar')
        self.assertEqual(info['description'], 'This is role, bar')
示例#8
0
    def test_enumerateUsers_multiple_logins(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zum = self._makeOne(id='partial').__of__(root)

        ID_LIST = ('foo', 'bar', 'baz', 'bam')
        LOGIN_LIST = ['*****@*****.**' % x for x in ID_LIST]

        for i in range(len(ID_LIST)):

            zum.addUser(ID_LIST[i], LOGIN_LIST[i], 'password')

        info_list = zum.enumerateUsers(login=LOGIN_LIST)

        self.assertEqual(len(info_list), len(LOGIN_LIST))

        for info in info_list:
            self.failUnless(info['id'] in ID_LIST)
            self.failUnless(info['login'] in LOGIN_LIST)

        SUBSET_LOGINS = LOGIN_LIST[:3]
        SUBSET_IDS = ID_LIST[:3]

        info_list = zum.enumerateUsers(login=SUBSET_LOGINS)

        self.assertEqual(len(info_list), len(SUBSET_LOGINS))

        for info in info_list:
            self.failUnless(info['id'] in SUBSET_IDS)
            self.failUnless(info['login'] in SUBSET_LOGINS)
示例#9
0
    def test_enumerateUsers_multiple_ids(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zum = self._makeOne(id='partial').__of__(root)

        ID_LIST = ('foo', 'bar', 'baz', 'bam')

        for id in ID_LIST:

            zum.addUser(id, '*****@*****.**' % id, 'password')

        info_list = zum.enumerateUsers(id=ID_LIST)

        self.assertEqual(len(info_list), len(ID_LIST))

        for info in info_list:
            self.failUnless(info['id'] in ID_LIST)

        SUBSET = ID_LIST[:3]

        info_list = zum.enumerateUsers(id=SUBSET)

        self.assertEqual(len(info_list), len(SUBSET))

        for info in info_list:
            self.failUnless(info['id'] in SUBSET)
示例#10
0
    def test_enumerateUsers_no_criteria(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zum = self._makeOne(id='no_crit').__of__(root)

        ID_LIST = ('foo', 'bar', 'baz', 'bam')

        for id in ID_LIST:

            zum.addUser(id, '*****@*****.**' % id, 'password')

        info_list = zum.enumerateUsers()

        self.assertEqual(len(info_list), len(ID_LIST))

        sorted = list(ID_LIST)
        sorted.sort()

        for i in range(len(sorted)):

            self.assertEqual(info_list[i]['id'], sorted[i])
            self.assertEqual(info_list[i]['login'],
                             '*****@*****.**' % sorted[i])
            self.assertEqual(info_list[i]['pluginid'], 'no_crit')
            self.assertEqual(info_list[i]['editurl'],
                             'no_crit/manage_users?user_id=%s' % sorted[i])
示例#11
0
    def _makeTree(self):

        rc = FauxObject('rc')
        root = FauxRoot('root').__of__(rc)
        folder = FauxContainer('folder').__of__(root)
        object = FauxObject('object').__of__(folder)

        return rc, root, folder, object
示例#12
0
    def test_removeRoleFromPrincipal_nonesuch(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zrm = self._makeOne(id='remove_nonesuch').__of__(root)

        self.assertRaises(KeyError, zrm.removeRoleFromPrincipal, 'test', 'foo')
示例#13
0
    def test_updateRole_nonesuch(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zrm = self._makeOne(id='update_nonesuch').__of__(root)

        self.assertRaises(KeyError, zrm.updateRole, 'nonesuch', 'title',
                          'description')
    def test_enumerateGroups_exact_nonesuch(self):
        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zgm = self._makeOne(id='exact_nonesuch').__of__(root)

        ID_LIST = ('foo', 'bar', 'baz', 'bam')

        for id in ID_LIST:

            zgm.addGroup(id, 'Group %s' % id, 'This is group, %s' % id)

        self.assertEqual(zgm.enumerateGroups(id='qux', exact_match=True), ())
示例#15
0
    def test_enumerateUsers_exact_nonesuch(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zum = self._makeOne(id='exact_nonesuch').__of__(root)

        ID_LIST = ('foo', 'bar', 'baz', 'bam')

        for id in ID_LIST:

            zum.addUser(id, '*****@*****.**' % id, 'password')

        self.assertEquals(zum.enumerateUsers(id='qux', exact_match=True), ())
示例#16
0
    def test_enumerateUsers_unicode(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zum = self._makeOne(id='partial').__of__(root)

        ID_LIST = ('foo', 'bar', 'baz', 'bam')

        for id in ID_LIST:

            zum.addUser(id, '*****@*****.**' % id, 'password')

        info_list = zum.enumerateUsers(id=u'abc', exact_match=False)
        self.assertEqual(len(info_list), 0)
    def test_enumerateGroups_exact_miss(self):
        # See https://bugs.launchpad.net/zope-pas/+bug/585365

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        dpg = self._makeOne('enumerating').__of__(root)

        dpg.addGroup('everyone', 'python:True', 'Everyone', '', True)
        dpg.addGroup('noone', 'python:False', active=True)
        dpg.addGroup('hohum', 'nothing', active=True)

        info_list = dpg.enumerateGroups(id='nonesuch', exact_match=True)

        self.assertEqual(len(info_list), 0)
示例#18
0
    def test_removeRole_valid_id(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zrm = self._makeOne().__of__(root)

        zrm.addRole('roleid', 'Role', 'This is a role')
        zrm.addRole('doomed', 'Fatal', 'rust never sleeps')

        zrm.removeRole('doomed')

        role_ids = zrm.listRoleIds()
        self.assertEqual(len(role_ids), 1)
        self.assertEqual(len(zrm.enumerateRoles()), 1)
        self.assertEqual(role_ids[0], 'roleid')
示例#19
0
    def test_removeRole_then_addRole(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zrm = self._makeOne(id='remove_then_add').__of__(root)
        user = DummyUser('foo')

        zrm.addRole('test')
        zrm.assignRoleToPrincipal('test', 'foo')
        self.failUnless('test' in zrm.getRolesForPrincipal(user))

        zrm.removeRole('test')
        zrm.addRole('test')

        self.failIf('test' in zrm.getRolesForPrincipal(user))
示例#20
0
    def test_enumerateUsers_partial(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zum = self._makeOne(id='partial').__of__(root)

        ID_LIST = ('foo', 'bar', 'baz', 'bam')

        for id in ID_LIST:

            zum.addUser(id, '*****@*****.**' % id, 'password')

        info_list = zum.enumerateUsers(login='******', exact_match=False)

        self.assertEqual(len(info_list), len(ID_LIST))  # all match

        sorted = list(ID_LIST)
        sorted.sort()

        for i in range(len(sorted)):

            self.assertEqual(info_list[i]['id'], sorted[i])
            self.assertEqual(info_list[i]['login'],
                             '*****@*****.**' % sorted[i])
            self.assertEqual(info_list[i]['pluginid'], 'partial')
            self.assertEqual(info_list[i]['editurl'],
                             'partial/manage_users?user_id=%s' % sorted[i])

        info_list = zum.enumerateUsers(id='ba', exact_match=False)

        self.assertEqual(len(info_list), len(ID_LIST) - 1)  # no 'foo'

        sorted = list(ID_LIST)
        sorted.sort()

        for i in range(len(sorted) - 1):

            self.assertEqual(info_list[i]['id'], sorted[i])
            self.assertEqual(info_list[i]['login'],
                             '*****@*****.**' % sorted[i])
            self.assertEqual(info_list[i]['pluginid'], 'partial')
            self.assertEqual(info_list[i]['editurl'],
                             'partial/manage_users?user_id=%s' % sorted[i])
示例#21
0
    def test_addGroup( self ):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zgm = self._makeOne().__of__( root )

        zgm.addGroup( 'group' )

        group_ids = zgm.listGroupIds()
        self.assertEqual( len( group_ids ), 1 )
        self.assertEqual( group_ids[0], 'group' )

        info_list = zgm.enumerateGroups()
        self.assertEqual( len( info_list ), 1 )
        info = info_list[ 0 ]
        self.assertEqual( info[ 'id' ], 'group' )
示例#22
0
    def test_addRole(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zrm = self._makeOne().__of__(root)

        zrm.addRole('roleid', 'Role', 'This is a role')

        role_ids = zrm.listRoleIds()
        self.assertEqual(len(role_ids), 1)
        self.assertEqual(role_ids[0], 'roleid')

        info_list = zrm.enumerateRoles()
        self.assertEqual(len(info_list), 1)
        info = info_list[0]
        self.assertEqual(info['id'], 'roleid')
示例#23
0
    def test_updateRole_normal(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zrm = self._makeOne(id='update_normal').__of__(root)

        zrm.addRole('role', 'Original Title', 'Original description')

        info = zrm.getRoleInfo('role')
        self.assertEqual(info['id'], 'role')
        self.assertEqual(info['title'], 'Original Title')
        self.assertEqual(info['description'], 'Original description')

        zrm.updateRole('role', 'Updated Title', 'Updated description')

        info = zrm.getRoleInfo('role')
        self.assertEqual(info['id'], 'role')
        self.assertEqual(info['title'], 'Updated Title')
        self.assertEqual(info['description'], 'Updated description')
    def test_enumerateGroups_skip_inactive(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        dpg = self._makeOne('enumerating').__of__(root)

        dpg.addGroup('everyone', 'python:True', 'Everyone', '', True)
        dpg.addGroup('noone', 'python:False', active=True)
        dpg.addGroup('inactive', 'nothing', active=False)

        info_list = dpg.enumerateGroups()

        self.assertEqual(len(info_list), 2)

        ids = [x['id'] for x in info_list]

        self.assertTrue('everyone' in ids)
        self.assertTrue('noone' in ids)
        self.assertFalse('inactive' in ids)
    def test_enumerateGroups_prefixed(self):
        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zrm = self._makeOne(id='prefixed').__of__(root)
        zrm.prefix = 'prefixed_'

        ID_LIST = ('foo', 'bar', 'baz', 'bam')
        PRE_LIST = tuple(['prefixed_%s' % x for x in ID_LIST])

        for id in ID_LIST:

            zrm.addGroup(id, 'Group %s' % id, 'This is group, %s' % id)

        info_list = zrm.enumerateGroups()

        self.assertEqual(len(info_list), len(ID_LIST))

        for info in info_list:
            self.assertTrue(info['id'] in PRE_LIST)
    def test_enumerateGroups_exact_list(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        dpg = self._makeOne('enumerating').__of__(root)

        dpg.addGroup('everyone', 'python:True', 'Everyone', '', True)
        dpg.addGroup('noone', 'python:False', active=True)
        dpg.addGroup('hohum', 'nothing', active=True)

        ID_LIST = ('everyone', 'noone')

        info_list = dpg.enumerateGroups(id=ID_LIST, exact_match=True)

        self.assertEqual(len(info_list), len(ID_LIST))

        ids = [x['id'] for x in info_list]

        for id in ID_LIST:
            self.assertTrue(id in ids)
示例#27
0
    def test_enumerateUsers_exact(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        zum = self._makeOne(id='exact').__of__(root)

        ID_LIST = ('foo', 'bar', 'baz', 'bam')

        for id in ID_LIST:

            zum.addUser(id, '*****@*****.**' % id, 'password')

        info_list = zum.enumerateUsers(id='bar', exact_match=True)

        self.assertEqual(len(info_list), 1)
        info = info_list[0]

        self.assertEqual(info['id'], 'bar')
        self.assertEqual(info['login'], '*****@*****.**')
        self.assertEqual(info['pluginid'], 'exact')
        self.assertEqual(info['editurl'], 'exact/manage_users?user_id=bar')
示例#28
0
    def test_enumerateGroups_enumerating_with_optional_prefix(self):

        from Products.PluggableAuthService.tests.test_PluggableAuthService \
            import FauxRoot

        root = FauxRoot()
        dpg = self._makeOne('enumerating').__of__(root)
        dpg.prefix = 'enumerating_'

        dpg.addGroup('everyone', 'python:True', 'Everyone', '', True)
        dpg.addGroup('noone', 'python:False', active=True)
        dpg.addGroup('hohum', 'nothing', active=True)

        ID_LIST = ('enumerating_everyone', 'enumerating_noone',
                   'enumerating_hohum')

        info_list = dpg.enumerateGroups()

        self.assertEqual(len(info_list), len(ID_LIST))

        ids = [x['id'] for x in info_list]

        for id in ID_LIST:
            self.failUnless(id in ids)