author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 11 Sep 2012 12:44:33 +0200 | |
changeset 8541 | 5b6bc27ece6e |
parent 8524 | d2a6163ce0d5 |
child 8634 | 22f1800ca6a9 |
permissions | -rw-r--r-- |
8188
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
1 |
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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
|
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/>. |
6434
d99b742a9c49
[test] fix ldap test when executed from certain hosts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
18 |
"""cubicweb.server.sources.ldapusers unit and functional tests""" |
8438
2c79c29193e7
[server/tests] fix tests
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8434
diff
changeset
|
19 |
from __future__ import with_statement |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
20 |
|
6887
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
21 |
import os |
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
22 |
import shutil |
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
23 |
import time |
8434
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
24 |
from os.path import join, exists |
6887
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
25 |
import subprocess |
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
|
26 |
|
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
27 |
from logilab.common.testlib import TestCase, unittest_main, mock_object, Tags |
8188
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
28 |
|
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
29 |
from cubicweb import AuthenticationError |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
30 |
from cubicweb.devtools.testlib import CubicWebTC |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
31 |
from cubicweb.devtools.repotest import RQLGeneratorTC |
6986
18343456ee49
[ldap test] use get_available_port from cw.devtools.httptest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6985
diff
changeset
|
32 |
from cubicweb.devtools.httptest import get_available_port |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
33 |
from cubicweb.devtools import get_test_db_handler |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
34 |
|
8434
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
35 |
from cubicweb.server.sources.ldapuser import GlobTrFunc, UnknownEid, RQL2LDAPFilter |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
36 |
|
8386
249b21722e5e
[ldapfeed, test] use default source config
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8385
diff
changeset
|
37 |
CONFIG = u'user-base-dn=ou=People,dc=cubicweb,dc=test' |
8188
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
38 |
URL = None |
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
|
39 |
|
8434
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
40 |
def create_slapd_configuration(cls): |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
41 |
global URL |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
42 |
config = cls.config |
6887
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
43 |
basedir = join(config.apphome, "ldapdb") |
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
44 |
slapdconf = join(config.apphome, "slapd.conf") |
6985
dda970c8a315
[test] generate slapd.conf to be cwd independant
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6888
diff
changeset
|
45 |
confin = file(join(config.apphome, "slapd.conf.in")).read() |
dda970c8a315
[test] generate slapd.conf to be cwd independant
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6888
diff
changeset
|
46 |
confstream = file(slapdconf, 'w') |
dda970c8a315
[test] generate slapd.conf to be cwd independant
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6888
diff
changeset
|
47 |
confstream.write(confin % {'apphome': config.apphome}) |
dda970c8a315
[test] generate slapd.conf to be cwd independant
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6888
diff
changeset
|
48 |
confstream.close() |
8430
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
49 |
if exists(basedir): |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
50 |
shutil.rmtree(basedir) |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
51 |
os.makedirs(basedir) |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
52 |
# fill ldap server with some data |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
53 |
ldiffile = join(config.apphome, "ldap_test.ldif") |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
54 |
config.info('Initing ldap database') |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
55 |
cmdline = "/usr/sbin/slapadd -f %s -l %s -c" % (slapdconf, ldiffile) |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
56 |
subprocess.call(cmdline, shell=True) |
6887
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
57 |
|
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
58 |
#ldapuri = 'ldapi://' + join(basedir, "ldapi").replace('/', '%2f') |
6986
18343456ee49
[ldap test] use get_available_port from cw.devtools.httptest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6985
diff
changeset
|
59 |
port = get_available_port(xrange(9000, 9100)) |
6887
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
60 |
host = 'localhost:%s' % port |
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
61 |
ldapuri = 'ldap://%s' % host |
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
62 |
cmdline = ["/usr/sbin/slapd", "-f", slapdconf, "-h", ldapuri, "-d", "0"] |
8430
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
63 |
config.info('Starting slapd:', ' '.join(cmdline)) |
8434
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
64 |
cls.slapd_process = subprocess.Popen(cmdline) |
6887
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
65 |
time.sleep(0.2) |
8434
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
66 |
if cls.slapd_process.poll() is None: |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
67 |
config.info('slapd started with pid %s' % cls.slapd_process.pid) |
6887
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
68 |
else: |
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
69 |
raise EnvironmentError('Cannot start slapd with cmdline="%s" (from directory "%s")' % |
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
70 |
(" ".join(cmdline), os.getcwd())) |
8188
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
71 |
URL = u'ldap://%s' % host |
6887
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
72 |
|
8434
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
73 |
def terminate_slapd(cls): |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
74 |
config = cls.config |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
75 |
if cls.slapd_process and cls.slapd_process.returncode is None: |
8430
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
76 |
config.info('terminating slapd') |
8434
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
77 |
if hasattr(cls.slapd_process, 'terminate'): |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
78 |
cls.slapd_process.terminate() |
6986
18343456ee49
[ldap test] use get_available_port from cw.devtools.httptest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6985
diff
changeset
|
79 |
else: |
18343456ee49
[ldap test] use get_available_port from cw.devtools.httptest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6985
diff
changeset
|
80 |
import os, signal |
8434
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
81 |
os.kill(cls.slapd_process.pid, signal.SIGTERM) |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
82 |
cls.slapd_process.wait() |
8430
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
83 |
config.info('DONE') |
8188
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
84 |
|
8430
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
85 |
class LDAPTestBase(CubicWebTC): |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
86 |
loglevel = 'ERROR' |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
87 |
|
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
88 |
@classmethod |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
89 |
def setUpClass(cls): |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
90 |
from cubicweb.cwctl import init_cmdline_log_threshold |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
91 |
init_cmdline_log_threshold(cls.config, cls.loglevel) |
8434
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
92 |
create_slapd_configuration(cls) |
8430
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
93 |
|
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
94 |
@classmethod |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
95 |
def tearDownClass(cls): |
8434
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
96 |
terminate_slapd(cls) |
8430
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
97 |
|
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
98 |
class DeleteStuffFromLDAPFeedSourceTC(LDAPTestBase): |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
99 |
test_db_id = 'ldap-feed' |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
100 |
|
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
101 |
@classmethod |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
102 |
def pre_setup_database(cls, session, config): |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
103 |
session.create_entity('CWSource', name=u'ldapuser', type=u'ldapfeed', parser=u'ldapfeed', |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
104 |
url=URL, config=CONFIG) |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
105 |
session.commit() |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
106 |
isession = session.repo.internal_session(safe=True) |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
107 |
lfsource = isession.repo.sources_by_uri['ldapuser'] |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
108 |
stats = lfsource.pull_data(isession, force=True, raise_on_error=True) |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
109 |
|
8434
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
110 |
def _pull(self): |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
111 |
with self.session.repo.internal_session() as isession: |
8478
e099ebc65e61
[ldap feed] fix error since with read security activated, password value is not selecteable (closes #2406597). Also add a note in the book about packages required to connect to an ldap server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8438
diff
changeset
|
112 |
lfsource = isession.repo.sources_by_uri['ldapuser'] |
e099ebc65e61
[ldap feed] fix error since with read security activated, password value is not selecteable (closes #2406597). Also add a note in the book about packages required to connect to an ldap server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8438
diff
changeset
|
113 |
stats = lfsource.pull_data(isession, force=True, raise_on_error=True) |
e099ebc65e61
[ldap feed] fix error since with read security activated, password value is not selecteable (closes #2406597). Also add a note in the book about packages required to connect to an ldap server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8438
diff
changeset
|
114 |
isession.commit() |
8434
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
115 |
|
8430
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
116 |
def test_delete(self): |
8434
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
117 |
""" delete syt, pull, check deactivation, repull, |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
118 |
readd syt, pull, check activation |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
119 |
""" |
8430
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
120 |
uri = self.repo.sources_by_uri['ldapuser'].urls[0] |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
121 |
deletecmd = ("ldapdelete -H %s 'uid=syt,ou=People,dc=cubicweb,dc=test' " |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
122 |
"-v -x -D cn=admin,dc=cubicweb,dc=test -w'cw'" % uri) |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
123 |
os.system(deletecmd) |
8434
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
124 |
self._pull() |
8430
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
125 |
self.assertRaises(AuthenticationError, self.repo.connect, 'syt', password='syt') |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
126 |
self.assertEqual(self.execute('Any N WHERE U login "syt", ' |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
127 |
'U in_state S, S name N').rows[0][0], |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
128 |
'deactivated') |
8434
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
129 |
# check that it doesn't choke |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
130 |
self._pull() |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
131 |
# reset the fscking ldap thing |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
132 |
self.tearDownClass() |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
133 |
self.setUpClass() |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
134 |
self._pull() |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
135 |
# still deactivated, but a warning has been emitted ... |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
136 |
self.assertEqual(self.execute('Any N WHERE U login "syt", ' |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
137 |
'U in_state S, S name N').rows[0][0], |
39c5bb4dcc59
[ldapfeed] do not crash on ldap user deletion + pull + already deactivated users, cleanups (closes #2392933)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8430
diff
changeset
|
138 |
'deactivated') |
8520
fcd048fa6e6d
[source/native] only system source users should be authenticated by the native source (closes #2465883)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8478
diff
changeset
|
139 |
# test reactivating the user isn't enough to authenticate, as the native source |
fcd048fa6e6d
[source/native] only system source users should be authenticated by the native source (closes #2465883)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8478
diff
changeset
|
140 |
# refuse to authenticate user from other sources |
8524
d2a6163ce0d5
fix ldapuser test
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8520
diff
changeset
|
141 |
os.system(deletecmd) |
d2a6163ce0d5
fix ldapuser test
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8520
diff
changeset
|
142 |
self._pull() |
8520
fcd048fa6e6d
[source/native] only system source users should be authenticated by the native source (closes #2465883)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8478
diff
changeset
|
143 |
user = self.execute('CWUser U WHERE U login "syt"').get_entity(0, 0) |
fcd048fa6e6d
[source/native] only system source users should be authenticated by the native source (closes #2465883)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8478
diff
changeset
|
144 |
user.cw_adapt_to('IWorkflowable').fire_transition('activate') |
fcd048fa6e6d
[source/native] only system source users should be authenticated by the native source (closes #2465883)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8478
diff
changeset
|
145 |
self.commit() |
fcd048fa6e6d
[source/native] only system source users should be authenticated by the native source (closes #2465883)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8478
diff
changeset
|
146 |
self.assertRaises(AuthenticationError, self.repo.connect, 'syt', password='syt') |
8430
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
147 |
|
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
148 |
class LDAPFeedSourceTC(LDAPTestBase): |
8188
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
149 |
test_db_id = 'ldap-feed' |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
150 |
|
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
151 |
@classmethod |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
152 |
def pre_setup_database(cls, session, config): |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
153 |
session.create_entity('CWSource', name=u'ldapuser', type=u'ldapfeed', parser=u'ldapfeed', |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
154 |
url=URL, config=CONFIG) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
155 |
session.commit() |
8385
5a261bac2962
[ldapfeed, test] use a safe internal session, as in real life
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8229
diff
changeset
|
156 |
isession = session.repo.internal_session(safe=True) |
8188
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
157 |
lfsource = isession.repo.sources_by_uri['ldapuser'] |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
158 |
stats = lfsource.pull_data(isession, force=True, raise_on_error=True) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
159 |
|
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
160 |
def setUp(self): |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
161 |
super(LDAPFeedSourceTC, self).setUp() |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
162 |
# ldap source url in the database may use a different port as the one |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
163 |
# just attributed |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
164 |
lfsource = self.repo.sources_by_uri['ldapuser'] |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
165 |
lfsource.urls = [URL] |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
166 |
|
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
167 |
def assertMetadata(self, entity): |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
168 |
self.assertTrue(entity.creation_date) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
169 |
self.assertTrue(entity.modification_date) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
170 |
|
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
171 |
def test_authenticate(self): |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
172 |
source = self.repo.sources_by_uri['ldapuser'] |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
173 |
self.session.set_cnxset() |
8229
b7bc631816f7
[ldapfeed] make authentication actually working
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8188
diff
changeset
|
174 |
# ensure we won't be logged against |
8188
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
175 |
self.assertRaises(AuthenticationError, |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
176 |
source.authenticate, self.session, 'toto', 'toto') |
8229
b7bc631816f7
[ldapfeed] make authentication actually working
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8188
diff
changeset
|
177 |
self.assertTrue(source.authenticate(self.session, 'syt', 'syt')) |
b7bc631816f7
[ldapfeed] make authentication actually working
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8188
diff
changeset
|
178 |
self.assertTrue(self.repo.connect('syt', password='syt')) |
8188
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
179 |
|
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
180 |
def test_base(self): |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
181 |
# check a known one |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
182 |
rset = self.sexecute('CWUser X WHERE X login %(login)s', {'login': 'syt'}) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
183 |
e = rset.get_entity(0, 0) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
184 |
self.assertEqual(e.login, 'syt') |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
185 |
e.complete() |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
186 |
self.assertMetadata(e) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
187 |
self.assertEqual(e.firstname, None) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
188 |
self.assertEqual(e.surname, None) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
189 |
self.assertEqual(e.in_group[0].name, 'users') |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
190 |
self.assertEqual(e.owned_by[0].login, 'syt') |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
191 |
self.assertEqual(e.created_by, ()) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
192 |
self.assertEqual(e.primary_email[0].address, 'Sylvain Thenault') |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
193 |
# email content should be indexed on the user |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
194 |
rset = self.sexecute('CWUser X WHERE X has_text "thenault"') |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
195 |
self.assertEqual(rset.rows, [[e.eid]]) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
196 |
|
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
197 |
def test_copy_to_system_source(self): |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
198 |
source = self.repo.sources_by_uri['ldapuser'] |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
199 |
eid = self.sexecute('CWUser X WHERE X login %(login)s', {'login': 'syt'})[0][0] |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
200 |
self.sexecute('SET X cw_source S WHERE X eid %(x)s, S name "system"', {'x': eid}) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
201 |
self.commit() |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
202 |
source.reset_caches() |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
203 |
rset = self.sexecute('CWUser X WHERE X login %(login)s', {'login': 'syt'}) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
204 |
self.assertEqual(len(rset), 1) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
205 |
e = rset.get_entity(0, 0) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
206 |
self.assertEqual(e.eid, eid) |
8430
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
207 |
self.assertEqual(e.cw_metainformation(), {'source': {'type': u'native', |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
208 |
'uri': u'system', |
5bee87a14bb1
fix ldap removal handling in ldapfeed (closes #2376625 and #2385133)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8387
diff
changeset
|
209 |
'use-cwuri-as-url': False}, |
8188
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
210 |
'type': 'CWUser', |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
211 |
'extid': None}) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
212 |
self.assertEqual(e.cw_source[0].name, 'system') |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
213 |
self.assertTrue(e.creation_date) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
214 |
self.assertTrue(e.modification_date) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
215 |
source.pull_data(self.session) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
216 |
rset = self.sexecute('CWUser X WHERE X login %(login)s', {'login': 'syt'}) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
217 |
self.assertEqual(len(rset), 1) |
8387
b59af20a868d
[ldap] we may actually get back password from ldap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8386
diff
changeset
|
218 |
# test some password has been set |
b59af20a868d
[ldap] we may actually get back password from ldap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8386
diff
changeset
|
219 |
cu = self.session.system_sql('SELECT cw_upassword FROM cw_CWUser WHERE cw_eid=%s' % rset[0][0]) |
b59af20a868d
[ldap] we may actually get back password from ldap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8386
diff
changeset
|
220 |
value = str(cu.fetchall()[0][0]) |
b59af20a868d
[ldap] we may actually get back password from ldap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8386
diff
changeset
|
221 |
self.assertEqual(value, '{SSHA}v/8xJQP3uoaTBZz1T7Y0B3qOxRN1cj7D') |
b59af20a868d
[ldap] we may actually get back password from ldap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8386
diff
changeset
|
222 |
self.assertTrue(self.repo.system_source.authenticate( |
b59af20a868d
[ldap] we may actually get back password from ldap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8386
diff
changeset
|
223 |
self.session, 'syt', password='syt')) |
8188
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
224 |
|
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
225 |
|
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
226 |
class LDAPUserSourceTC(LDAPFeedSourceTC): |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
227 |
test_db_id = 'ldap-user' |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
228 |
tags = CubicWebTC.tags | Tags(('ldap')) |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
229 |
|
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
230 |
@classmethod |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
231 |
def pre_setup_database(cls, session, config): |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
232 |
session.create_entity('CWSource', name=u'ldapuser', type=u'ldapuser', |
8188
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
233 |
url=URL, config=CONFIG) |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
234 |
session.commit() |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
235 |
# XXX keep it there |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
236 |
session.execute('CWUser U') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
237 |
|
8188
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
238 |
def assertMetadata(self, entity): |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
239 |
self.assertEqual(entity.creation_date, None) |
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
240 |
self.assertEqual(entity.modification_date, None) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
241 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
242 |
def test_synchronize(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
243 |
source = self.repo.sources_by_uri['ldapuser'] |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
244 |
source.synchronize() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
245 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
246 |
def test_base(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
247 |
# check a known one |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
248 |
rset = self.sexecute('CWUser X WHERE X login %(login)s', {'login': 'syt'}) |
6887
72d7feeb071e
[tests] make ldap source test run its own local (Open)LDAP server
David Douard <david.douard@logilab.fr>
parents:
6781
diff
changeset
|
249 |
e = rset.get_entity(0, 0) |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
250 |
self.assertEqual(e.login, 'syt') |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
251 |
e.complete() |
8188
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
252 |
self.assertMetadata(e) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
253 |
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
|
254 |
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
|
255 |
self.assertEqual(e.in_group[0].name, 'users') |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
256 |
self.assertEqual(e.owned_by[0].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
|
257 |
self.assertEqual(e.created_by, ()) |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
258 |
self.assertEqual(e.primary_email[0].address, 'Sylvain Thenault') |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
259 |
# 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
|
260 |
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
|
261 |
self.assertEqual(rset.rows, [[e.eid]]) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
262 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
263 |
def test_not(self): |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
264 |
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
|
265 |
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
|
266 |
self.assert_(rset) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
267 |
self.assert_(not eid in (r[0] for r in rset)) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
268 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
269 |
def test_multiple(self): |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
270 |
seid = self.sexecute('CWUser X WHERE X login %(login)s', {'login': 'syt'})[0][0] |
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
271 |
aeid = self.sexecute('CWUser X WHERE X login %(login)s', {'login': 'adim'})[0][0] |
3890
d7a270f50f54
backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
272 |
rset = self.sexecute('CWUser X, Y WHERE X login %(syt)s, Y login %(adim)s', |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
273 |
{'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
|
274 |
self.assertEqual(rset.rows, [[seid, aeid]]) |
3890
d7a270f50f54
backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
275 |
rset = self.sexecute('Any X,Y,L WHERE X login L, X login %(syt)s, Y login %(adim)s', |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
276 |
{'syt': 'syt', 'adim': 'adim'}) |
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
277 |
self.assertEqual(rset.rows, [[seid, aeid, 'syt']]) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
278 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
279 |
def test_in(self): |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
280 |
seid = self.sexecute('CWUser X WHERE X login %(login)s', {'login': 'syt'})[0][0] |
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
281 |
aeid = self.sexecute('CWUser X WHERE X login %(login)s', {'login': 'adim'})[0][0] |
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
282 |
rset = self.sexecute('Any X,L ORDERBY L WHERE X login IN("%s", "%s"), X login L' % ('syt', 'adim')) |
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
283 |
self.assertEqual(rset.rows, [[aeid, 'adim'], [seid, 'syt']]) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
284 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
285 |
def test_relations(self): |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
286 |
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
|
287 |
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
|
288 |
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
|
289 |
rset = self.sexecute('Any X,L,E WHERE X is CWUser, X login L, X primary_email E') |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
290 |
self.assert_('syt' in (r[1] for r in rset)) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
291 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
292 |
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
|
293 |
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
|
294 |
# just check this is a possible number |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
295 |
self.assert_(nbusers > 1, nbusers) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
296 |
self.assert_(nbusers < 30, nbusers) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
297 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
298 |
def test_upper(self): |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
299 |
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
|
300 |
rset = self.sexecute('Any UPPER(L) WHERE X eid %s, X login L' % eid) |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
301 |
self.assertEqual(rset[0][0], 'syt'.upper()) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
302 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
303 |
def test_unknown_attr(self): |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
304 |
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
|
305 |
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
|
306 |
'X creation_date C, X modification_date M' % eid) |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
307 |
self.assertEqual(rset[0][0], '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
|
308 |
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
|
309 |
self.assertEqual(rset[0][2], None) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
310 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
311 |
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
|
312 |
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
|
313 |
self.assertEqual(logins, sorted(logins)) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
314 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
315 |
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
|
316 |
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
|
317 |
self.assertEqual(logins, sorted(logins)) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
318 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
319 |
def test_or(self): |
3890
d7a270f50f54
backport stable branch (one more time painfully)
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
320 |
rset = self.sexecute('DISTINCT Any X WHERE X login %(login)s OR (X in_group G, G name "managers")', |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
321 |
{'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
|
322 |
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
|
323 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
324 |
def test_nonregr_set_owned_by(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
325 |
# 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
|
326 |
# the related TrInfo has correct owner information |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
327 |
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
|
328 |
self.commit() |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
329 |
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
|
330 |
self.assertEqual([g.name for g in syt.in_group], ['managers', 'users']) |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
331 |
cnx = self.login('syt', password='syt') |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
332 |
cu = cnx.cursor() |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
333 |
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
|
334 |
iworkflowable = adim.cw_adapt_to('IWorkflowable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
335 |
iworkflowable.fire_transition('deactivate') |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
336 |
try: |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
337 |
cnx.commit() |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7241
diff
changeset
|
338 |
adim.cw_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
|
339 |
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
|
340 |
trinfo = iworkflowable.latest_trinfo() |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
341 |
self.assertEqual(trinfo.owned_by[0].login, 'syt') |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
342 |
# 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
|
343 |
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
|
344 |
'WF creation_date D, WF from_state FS,' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
345 |
'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
|
346 |
{'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
|
347 |
self.assertEqual(rset.rows, [[syt.eid]]) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
348 |
finally: |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
349 |
# restore db state |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
350 |
self.restore_connection() |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
351 |
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
|
352 |
adim.cw_adapt_to('IWorkflowable').fire_transition('activate') |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
353 |
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
|
354 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
355 |
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
|
356 |
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
|
357 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
358 |
def test_multiple_entities_from_different_sources(self): |
7241
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
359 |
req = self.request() |
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
360 |
self.create_user(req, 'cochon') |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
361 |
self.assertTrue(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
|
362 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
363 |
def test_exists1(self): |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7293
diff
changeset
|
364 |
self.session.set_cnxset() |
4089
ff92c7d692bf
typos, api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
365 |
self.session.create_entity('CWGroup', name=u'bougloup1') |
ff92c7d692bf
typos, api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
366 |
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
|
367 |
self.sexecute('SET U in_group G WHERE G name ~= "bougloup%", U login "admin"') |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
368 |
self.sexecute('SET U in_group G WHERE G name = "bougloup1", U login %(syt)s', {'syt': 'syt'}) |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
369 |
rset = self.sexecute('Any L,SN ORDERBY L WHERE X in_state S, ' |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
370 |
'S name SN, X login L, EXISTS(X in_group G, G name ~= "bougloup%")') |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
371 |
self.assertEqual(rset.rows, [['admin', 'activated'], ['syt', 'activated']]) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
372 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
373 |
def test_exists2(self): |
7241
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
374 |
req = self.request() |
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
375 |
self.create_user(req, 'comme') |
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
376 |
self.create_user(req, '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
|
377 |
self.sexecute('SET X copain Y WHERE X login "comme", Y login "cochon"') |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
378 |
rset = self.sexecute('Any GN ORDERBY GN WHERE X in_group G, G name GN, ' |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
379 |
'(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
|
380 |
self.assertEqual(rset.rows, [['managers'], ['users']]) |
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_exists3(self): |
7241
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
383 |
req = self.request() |
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
384 |
self.create_user(req, 'comme') |
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
385 |
self.create_user(req, '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
|
386 |
self.sexecute('SET X copain Y WHERE X login "comme", Y login "cochon"') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7697
diff
changeset
|
387 |
self.assertTrue(self.sexecute('Any X, Y WHERE X copain Y, X login "comme", Y login "cochon"')) |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
388 |
self.sexecute('SET X copain Y WHERE X login %(syt)s, Y login "cochon"', {'syt': 'syt'}) |
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
389 |
self.assertTrue(self.sexecute('Any X, Y WHERE X copain Y, X login %(syt)s, Y login "cochon"', {'syt': 'syt'})) |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
390 |
rset = self.sexecute('Any GN,L WHERE X in_group G, X login L, G name GN, G name "managers" ' |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
391 |
'OR EXISTS(X copain T, T login in ("comme", "cochon"))') |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
392 |
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
|
393 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
394 |
def test_exists4(self): |
7241
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
395 |
req = self.request() |
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
396 |
self.create_user(req, 'comme') |
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
397 |
self.create_user(req, 'cochon', groups=('users', 'guests')) |
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
398 |
self.create_user(req, '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
|
399 |
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
|
400 |
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
|
401 |
self.sexecute('SET X copain Y WHERE X login "comme", Y login "billy"') |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
402 |
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
|
403 |
# 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
|
404 |
# 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
|
405 |
# OR |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
406 |
# CWUser in_state activated AND not copain with billy |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
407 |
# |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
408 |
# 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
|
409 |
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
|
410 |
'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
|
411 |
'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
|
412 |
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
|
413 |
all.rows.remove(['users', 'comme']) |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
414 |
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
|
415 |
self.assertEqual(sorted(rset.rows), sorted(all.rows)) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
416 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
417 |
def test_exists5(self): |
7241
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
418 |
req = self.request() |
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
419 |
self.create_user(req, 'comme') |
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
420 |
self.create_user(req, 'cochon', groups=('users', 'guests')) |
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
421 |
self.create_user(req, '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
|
422 |
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
|
423 |
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
|
424 |
self.sexecute('SET X copain Y WHERE X login "comme", Y login "billy"') |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
425 |
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
|
426 |
rset= self.sexecute('Any L WHERE X login L, ' |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
427 |
'EXISTS(X copain T, T login in ("comme", "cochon")) AND ' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
428 |
'NOT EXISTS(X copain T2, T2 login "billy")') |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
429 |
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
|
430 |
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
|
431 |
'EXISTS(X copain T, T login in ("comme", "cochon")) AND ' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
432 |
'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
|
433 |
self.assertEqual(sorted(rset.rows), [['guests', 'cochon'], |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
434 |
['users', 'cochon'], |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
435 |
['users', 'syt']]) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
436 |
|
975
0928daea04e9
fix ldapsource w/ restriction on unsupported relation (return no results in that case)
sylvain.thenault@logilab.fr
parents:
360
diff
changeset
|
437 |
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
|
438 |
rset = self.sexecute('CWUser X WHERE X creation_date > "2009-02-01"') |
3436 | 439 |
# 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
|
440 |
self.assertEqual(sorted(e.login for e in rset.entities()), |
3436 | 441 |
['admin', 'anon']) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
442 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
443 |
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
|
444 |
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
|
445 |
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
|
446 |
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
|
447 |
self.assertEqual(sorted(r[0] for r in rset.rows), |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
448 |
sorted(r[0] for r in afeids + ueids)) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
449 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
450 |
def _init_security_test(self): |
7241
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
451 |
req = self.request() |
65d65da31356
fix tests broken by fcb8932082a5
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7121
diff
changeset
|
452 |
self.create_user(req, 'iaminguestsgrouponly', groups=('guests',)) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
453 |
cnx = self.login('iaminguestsgrouponly') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
454 |
return cnx.cursor() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
455 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
456 |
def test_security1(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
457 |
cu = self._init_security_test() |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
458 |
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
|
459 |
self.assertEqual(rset.rows, []) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
460 |
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
|
461 |
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
|
462 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
463 |
def test_security2(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
464 |
cu = self._init_security_test() |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
465 |
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
|
466 |
self.assertEqual(rset.rows, []) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
467 |
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
|
468 |
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
|
469 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
470 |
def test_security3(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
471 |
cu = self._init_security_test() |
8146
67b9b273b70d
[ldap test] test actual ldap authentication instead of monkey-patching
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
472 |
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
|
473 |
self.assertEqual(rset.rows, []) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
474 |
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
|
475 |
self.assertEqual(rset.rows, [[None]]) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
476 |
|
1122
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
477 |
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
|
478 |
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
|
479 |
'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
|
480 |
{'x': self.session.user.eid}) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
481 |
|
1122
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
482 |
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
|
483 |
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
|
484 |
'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
|
485 |
{'x': self.session.user.eid}) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
486 |
|
1122
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
487 |
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
|
488 |
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
|
489 |
'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
|
490 |
{'x': self.session.user.eid}) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
491 |
|
1122
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
492 |
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
|
493 |
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
|
494 |
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
|
495 |
{'x': emaileid}) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
496 |
|
1122
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
497 |
def test_nonregr5(self): |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
498 |
# original jpl query: |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
499 |
# Any X, NOW - CD, P WHERE P is Project, U interested_in P, U is CWUser, |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
500 |
# U login "sthenault", X concerns P, X creation_date CD ORDERBY CD DESC LIMIT 5 |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
501 |
rql = ('Any X, NOW - CD, P ORDERBY CD DESC LIMIT 5 WHERE P bookmarked_by U, ' |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
502 |
'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
|
503 |
self.sexecute(rql, )#{'x': }) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
504 |
|
1122
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
505 |
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
|
506 |
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
|
507 |
'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
|
508 |
'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
|
509 |
'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
|
510 |
{'x': self.session.user.eid}) |
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
511 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
512 |
class GlobTrFuncTC(TestCase): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
513 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
514 |
def test_count(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
515 |
trfunc = GlobTrFunc('count', 0) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
516 |
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
|
517 |
self.assertEqual(res, [[4]]) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
518 |
trfunc = GlobTrFunc('count', 1) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
519 |
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
|
520 |
self.assertEqual(res, [[1, 2], [2, 1], [3, 1]]) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
521 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
522 |
def test_sum(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
523 |
trfunc = GlobTrFunc('sum', 0) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
524 |
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
|
525 |
self.assertEqual(res, [[10]]) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
526 |
trfunc = GlobTrFunc('sum', 1) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
527 |
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
|
528 |
self.assertEqual(res, [[1, 7], [2, 4], [3, 6]]) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
529 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
530 |
def test_min(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
531 |
trfunc = GlobTrFunc('min', 0) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
532 |
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
|
533 |
self.assertEqual(res, [[1]]) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
534 |
trfunc = GlobTrFunc('min', 1) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
535 |
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
|
536 |
self.assertEqual(res, [[1, 2], [2, 4], [3, 6]]) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
537 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
538 |
def test_max(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
539 |
trfunc = GlobTrFunc('max', 0) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
540 |
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
|
541 |
self.assertEqual(res, [[4]]) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
542 |
trfunc = GlobTrFunc('max', 1) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
543 |
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
|
544 |
self.assertEqual(res, [[1, 5], [2, 4], [3, 6]]) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
545 |
|
8188
1867e252e487
[repository] ldap-feed source. Closes #2086984
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8146
diff
changeset
|
546 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
547 |
class RQL2LDAPFilterTC(RQLGeneratorTC): |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
548 |
|
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
549 |
tags = RQLGeneratorTC.tags | Tags(('ldap')) |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
550 |
|
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
551 |
@property |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
552 |
def schema(self): |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
553 |
"""return the application schema""" |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
554 |
return self._schema |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
555 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
556 |
def setUp(self): |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
557 |
self.handler = get_test_db_handler(LDAPUserSourceTC.config) |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
558 |
self.handler.build_db_cache('ldap-user', LDAPUserSourceTC.pre_setup_database) |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
559 |
self.handler.restore_database('ldap-user') |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
560 |
self._repo = repo = self.handler.get_repo() |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
561 |
self._schema = repo.schema |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
562 |
super(RQL2LDAPFilterTC, self).setUp() |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
563 |
ldapsource = repo.sources[-1] |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7293
diff
changeset
|
564 |
self.cnxset = repo._get_cnxset() |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7293
diff
changeset
|
565 |
session = mock_object(cnxset=self.cnxset) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
566 |
self.o = RQL2LDAPFilter(ldapsource, session) |
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6888
diff
changeset
|
567 |
self.ldapclasses = ''.join(ldapsource.base_filters) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
568 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
569 |
def tearDown(self): |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
570 |
self._repo.turn_repo_off() |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6986
diff
changeset
|
571 |
super(RQL2LDAPFilterTC, self).tearDown() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
572 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
573 |
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
|
574 |
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
|
575 |
self.assertEqual(self.o.generate(rqlst, 'X')[1], |
6434
d99b742a9c49
[test] fix ldap test when executed from certain hosts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
576 |
'(&%s(uid=toto))' % self.ldapclasses) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
577 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
578 |
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
|
579 |
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
|
580 |
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
|
581 |
self.assertEqual(self.o.generate(rqlst, 'X')[1], |
6434
d99b742a9c49
[test] fix ldap test when executed from certain hosts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
582 |
'(&%s(uid=toto))' % self.ldapclasses) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
583 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
584 |
def test_get_attr(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
585 |
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
|
586 |
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
|
587 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
588 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
589 |
if __name__ == '__main__': |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
590 |
unittest_main() |