server/test/unittest_ldapuser.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Sat, 09 Oct 2010 00:05:52 +0200
changeset 6427 c8a5ac2d1eaa
parent 6415 b0b0f097a72d
child 6435 71b2a3fe7ba1
permissions -rw-r--r--
[schema / sources] store data sources as cubicweb entities this implies several changes: * new CWSource / CWSourceHostConfig entity types * only the system sources and default admin login/password stored in sources file (other stuff will be ignored) * on startup, get sources definition from the database * every entities have a cw_source relation * a facet allow filtering
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
6415
b0b0f097a72d cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    18
"""cubicweb.server.sources.ldapusers unit and functional tests"""
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
3855
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
    20
import socket
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
    21
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
from logilab.common.testlib import TestCase, unittest_main, mock_object
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    23
from cubicweb.devtools.testlib import CubicWebTC
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
from cubicweb.devtools.repotest import RQLGeneratorTC
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
from cubicweb.server.sources.ldapuser import *
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
5029
f7709d28fb79 [test] fixes when executed under apycot environment (also added ldap1 to test host /etc/hosts)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4766
diff changeset
    28
if '17.1' in socket.gethostbyname('ldap1'):
3855
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
    29
    SYT = 'syt'
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
    30
    ADIM = 'adim'
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
    31
else:
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
    32
    SYT = 'sthenault'
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
    33
    ADIM = 'adimascio'
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
    34
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
    35
4089
ff92c7d692bf typos, api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
    36
def nopwd_authenticate(self, session, login, password):
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    37
    """used to monkey patch the source to get successful authentication without
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    38
    upassword checking
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    39
    """
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    40
    assert login, 'no login!'
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    41
    searchfilter = [filter_format('(%s=%s)', (self.user_login_attr, login))]
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    42
    searchfilter.extend([filter_format('(%s=%s)', ('objectClass', o))
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    43
                         for o in self.user_classes])
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    44
    searchstr = '(&%s)' % ''.join(searchfilter)
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
    # first search the user
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    46
    try:
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
        user = self._search(session, self.user_base_dn, self.user_base_scope,
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    48
                            searchstr)[0]
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
    except IndexError:
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    50
        # no such user
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    51
        raise AuthenticationError()
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    52
    # don't check upassword !
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
    53
    return self.extid2eid(user['dn'], 'CWUser', session)
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    54
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    55
def setup_module(*args):
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    56
    global repo
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    57
    LDAPUserSourceTC._init_repo()
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    58
    repo = LDAPUserSourceTC.repo
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    59
    add_ldap_source(LDAPUserSourceTC.cnx)
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    60
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    61
def teardown_module(*args):
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    62
    global repo
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    63
    repo.shutdown()
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    64
    del repo
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    65
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    66
def add_ldap_source(cnx):
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    67
    cnx.request().create_entity('CWSource', name=u'ldapuser', type=u'ldapuser',
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    68
                                config=u'''
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    69
# ldap host
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    70
host=ldap1
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    71
# base DN to lookup for usres
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    72
user-base-dn=ou=People,dc=logilab,dc=fr
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    73
# user search scope
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    74
user-scope=ONELEVEL
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    75
# classes of user
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    76
user-classes=top,posixAccount
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    77
# attribute used as login on authentication
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    78
user-login-attr=uid
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    79
# name of a group in which ldap users will be by default
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    80
user-default-group=users
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    81
# map from ldap user attributes to cubicweb attributes
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    82
user-attrs-map=gecos:email,uid:login
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    83
''')
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    84
    cnx.commit()
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    85
    # XXX: need this first query else we get 'database is locked' from
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    86
    # sqlite since it doesn't support multiple connections on the same
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    87
    # database
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    88
    # so doing, ldap inserted users don't get removed between each test
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    89
    rset = cnx.cursor().execute('CWUser X')
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    90
    # check we get some users from ldap
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
    91
    assert len(rset) > 1
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    92
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    93
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    94
class LDAPUserSourceTC(CubicWebTC):
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
    95
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    96
    def patch_authenticate(self):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    97
        self._orig_authenticate = LDAPUserSource.authenticate
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    98
        LDAPUserSource.authenticate = nopwd_authenticate
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    99
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   100
    def tearDown(self):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   101
        if hasattr(self, '_orig_authenticate'):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   102
            LDAPUserSource.authenticate = self._orig_authenticate
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   103
        CubicWebTC.tearDown(self)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   104
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   105
    def test_authenticate(self):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   106
        source = self.repo.sources_by_uri['ldapuser']
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   107
        self.session.set_pool()
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   108
        self.assertRaises(AuthenticationError,
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   109
                          source.authenticate, self.session, 'toto', 'toto')
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   110
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   111
    def test_synchronize(self):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   112
        source = self.repo.sources_by_uri['ldapuser']
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   113
        source.synchronize()
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   114
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   115
    def test_base(self):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   116
        # check a known one
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   117
        e = self.sexecute('CWUser X WHERE X login %(login)s', {'login': SYT}).get_entity(0, 0)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   118
        self.assertEqual(e.login, SYT)
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   119
        e.complete()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   120
        self.assertEqual(e.creation_date, None)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   121
        self.assertEqual(e.modification_date, None)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   122
        self.assertEqual(e.firstname, None)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   123
        self.assertEqual(e.surname, None)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   124
        self.assertEqual(e.in_group[0].name, 'users')
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   125
        self.assertEqual(e.owned_by[0].login, SYT)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   126
        self.assertEqual(e.created_by, ())
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   127
        self.assertEqual(e.primary_email[0].address, 'Sylvain Thenault')
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   128
        # email content should be indexed on the user
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   129
        rset = self.sexecute('CWUser X WHERE X has_text "thenault"')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   130
        self.assertEqual(rset.rows, [[e.eid]])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   131
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   132
    def test_not(self):
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   133
        eid = self.sexecute('CWUser X WHERE X login %(login)s', {'login': SYT})[0][0]
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   134
        rset = self.sexecute('CWUser X WHERE NOT X eid %s' % eid)
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   135
        self.assert_(rset)
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   136
        self.assert_(not eid in (r[0] for r in rset))
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   137
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   138
    def test_multiple(self):
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   139
        seid = self.sexecute('CWUser X WHERE X login %(login)s', {'login': SYT})[0][0]
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   140
        aeid = self.sexecute('CWUser X WHERE X login %(login)s', {'login': ADIM})[0][0]
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   141
        rset = self.sexecute('CWUser X, Y WHERE X login %(syt)s, Y login %(adim)s',
3855
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   142
                            {'syt': SYT, 'adim': ADIM})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   143
        self.assertEqual(rset.rows, [[seid, aeid]])
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   144
        rset = self.sexecute('Any X,Y,L WHERE X login L, X login %(syt)s, Y login %(adim)s',
3855
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   145
                            {'syt': SYT, 'adim': ADIM})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   146
        self.assertEqual(rset.rows, [[seid, aeid, SYT]])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   147
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   148
    def test_in(self):
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   149
        seid = self.sexecute('CWUser X WHERE X login %(login)s', {'login': SYT})[0][0]
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   150
        aeid = self.sexecute('CWUser X WHERE X login %(login)s', {'login': ADIM})[0][0]
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   151
        rset = self.sexecute('Any X,L ORDERBY L WHERE X login IN("%s", "%s"), X login L' % (SYT, ADIM))
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   152
        self.assertEqual(rset.rows, [[aeid, ADIM], [seid, SYT]])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   153
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   154
    def test_relations(self):
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   155
        eid = self.sexecute('CWUser X WHERE X login %(login)s', {'login': SYT})[0][0]
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   156
        rset = self.sexecute('Any X,E WHERE X is CWUser, X login L, X primary_email E')
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   157
        self.assert_(eid in (r[0] for r in rset))
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   158
        rset = self.sexecute('Any X,L,E WHERE X is CWUser, X login L, X primary_email E')
3855
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   159
        self.assert_(SYT in (r[1] for r in rset))
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   160
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   161
    def test_count(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   162
        nbusers = self.sexecute('Any COUNT(X) WHERE X is CWUser')[0][0]
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   163
        # just check this is a possible number
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   164
        self.assert_(nbusers > 1, nbusers)
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   165
        self.assert_(nbusers < 30, nbusers)
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   166
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   167
    def test_upper(self):
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   168
        eid = self.sexecute('CWUser X WHERE X login %(login)s', {'login': SYT})[0][0]
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   169
        rset = self.sexecute('Any UPPER(L) WHERE X eid %s, X login L' % eid)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   170
        self.assertEqual(rset[0][0], SYT.upper())
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   171
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   172
    def test_unknown_attr(self):
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   173
        eid = self.sexecute('CWUser X WHERE X login %(login)s', {'login': SYT})[0][0]
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   174
        rset = self.sexecute('Any L,C,M WHERE X eid %s, X login L, '
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   175
                            'X creation_date C, X modification_date M' % eid)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   176
        self.assertEqual(rset[0][0], SYT)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   177
        self.assertEqual(rset[0][1], None)
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   178
        self.assertEqual(rset[0][2], None)
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   179
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   180
    def test_sort(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   181
        logins = [l for l, in self.sexecute('Any L ORDERBY L WHERE X login L')]
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   182
        self.assertEqual(logins, sorted(logins))
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   183
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   184
    def test_lower_sort(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   185
        logins = [l for l, in self.sexecute('Any L ORDERBY lower(L) WHERE X login L')]
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   186
        self.assertEqual(logins, sorted(logins))
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   187
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   188
    def test_or(self):
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   189
        rset = self.sexecute('DISTINCT Any X WHERE X login %(login)s OR (X in_group G, G name "managers")',
3855
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   190
                            {'login': SYT})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   191
        self.assertEqual(len(rset), 2, rset.rows) # syt + admin
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   192
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   193
    def test_nonregr_set_owned_by(self):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   194
        # test that when a user coming from ldap is triggering a transition
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   195
        # the related TrInfo has correct owner information
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   196
        self.sexecute('SET X in_group G WHERE X login %(syt)s, G name "managers"', {'syt': SYT})
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   197
        self.commit()
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   198
        syt = self.sexecute('CWUser X WHERE X login %(login)s', {'login': SYT}).get_entity(0, 0)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   199
        self.assertEqual([g.name for g in syt.in_group], ['managers', 'users'])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   200
        self.patch_authenticate()
4089
ff92c7d692bf typos, api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
   201
        cnx = self.login(SYT, password='dummypassword')
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   202
        cu = cnx.cursor()
3855
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   203
        adim = cu.execute('CWUser X WHERE X login %(login)s', {'login': ADIM}).get_entity(0, 0)
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   204
        iworkflowable = adim.cw_adapt_to('IWorkflowable')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   205
        iworkflowable.fire_transition('deactivate')
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   206
        try:
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   207
            cnx.commit()
3855
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   208
            adim.clear_all_caches()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   209
            self.assertEqual(adim.in_state[0].name, 'deactivated')
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   210
            trinfo = iworkflowable.latest_trinfo()
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   211
            self.assertEqual(trinfo.owned_by[0].login, SYT)
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   212
            # select from_state to skip the user's creation TrInfo
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   213
            rset = self.sexecute('Any U ORDERBY D DESC WHERE WF wf_info_for X,'
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   214
                                'WF creation_date D, WF from_state FS,'
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   215
                                'WF owned_by U?, X eid %(x)s',
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5064
diff changeset
   216
                                {'x': adim.eid})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   217
            self.assertEqual(rset.rows, [[syt.eid]])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   218
        finally:
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   219
            # restore db state
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   220
            self.restore_connection()
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   221
            adim = self.sexecute('CWUser X WHERE X login %(login)s', {'login': ADIM}).get_entity(0, 0)
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   222
            adim.cw_adapt_to('IWorkflowable').fire_transition('activate')
4089
ff92c7d692bf typos, api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
   223
            self.sexecute('DELETE X in_group G WHERE X login %(syt)s, G name "managers"', {'syt': SYT})
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   224
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   225
    def test_same_column_names(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   226
        self.sexecute('Any X, Y WHERE X copain Y, X login "comme", Y login "cochon"')
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   227
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   228
    def test_multiple_entities_from_different_sources(self):
5064
494ae4ad4a14 [test] CubicWebTC.create_user expect an actual query, and we don't need to give session here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5029
diff changeset
   229
        self.create_user('cochon')
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   230
        self.failUnless(self.sexecute('Any X,Y WHERE X login %(syt)s, Y login "cochon"', {'syt': SYT}))
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   231
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   232
    def test_exists1(self):
4089
ff92c7d692bf typos, api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
   233
        self.session.set_pool()
ff92c7d692bf typos, api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
   234
        self.session.create_entity('CWGroup', name=u'bougloup1')
ff92c7d692bf typos, api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
   235
        self.session.create_entity('CWGroup', name=u'bougloup2')
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   236
        self.sexecute('SET U in_group G WHERE G name ~= "bougloup%", U login "admin"')
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   237
        self.sexecute('SET U in_group G WHERE G name = "bougloup1", U login %(syt)s', {'syt': SYT})
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   238
        rset = self.sexecute('Any L,SN ORDERBY L WHERE X in_state S, S name SN, X login L, EXISTS(X in_group G, G name ~= "bougloup%")')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   239
        self.assertEqual(rset.rows, [['admin', 'activated'], [SYT, 'activated']])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   240
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   241
    def test_exists2(self):
5064
494ae4ad4a14 [test] CubicWebTC.create_user expect an actual query, and we don't need to give session here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5029
diff changeset
   242
        self.create_user('comme')
494ae4ad4a14 [test] CubicWebTC.create_user expect an actual query, and we don't need to give session here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5029
diff changeset
   243
        self.create_user('cochon')
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   244
        self.sexecute('SET X copain Y WHERE X login "comme", Y login "cochon"')
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   245
        rset = self.sexecute('Any GN ORDERBY GN WHERE X in_group G, G name GN, (G name "managers" OR EXISTS(X copain T, T login in ("comme", "cochon")))')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   246
        self.assertEqual(rset.rows, [['managers'], ['users']])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   247
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   248
    def test_exists3(self):
5064
494ae4ad4a14 [test] CubicWebTC.create_user expect an actual query, and we don't need to give session here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5029
diff changeset
   249
        self.create_user('comme')
494ae4ad4a14 [test] CubicWebTC.create_user expect an actual query, and we don't need to give session here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5029
diff changeset
   250
        self.create_user('cochon')
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   251
        self.sexecute('SET X copain Y WHERE X login "comme", Y login "cochon"')
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   252
        self.failUnless(self.sexecute('Any X, Y WHERE X copain Y, X login "comme", Y login "cochon"'))
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   253
        self.sexecute('SET X copain Y WHERE X login %(syt)s, Y login "cochon"', {'syt': SYT})
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   254
        self.failUnless(self.sexecute('Any X, Y WHERE X copain Y, X login %(syt)s, Y login "cochon"', {'syt': SYT}))
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   255
        rset = self.sexecute('Any GN,L WHERE X in_group G, X login L, G name GN, G name "managers" OR EXISTS(X copain T, T login in ("comme", "cochon"))')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   256
        self.assertEqual(sorted(rset.rows), [['managers', 'admin'], ['users', 'comme'], ['users', SYT]])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   257
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   258
    def test_exists4(self):
5064
494ae4ad4a14 [test] CubicWebTC.create_user expect an actual query, and we don't need to give session here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5029
diff changeset
   259
        self.create_user('comme')
494ae4ad4a14 [test] CubicWebTC.create_user expect an actual query, and we don't need to give session here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5029
diff changeset
   260
        self.create_user('cochon', groups=('users', 'guests'))
494ae4ad4a14 [test] CubicWebTC.create_user expect an actual query, and we don't need to give session here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5029
diff changeset
   261
        self.create_user('billy')
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   262
        self.sexecute('SET X copain Y WHERE X login "comme", Y login "cochon"')
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   263
        self.sexecute('SET X copain Y WHERE X login "cochon", Y login "cochon"')
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   264
        self.sexecute('SET X copain Y WHERE X login "comme", Y login "billy"')
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   265
        self.sexecute('SET X copain Y WHERE X login %(syt)s, Y login "billy"', {'syt': SYT})
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   266
        # search for group name, login where
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   267
        #   CWUser copain with "comme" or "cochon" AND same login as the copain
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   268
        # OR
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   269
        #   CWUser in_state activated AND not copain with billy
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   270
        #
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   271
        # SO we expect everybody but "comme" and "syt"
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   272
        rset= self.sexecute('Any GN,L WHERE X in_group G, X login L, G name GN, '
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   273
                           'EXISTS(X copain T, T login L, T login in ("comme", "cochon")) OR '
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   274
                           'EXISTS(X in_state S, S name "activated", NOT X copain T2, T2 login "billy")')
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   275
        all = self.sexecute('Any GN, L WHERE X in_group G, X login L, G name GN')
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   276
        all.rows.remove(['users', 'comme'])
3855
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   277
        all.rows.remove(['users', SYT])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   278
        self.assertEqual(sorted(rset.rows), sorted(all.rows))
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   279
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   280
    def test_exists5(self):
5064
494ae4ad4a14 [test] CubicWebTC.create_user expect an actual query, and we don't need to give session here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5029
diff changeset
   281
        self.create_user('comme')
494ae4ad4a14 [test] CubicWebTC.create_user expect an actual query, and we don't need to give session here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5029
diff changeset
   282
        self.create_user('cochon', groups=('users', 'guests'))
494ae4ad4a14 [test] CubicWebTC.create_user expect an actual query, and we don't need to give session here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5029
diff changeset
   283
        self.create_user('billy')
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   284
        self.sexecute('SET X copain Y WHERE X login "comme", Y login "cochon"')
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   285
        self.sexecute('SET X copain Y WHERE X login "cochon", Y login "cochon"')
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   286
        self.sexecute('SET X copain Y WHERE X login "comme", Y login "billy"')
3890
d7a270f50f54 backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3589 3855
diff changeset
   287
        self.sexecute('SET X copain Y WHERE X login %(syt)s, Y login "cochon"', {'syt': SYT})
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   288
        rset= self.sexecute('Any L WHERE X login L, '
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   289
                           'EXISTS(X copain T, T login in ("comme", "cochon")) AND '
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   290
                           'NOT EXISTS(X copain T2, T2 login "billy")')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   291
        self.assertEqual(sorted(rset.rows), [['cochon'], [SYT]])
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   292
        rset= self.sexecute('Any GN,L WHERE X in_group G, X login L, G name GN, '
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   293
                           'EXISTS(X copain T, T login in ("comme", "cochon")) AND '
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   294
                           'NOT EXISTS(X copain T2, T2 login "billy")')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   295
        self.assertEqual(sorted(rset.rows), [['guests', 'cochon'],
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   296
                                              ['users', 'cochon'],
3855
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   297
                                              ['users', SYT]])
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   298
975
0928daea04e9 fix ldapsource w/ restriction on unsupported relation (return no results in that case)
sylvain.thenault@logilab.fr
parents: 360
diff changeset
   299
    def test_cd_restriction(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   300
        rset = self.sexecute('CWUser X WHERE X creation_date > "2009-02-01"')
3436
1e927f7ccb23 nicer test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   301
        # admin/anon but no ldap user since it doesn't support creation_date
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   302
        self.assertEqual(sorted(e.login for e in rset.entities()),
3436
1e927f7ccb23 nicer test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   303
                          ['admin', 'anon'])
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   304
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   305
    def test_union(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   306
        afeids = self.sexecute('State X')
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   307
        ueids = self.sexecute('CWUser X')
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   308
        rset = self.sexecute('(Any X WHERE X is State) UNION (Any X WHERE X is CWUser)')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   309
        self.assertEqual(sorted(r[0] for r in rset.rows),
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   310
                          sorted(r[0] for r in afeids + ueids))
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   311
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   312
    def _init_security_test(self):
5064
494ae4ad4a14 [test] CubicWebTC.create_user expect an actual query, and we don't need to give session here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5029
diff changeset
   313
        self.create_user('iaminguestsgrouponly', groups=('guests',))
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   314
        cnx = self.login('iaminguestsgrouponly')
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   315
        return cnx.cursor()
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   316
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   317
    def test_security1(self):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   318
        cu = self._init_security_test()
3855
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   319
        rset = cu.execute('CWUser X WHERE X login %(login)s', {'login': SYT})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   320
        self.assertEqual(rset.rows, [])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   321
        rset = cu.execute('Any X WHERE X login "iaminguestsgrouponly"')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   322
        self.assertEqual(len(rset.rows), 1)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   323
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   324
    def test_security2(self):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   325
        cu = self._init_security_test()
3855
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   326
        rset = cu.execute('Any X WHERE X has_text %(syt)s', {'syt': SYT})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   327
        self.assertEqual(rset.rows, [])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   328
        rset = cu.execute('Any X WHERE X has_text "iaminguestsgrouponly"')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   329
        self.assertEqual(len(rset.rows), 1)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   330
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   331
    def test_security3(self):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   332
        cu = self._init_security_test()
3855
dbd37c10f865 try to update ldap tests to make them work from the DMZ (eg using another ldap directory)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
   333
        rset = cu.execute('Any F WHERE X has_text %(syt)s, X firstname F', {'syt': SYT})
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   334
        self.assertEqual(rset.rows, [])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   335
        rset = cu.execute('Any F WHERE X has_text "iaminguestsgrouponly", X firstname F')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   336
        self.assertEqual(rset.rows, [[None]])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   337
1122
9f37de24251f fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents: 975
diff changeset
   338
    def test_nonregr1(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   339
        self.sexecute('Any X,AA ORDERBY AA DESC WHERE E eid %(x)s, E owned_by X, '
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   340
                     'X modification_date AA',
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   341
                     {'x': self.session.user.eid})
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   342
1122
9f37de24251f fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents: 975
diff changeset
   343
    def test_nonregr2(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   344
        self.sexecute('Any X,L,AA WHERE E eid %(x)s, E owned_by X, '
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   345
                     'X login L, X modification_date AA',
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   346
                     {'x': self.session.user.eid})
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   347
1122
9f37de24251f fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents: 975
diff changeset
   348
    def test_nonregr3(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   349
        self.sexecute('Any X,AA ORDERBY AA DESC WHERE E eid %(x)s, '
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   350
                     'X modification_date AA',
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   351
                     {'x': self.session.user.eid})
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   352
1122
9f37de24251f fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents: 975
diff changeset
   353
    def test_nonregr4(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   354
        emaileid = self.sexecute('INSERT EmailAddress X: X address "toto@logilab.org"')[0][0]
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   355
        self.sexecute('Any X,AA WHERE X use_email Y, Y eid %(x)s, X modification_date AA',
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   356
                     {'x': emaileid})
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   357
1122
9f37de24251f fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents: 975
diff changeset
   358
    def test_nonregr5(self):
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   359
        # original jpl query:
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   360
        # Any X, NOW - CD, P WHERE P is Project, U interested_in P, U is CWUser, U login "sthenault", X concerns P, X creation_date CD ORDERBY CD DESC LIMIT 5
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   361
        rql = 'Any X, NOW - CD, P ORDERBY CD DESC LIMIT 5 WHERE P bookmarked_by U, U login "%s", P is X, X creation_date CD' % self.session.user.login
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   362
        self.sexecute(rql, )#{'x': })
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   363
1122
9f37de24251f fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents: 975
diff changeset
   364
    def test_nonregr6(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   365
        self.sexecute('Any B,U,UL GROUPBY B,U,UL WHERE B created_by U?, B is File '
1122
9f37de24251f fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents: 975
diff changeset
   366
                     'WITH U,UL BEING (Any U,UL WHERE ME eid %(x)s, (EXISTS(U identity ME) '
9f37de24251f fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents: 975
diff changeset
   367
                     'OR (EXISTS(U in_group G, G name IN("managers", "staff")))) '
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   368
                     'OR (EXISTS(U in_group H, ME in_group H, NOT H name "users")), U login UL, U is CWUser)',
1122
9f37de24251f fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents: 975
diff changeset
   369
                     {'x': self.session.user.eid})
9f37de24251f fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents: 975
diff changeset
   370
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   371
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   372
class GlobTrFuncTC(TestCase):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   373
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   374
    def test_count(self):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   375
        trfunc = GlobTrFunc('count', 0)
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   376
        res = trfunc.apply([[1], [2], [3], [4]])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   377
        self.assertEqual(res, [[4]])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   378
        trfunc = GlobTrFunc('count', 1)
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   379
        res = trfunc.apply([[1, 2], [2, 4], [3, 6], [1, 5]])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   380
        self.assertEqual(res, [[1, 2], [2, 1], [3, 1]])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   381
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   382
    def test_sum(self):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   383
        trfunc = GlobTrFunc('sum', 0)
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   384
        res = trfunc.apply([[1], [2], [3], [4]])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   385
        self.assertEqual(res, [[10]])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   386
        trfunc = GlobTrFunc('sum', 1)
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   387
        res = trfunc.apply([[1, 2], [2, 4], [3, 6], [1, 5]])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   388
        self.assertEqual(res, [[1, 7], [2, 4], [3, 6]])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   389
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   390
    def test_min(self):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   391
        trfunc = GlobTrFunc('min', 0)
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   392
        res = trfunc.apply([[1], [2], [3], [4]])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   393
        self.assertEqual(res, [[1]])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   394
        trfunc = GlobTrFunc('min', 1)
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   395
        res = trfunc.apply([[1, 2], [2, 4], [3, 6], [1, 5]])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   396
        self.assertEqual(res, [[1, 2], [2, 4], [3, 6]])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   397
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   398
    def test_max(self):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   399
        trfunc = GlobTrFunc('max', 0)
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   400
        res = trfunc.apply([[1], [2], [3], [4]])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   401
        self.assertEqual(res, [[4]])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   402
        trfunc = GlobTrFunc('max', 1)
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   403
        res = trfunc.apply([[1, 2], [2, 4], [3, 6], [1, 5]])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   404
        self.assertEqual(res, [[1, 5], [2, 4], [3, 6]])
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   405
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   406
class RQL2LDAPFilterTC(RQLGeneratorTC):
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   407
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   408
    def setUp(self):
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
   409
        self.schema = repo.schema
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   410
        RQLGeneratorTC.setUp(self)
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   411
        ldapsource = repo.sources[-1]
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   412
        self.pool = repo._get_pool()
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   413
        session = mock_object(pool=self.pool)
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   414
        self.o = RQL2LDAPFilter(ldapsource, session)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   415
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   416
    def tearDown(self):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   417
        repo._free_pool(self.pool)
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   418
        RQLGeneratorTC.tearDown(self)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   419
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   420
    def test_base(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   421
        rqlst = self._prepare('CWUser X WHERE X login "toto"').children[0]
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   422
        self.assertEqual(self.o.generate(rqlst, 'X')[1],
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   423
                          '(&(objectClass=top)(objectClass=posixAccount)(uid=toto))')
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   424
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   425
    def test_kwargs(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   426
        rqlst = self._prepare('CWUser X WHERE X login %(x)s').children[0]
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   427
        self.o._args = {'x': "toto"}
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   428
        self.assertEqual(self.o.generate(rqlst, 'X')[1],
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   429
                          '(&(objectClass=top)(objectClass=posixAccount)(uid=toto))')
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   430
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   431
    def test_get_attr(self):
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   432
        rqlst = self._prepare('Any X WHERE E firstname X, E eid 12').children[0]
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   433
        self.assertRaises(UnknownEid, self.o.generate, rqlst, 'E')
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   434
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   435
360
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   436
if __name__ == '__main__':
600dd2fe8b40 backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   437
    unittest_main()