author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 22 Sep 2011 16:12:23 +0200 | |
changeset 7827 | 9bbf83f68bcc |
parent 7791 | 31bb51ea5485 |
child 8075 | f57ffbfe90fe |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5419
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5419
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:
5419
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:
5419
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:
5419
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:
5419
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:
5419
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:
5419
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:
5419
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:
5419
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:
5419
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:
5419
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:
5419
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:
5419
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:
5419
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:
5419
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5886 | 18 |
"""functional tests for server'security""" |
19 |
||
0 | 20 |
import sys |
21 |
||
22 |
from logilab.common.testlib import unittest_main, TestCase |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
23 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 24 |
|
6410
2e7a7b0829ed
[test] fix tests broken by transaction behaviour on Unauthorized/ValidationError (no rollback but connection marked as non-commitable)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
25 |
from cubicweb import Unauthorized, ValidationError, QueryError |
0 | 26 |
from cubicweb.server.querier import check_read_access |
27 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
28 |
class BaseSecurityTC(CubicWebTC): |
0 | 29 |
|
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
30 |
def setup_database(self): |
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
31 |
super(BaseSecurityTC, self).setup_database() |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7078
diff
changeset
|
32 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7078
diff
changeset
|
33 |
self.create_user(req, 'iaminusersgrouponly') |
7078
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7072
diff
changeset
|
34 |
readoriggroups = self.schema['Personne'].permissions['read'] |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7072
diff
changeset
|
35 |
addoriggroups = self.schema['Personne'].permissions['add'] |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7072
diff
changeset
|
36 |
def fix_perm(): |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7072
diff
changeset
|
37 |
self.schema['Personne'].set_action_permissions('read', readoriggroups) |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7072
diff
changeset
|
38 |
self.schema['Personne'].set_action_permissions('add', addoriggroups) |
bad26a22fe29
[test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7072
diff
changeset
|
39 |
self.addCleanup(fix_perm) |
0 | 40 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
41 |
|
0 | 42 |
class LowLevelSecurityFunctionTC(BaseSecurityTC): |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
43 |
|
0 | 44 |
def test_check_read_access(self): |
45 |
rql = u'Personne U where U nom "managers"' |
|
3252
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
46 |
rqlst = self.repo.vreg.rqlhelper.parse(rql).children[0] |
0 | 47 |
origgroups = self.schema['Personne'].get_groups('read') |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
48 |
self.schema['Personne'].set_action_permissions('read', ('users', 'managers')) |
4711
7ef3b029e10b
[test] we should properly use vreg method to compute solutions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
49 |
self.repo.vreg.solutions(self.session, rqlst, None) |
0 | 50 |
solution = rqlst.solutions[0] |
5419
0b7805928a27
[repo security] deal with rewriten constant nodes in check_read_access, necessary when repo is used as an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
51 |
check_read_access(self.session, rqlst, solution, {}) |
0 | 52 |
cnx = self.login('anon') |
53 |
cu = cnx.cursor() |
|
54 |
self.assertRaises(Unauthorized, |
|
55 |
check_read_access, |
|
5419
0b7805928a27
[repo security] deal with rewriten constant nodes in check_read_access, necessary when repo is used as an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
56 |
self.session, rqlst, solution, {}) |
0 | 57 |
self.assertRaises(Unauthorized, cu.execute, rql) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
58 |
|
0 | 59 |
def test_upassword_not_selectable(self): |
60 |
self.assertRaises(Unauthorized, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
61 |
self.execute, 'Any X,P WHERE X is CWUser, X upassword P') |
0 | 62 |
self.rollback() |
63 |
cnx = self.login('iaminusersgrouponly') |
|
64 |
cu = cnx.cursor() |
|
65 |
self.assertRaises(Unauthorized, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
66 |
cu.execute, 'Any X,P WHERE X is CWUser, X upassword P') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
67 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
68 |
|
5888
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
69 |
class SecurityRewritingTC(BaseSecurityTC): |
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
70 |
def hijack_source_execute(self): |
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
71 |
def syntax_tree_search(*args, **kwargs): |
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
72 |
self.query = (args, kwargs) |
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
73 |
return [] |
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
74 |
self.repo.system_source.syntax_tree_search = syntax_tree_search |
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
75 |
|
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
76 |
def tearDown(self): |
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
77 |
self.repo.system_source.__dict__.pop('syntax_tree_search', None) |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
78 |
super(SecurityRewritingTC, self).tearDown() |
5888
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
79 |
|
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
80 |
def test_not_relation_read_security(self): |
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
81 |
cnx = self.login('iaminusersgrouponly') |
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
82 |
self.hijack_source_execute() |
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
83 |
self.execute('Any U WHERE NOT A todo_by U, A is Affaire') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
84 |
self.assertEqual(self.query[0][1].as_string(), |
5888
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
85 |
'Any U WHERE NOT EXISTS(A todo_by U), A is Affaire') |
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
86 |
self.execute('Any U WHERE NOT EXISTS(A todo_by U), A is Affaire') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
87 |
self.assertEqual(self.query[0][1].as_string(), |
5888
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
88 |
'Any U WHERE NOT EXISTS(A todo_by U), A is Affaire') |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
89 |
cnx.close() |
5888
3ee80d487f11
[security] fix read rql expression insertion: we should not insert rql expr on variables only referenced in neged relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5886
diff
changeset
|
90 |
|
0 | 91 |
class SecurityTC(BaseSecurityTC): |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
92 |
|
0 | 93 |
def setUp(self): |
94 |
BaseSecurityTC.setUp(self) |
|
95 |
# implicitly test manager can add some entities |
|
96 |
self.execute("INSERT Affaire X: X sujet 'cool'") |
|
97 |
self.execute("INSERT Societe X: X nom 'logilab'") |
|
98 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
99 |
self.execute('INSERT CWGroup X: X name "staff"') |
0 | 100 |
self.commit() |
101 |
||
102 |
def test_insert_security(self): |
|
103 |
cnx = self.login('anon') |
|
104 |
cu = cnx.cursor() |
|
105 |
cu.execute("INSERT Personne X: X nom 'bidule'") |
|
106 |
self.assertRaises(Unauthorized, cnx.commit) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
107 |
self.assertEqual(cu.execute('Personne X').rowcount, 1) |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
108 |
cnx.close() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
109 |
|
0 | 110 |
def test_insert_rql_permission(self): |
111 |
# test user can only add une affaire related to a societe he owns |
|
112 |
cnx = self.login('iaminusersgrouponly') |
|
113 |
cu = cnx.cursor() |
|
114 |
cu.execute("INSERT Affaire X: X sujet 'cool'") |
|
115 |
self.assertRaises(Unauthorized, cnx.commit) |
|
116 |
# test nothing has actually been inserted |
|
117 |
self.restore_connection() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
118 |
self.assertEqual(self.execute('Affaire X').rowcount, 1) |
0 | 119 |
cnx = self.login('iaminusersgrouponly') |
120 |
cu = cnx.cursor() |
|
121 |
cu.execute("INSERT Affaire X: X sujet 'cool'") |
|
122 |
cu.execute("INSERT Societe X: X nom 'chouette'") |
|
123 |
cu.execute("SET A concerne S WHERE A sujet 'cool', S nom 'chouette'") |
|
124 |
cnx.commit() |
|
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
125 |
cnx.close() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
126 |
|
0 | 127 |
def test_update_security_1(self): |
128 |
cnx = self.login('anon') |
|
129 |
cu = cnx.cursor() |
|
130 |
# local security check |
|
131 |
cu.execute( "SET X nom 'bidulechouette' WHERE X is Personne") |
|
132 |
self.assertRaises(Unauthorized, cnx.commit) |
|
133 |
self.restore_connection() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
134 |
self.assertEqual(self.execute('Personne X WHERE X nom "bidulechouette"').rowcount, 0) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
135 |
|
0 | 136 |
def test_update_security_2(self): |
137 |
cnx = self.login('anon') |
|
138 |
cu = cnx.cursor() |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
139 |
self.repo.schema['Personne'].set_action_permissions('read', ('users', 'managers')) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
140 |
self.repo.schema['Personne'].set_action_permissions('add', ('guests', 'users', 'managers')) |
0 | 141 |
self.assertRaises(Unauthorized, cu.execute, "SET X nom 'bidulechouette' WHERE X is Personne") |
142 |
#self.assertRaises(Unauthorized, cnx.commit) |
|
143 |
# test nothing has actually been inserted |
|
144 |
self.restore_connection() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
145 |
self.assertEqual(self.execute('Personne X WHERE X nom "bidulechouette"').rowcount, 0) |
0 | 146 |
|
147 |
def test_update_security_3(self): |
|
148 |
cnx = self.login('iaminusersgrouponly') |
|
149 |
cu = cnx.cursor() |
|
150 |
cu.execute("INSERT Personne X: X nom 'biduuule'") |
|
151 |
cu.execute("INSERT Societe X: X nom 'looogilab'") |
|
152 |
cu.execute("SET X travaille S WHERE X nom 'biduuule', S nom 'looogilab'") |
|
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
153 |
cnx.close() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
154 |
|
0 | 155 |
def test_update_rql_permission(self): |
156 |
self.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
157 |
self.commit() |
|
158 |
# test user can only update une affaire related to a societe he owns |
|
159 |
cnx = self.login('iaminusersgrouponly') |
|
160 |
cu = cnx.cursor() |
|
161 |
cu.execute("SET X sujet 'pascool' WHERE X is Affaire") |
|
162 |
# this won't actually do anything since the selection query won't return anything |
|
163 |
cnx.commit() |
|
164 |
# to actually get Unauthorized exception, try to update an entity we can read |
|
165 |
cu.execute("SET X nom 'toto' WHERE X is Societe") |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
166 |
self.assertRaises(Unauthorized, cnx.commit) |
0 | 167 |
cu.execute("INSERT Affaire X: X sujet 'pascool'") |
168 |
cu.execute("INSERT Societe X: X nom 'chouette'") |
|
169 |
cu.execute("SET A concerne S WHERE A sujet 'pascool', S nom 'chouette'") |
|
170 |
cu.execute("SET X sujet 'habahsicestcool' WHERE X sujet 'pascool'") |
|
171 |
cnx.commit() |
|
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
172 |
cnx.close() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
173 |
|
0 | 174 |
def test_delete_security(self): |
175 |
# FIXME: sample below fails because we don't detect "owner" can't delete |
|
176 |
# user anyway, and since no user with login == 'bidule' exists, no |
|
177 |
# exception is raised |
|
178 |
#user._groups = {'guests':1} |
|
179 |
#self.assertRaises(Unauthorized, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
180 |
# self.o.execute, user, "DELETE CWUser X WHERE X login 'bidule'") |
0 | 181 |
# check local security |
182 |
cnx = self.login('iaminusersgrouponly') |
|
183 |
cu = cnx.cursor() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
184 |
self.assertRaises(Unauthorized, cu.execute, "DELETE CWGroup Y WHERE Y name 'staff'") |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
185 |
cnx.close() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
186 |
|
0 | 187 |
def test_delete_rql_permission(self): |
188 |
self.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
189 |
self.commit() |
|
190 |
# test user can only dele une affaire related to a societe he owns |
|
191 |
cnx = self.login('iaminusersgrouponly') |
|
192 |
cu = cnx.cursor() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
193 |
# this won't actually do anything since the selection query won't return anything |
0 | 194 |
cu.execute("DELETE Affaire X") |
195 |
cnx.commit() |
|
196 |
# to actually get Unauthorized exception, try to delete an entity we can read |
|
197 |
self.assertRaises(Unauthorized, cu.execute, "DELETE Societe S") |
|
6410
2e7a7b0829ed
[test] fix tests broken by transaction behaviour on Unauthorized/ValidationError (no rollback but connection marked as non-commitable)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
198 |
self.assertRaises(QueryError, cnx.commit) # can't commit anymore |
2e7a7b0829ed
[test] fix tests broken by transaction behaviour on Unauthorized/ValidationError (no rollback but connection marked as non-commitable)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
199 |
cnx.rollback() # required after Unauthorized |
0 | 200 |
cu.execute("INSERT Affaire X: X sujet 'pascool'") |
201 |
cu.execute("INSERT Societe X: X nom 'chouette'") |
|
202 |
cu.execute("SET A concerne S WHERE A sujet 'pascool', S nom 'chouette'") |
|
203 |
cnx.commit() |
|
204 |
## # this one should fail since it will try to delete two affaires, one authorized |
|
205 |
## # and the other not |
|
206 |
## self.assertRaises(Unauthorized, cu.execute, "DELETE Affaire X") |
|
207 |
cu.execute("DELETE Affaire X WHERE X sujet 'pascool'") |
|
208 |
cnx.commit() |
|
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
209 |
cnx.close() |
0 | 210 |
|
211 |
||
212 |
def test_insert_relation_rql_permission(self): |
|
213 |
cnx = self.login('iaminusersgrouponly') |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
214 |
session = self.session |
0 | 215 |
cu = cnx.cursor(session) |
216 |
cu.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
217 |
# should raise Unauthorized since user don't own S |
|
218 |
# though this won't actually do anything since the selection query won't return anything |
|
219 |
cnx.commit() |
|
220 |
# to actually get Unauthorized exception, try to insert a relation were we can read both entities |
|
221 |
rset = cu.execute('Personne P') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
222 |
self.assertEqual(len(rset), 1) |
0 | 223 |
ent = rset.get_entity(0, 0) |
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:
7244
diff
changeset
|
224 |
session.set_cnxset() # necessary |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
225 |
self.assertRaises(Unauthorized, ent.cw_check_perm, 'update') |
0 | 226 |
self.assertRaises(Unauthorized, |
227 |
cu.execute, "SET P travaille S WHERE P is Personne, S is Societe") |
|
6410
2e7a7b0829ed
[test] fix tests broken by transaction behaviour on Unauthorized/ValidationError (no rollback but connection marked as non-commitable)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
228 |
self.assertRaises(QueryError, cnx.commit) # can't commit anymore |
2e7a7b0829ed
[test] fix tests broken by transaction behaviour on Unauthorized/ValidationError (no rollback but connection marked as non-commitable)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
229 |
cnx.rollback() |
0 | 230 |
# test nothing has actually been inserted: |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
231 |
self.assertEqual(cu.execute('Any P,S WHERE P travaille S,P is Personne, S is Societe').rowcount, 0) |
0 | 232 |
cu.execute("INSERT Societe X: X nom 'chouette'") |
233 |
cu.execute("SET A concerne S WHERE A is Affaire, S nom 'chouette'") |
|
234 |
cnx.commit() |
|
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
235 |
cnx.close() |
0 | 236 |
|
237 |
def test_delete_relation_rql_permission(self): |
|
238 |
self.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
239 |
self.commit() |
|
240 |
cnx = self.login('iaminusersgrouponly') |
|
241 |
cu = cnx.cursor() |
|
242 |
# this won't actually do anything since the selection query won't return anything |
|
243 |
cu.execute("DELETE A concerne S") |
|
244 |
cnx.commit() |
|
245 |
# to actually get Unauthorized exception, try to delete a relation we can read |
|
246 |
self.restore_connection() |
|
247 |
eid = self.execute("INSERT Affaire X: X sujet 'pascool'")[0][0] |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
248 |
self.execute('SET X owned_by U WHERE X eid %(x)s, U login "iaminusersgrouponly"', {'x': eid}) |
0 | 249 |
self.execute("SET A concerne S WHERE A sujet 'pascool', S is Societe") |
250 |
self.commit() |
|
251 |
cnx = self.login('iaminusersgrouponly') |
|
252 |
cu = cnx.cursor() |
|
253 |
self.assertRaises(Unauthorized, cu.execute, "DELETE A concerne S") |
|
6410
2e7a7b0829ed
[test] fix tests broken by transaction behaviour on Unauthorized/ValidationError (no rollback but connection marked as non-commitable)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
254 |
self.assertRaises(QueryError, cnx.commit) # can't commit anymore |
2e7a7b0829ed
[test] fix tests broken by transaction behaviour on Unauthorized/ValidationError (no rollback but connection marked as non-commitable)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
255 |
cnx.rollback() # required after Unauthorized |
0 | 256 |
cu.execute("INSERT Societe X: X nom 'chouette'") |
257 |
cu.execute("SET A concerne S WHERE A is Affaire, S nom 'chouette'") |
|
258 |
cnx.commit() |
|
259 |
cu.execute("DELETE A concerne S WHERE S nom 'chouette'") |
|
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
260 |
cnx.close() |
0 | 261 |
|
262 |
||
263 |
def test_user_can_change_its_upassword(self): |
|
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7078
diff
changeset
|
264 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7078
diff
changeset
|
265 |
ueid = self.create_user(req, 'user').eid |
0 | 266 |
cnx = self.login('user') |
267 |
cu = cnx.cursor() |
|
268 |
cu.execute('SET X upassword %(passwd)s WHERE X eid %(x)s', |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
269 |
{'x': ueid, 'passwd': 'newpwd'}) |
0 | 270 |
cnx.commit() |
271 |
cnx.close() |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
272 |
cnx = self.login('user', password='newpwd') |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
273 |
cnx.close() |
0 | 274 |
|
275 |
def test_user_cant_change_other_upassword(self): |
|
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7078
diff
changeset
|
276 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7078
diff
changeset
|
277 |
ueid = self.create_user(req, 'otheruser').eid |
0 | 278 |
cnx = self.login('iaminusersgrouponly') |
279 |
cu = cnx.cursor() |
|
280 |
cu.execute('SET X upassword %(passwd)s WHERE X eid %(x)s', |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
281 |
{'x': ueid, 'passwd': 'newpwd'}) |
0 | 282 |
self.assertRaises(Unauthorized, cnx.commit) |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
283 |
cnx.close() |
0 | 284 |
|
285 |
# read security test |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
286 |
|
0 | 287 |
def test_read_base(self): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
288 |
self.schema['Personne'].set_action_permissions('read', ('users', 'managers')) |
0 | 289 |
cnx = self.login('anon') |
290 |
cu = cnx.cursor() |
|
291 |
self.assertRaises(Unauthorized, |
|
292 |
cu.execute, 'Personne U where U nom "managers"') |
|
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
293 |
cnx.close() |
0 | 294 |
|
321
247947250382
fix security bug w/ query using 'NOT X eid 123'
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
295 |
def test_read_erqlexpr_base(self): |
0 | 296 |
eid = self.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
297 |
self.commit() |
|
298 |
cnx = self.login('iaminusersgrouponly') |
|
299 |
cu = cnx.cursor() |
|
300 |
rset = cu.execute('Affaire X') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
301 |
self.assertEqual(rset.rows, []) |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
302 |
self.assertRaises(Unauthorized, cu.execute, 'Any X WHERE X eid %(x)s', {'x': eid}) |
321
247947250382
fix security bug w/ query using 'NOT X eid 123'
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
303 |
# cache test |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
304 |
self.assertRaises(Unauthorized, cu.execute, 'Any X WHERE X eid %(x)s', {'x': eid}) |
0 | 305 |
aff2 = cu.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
306 |
soc1 = cu.execute("INSERT Societe X: X nom 'chouette'")[0][0] |
|
307 |
cu.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
308 |
cnx.commit() |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
309 |
rset = cu.execute('Any X WHERE X eid %(x)s', {'x': aff2}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
310 |
self.assertEqual(rset.rows, [[aff2]]) |
321
247947250382
fix security bug w/ query using 'NOT X eid 123'
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
311 |
# more cache test w/ NOT eid |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
312 |
rset = cu.execute('Affaire X WHERE NOT X eid %(x)s', {'x': eid}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
313 |
self.assertEqual(rset.rows, [[aff2]]) |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
314 |
rset = cu.execute('Affaire X WHERE NOT X eid %(x)s', {'x': aff2}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
315 |
self.assertEqual(rset.rows, []) |
4765 | 316 |
# test can't update an attribute of an entity that can't be readen |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
317 |
self.assertRaises(Unauthorized, cu.execute, 'SET X sujet "hacked" WHERE X eid %(x)s', {'x': eid}) |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
318 |
cnx.close() |
4765 | 319 |
|
320 |
||
321 |
def test_entity_created_in_transaction(self): |
|
322 |
affschema = self.schema['Affaire'] |
|
323 |
origperms = affschema.permissions['read'] |
|
324 |
affschema.set_action_permissions('read', affschema.permissions['add']) |
|
325 |
try: |
|
326 |
cnx = self.login('iaminusersgrouponly') |
|
327 |
cu = cnx.cursor() |
|
328 |
aff2 = cu.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
|
329 |
# entity created in transaction are readable *by eid* |
|
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
330 |
self.assertTrue(cu.execute('Any X WHERE X eid %(x)s', {'x':aff2})) |
4765 | 331 |
# XXX would be nice if it worked |
332 |
rset = cu.execute("Affaire X WHERE X sujet 'cool'") |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
333 |
self.assertEqual(len(rset), 0) |
4765 | 334 |
finally: |
335 |
affschema.set_action_permissions('read', origperms) |
|
336 |
cnx.close() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
337 |
|
0 | 338 |
def test_read_erqlexpr_has_text1(self): |
339 |
aff1 = self.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
|
340 |
card1 = self.execute("INSERT Card X: X title 'cool'")[0][0] |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
341 |
self.execute('SET X owned_by U WHERE X eid %(x)s, U login "iaminusersgrouponly"', {'x': card1}) |
0 | 342 |
self.commit() |
343 |
cnx = self.login('iaminusersgrouponly') |
|
344 |
cu = cnx.cursor() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
345 |
aff2 = cu.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
0 | 346 |
soc1 = cu.execute("INSERT Societe X: X nom 'chouette'")[0][0] |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
347 |
cu.execute("SET A concerne S WHERE A eid %(a)s, S eid %(s)s", {'a': aff2, 's': soc1}) |
0 | 348 |
cnx.commit() |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
349 |
self.assertRaises(Unauthorized, cu.execute, 'Any X WHERE X eid %(x)s', {'x':aff1}) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
350 |
self.assertTrue(cu.execute('Any X WHERE X eid %(x)s', {'x':aff2})) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
351 |
self.assertTrue(cu.execute('Any X WHERE X eid %(x)s', {'x':card1})) |
0 | 352 |
rset = cu.execute("Any X WHERE X has_text 'cool'") |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
353 |
self.assertEqual(sorted(eid for eid, in rset.rows), |
0 | 354 |
[card1, aff2]) |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
355 |
cnx.close() |
0 | 356 |
|
357 |
def test_read_erqlexpr_has_text2(self): |
|
358 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
359 |
self.execute("INSERT Societe X: X nom 'bidule'") |
|
360 |
self.commit() |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
361 |
self.schema['Personne'].set_action_permissions('read', ('managers',)) |
0 | 362 |
cnx = self.login('iaminusersgrouponly') |
363 |
cu = cnx.cursor() |
|
364 |
rset = cu.execute('Any N WHERE N has_text "bidule"') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
365 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
0 | 366 |
rset = cu.execute('Any N WITH N BEING (Any N WHERE N has_text "bidule")') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
367 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
368 |
cnx.close() |
0 | 369 |
|
370 |
def test_read_erqlexpr_optional_rel(self): |
|
371 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
372 |
self.execute("INSERT Societe X: X nom 'bidule'") |
|
373 |
self.commit() |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
374 |
self.schema['Personne'].set_action_permissions('read', ('managers',)) |
0 | 375 |
cnx = self.login('anon') |
376 |
cu = cnx.cursor() |
|
377 |
rset = cu.execute('Any N,U WHERE N has_text "bidule", N owned_by U?') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
378 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
379 |
cnx.close() |
0 | 380 |
|
381 |
def test_read_erqlexpr_aggregat(self): |
|
382 |
self.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
|
383 |
self.commit() |
|
384 |
cnx = self.login('iaminusersgrouponly') |
|
385 |
cu = cnx.cursor() |
|
386 |
rset = cu.execute('Any COUNT(X) WHERE X is Affaire') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
387 |
self.assertEqual(rset.rows, [[0]]) |
0 | 388 |
aff2 = cu.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
389 |
soc1 = cu.execute("INSERT Societe X: X nom 'chouette'")[0][0] |
|
390 |
cu.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
391 |
cnx.commit() |
|
392 |
rset = cu.execute('Any COUNT(X) WHERE X is Affaire') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
393 |
self.assertEqual(rset.rows, [[1]]) |
0 | 394 |
rset = cu.execute('Any ETN, COUNT(X) GROUPBY ETN WHERE X is ET, ET name ETN') |
395 |
values = dict(rset) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
396 |
self.assertEqual(values['Affaire'], 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
397 |
self.assertEqual(values['Societe'], 2) |
0 | 398 |
rset = cu.execute('Any ETN, COUNT(X) GROUPBY ETN WHERE X is ET, ET name ETN WITH X BEING ((Affaire X) UNION (Societe X))') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
399 |
self.assertEqual(len(rset), 2) |
0 | 400 |
values = dict(rset) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
401 |
self.assertEqual(values['Affaire'], 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
402 |
self.assertEqual(values['Societe'], 2) |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
403 |
cnx.close() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
404 |
|
0 | 405 |
|
406 |
def test_attribute_security(self): |
|
407 |
# only managers should be able to edit the 'test' attribute of Personne entities |
|
408 |
eid = self.execute("INSERT Personne X: X nom 'bidule', X web 'http://www.debian.org', X test TRUE")[0][0] |
|
409 |
self.commit() |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
410 |
self.execute('SET X test FALSE WHERE X eid %(x)s', {'x': eid}) |
0 | 411 |
self.commit() |
412 |
cnx = self.login('iaminusersgrouponly') |
|
413 |
cu = cnx.cursor() |
|
414 |
cu.execute("INSERT Personne X: X nom 'bidule', X web 'http://www.debian.org', X test TRUE") |
|
415 |
self.assertRaises(Unauthorized, cnx.commit) |
|
416 |
cu.execute("INSERT Personne X: X nom 'bidule', X web 'http://www.debian.org', X test FALSE") |
|
417 |
self.assertRaises(Unauthorized, cnx.commit) |
|
418 |
eid = cu.execute("INSERT Personne X: X nom 'bidule', X web 'http://www.debian.org'")[0][0] |
|
419 |
cnx.commit() |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
420 |
cu.execute('SET X test FALSE WHERE X eid %(x)s', {'x': eid}) |
0 | 421 |
self.assertRaises(Unauthorized, cnx.commit) |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
422 |
cu.execute('SET X test TRUE WHERE X eid %(x)s', {'x': eid}) |
0 | 423 |
self.assertRaises(Unauthorized, cnx.commit) |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
424 |
cu.execute('SET X web "http://www.logilab.org" WHERE X eid %(x)s', {'x': eid}) |
0 | 425 |
cnx.commit() |
426 |
cnx.close() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
427 |
|
0 | 428 |
def test_attribute_security_rqlexpr(self): |
429 |
# Note.para attribute editable by managers or if the note is in "todo" state |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
430 |
note = self.execute("INSERT Note X: X para 'bidule'").get_entity(0, 0) |
0 | 431 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
432 |
note.cw_adapt_to('IWorkflowable').fire_transition('markasdone') |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
433 |
self.execute('SET X para "truc" WHERE X eid %(x)s', {'x': note.eid}) |
0 | 434 |
self.commit() |
435 |
cnx = self.login('iaminusersgrouponly') |
|
436 |
cu = cnx.cursor() |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
437 |
cu.execute("SET X para 'chouette' WHERE X eid %(x)s", {'x': note.eid}) |
0 | 438 |
self.assertRaises(Unauthorized, cnx.commit) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
439 |
note2 = cu.execute("INSERT Note X: X para 'bidule'").get_entity(0, 0) |
0 | 440 |
cnx.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
441 |
note2.cw_adapt_to('IWorkflowable').fire_transition('markasdone') |
0 | 442 |
cnx.commit() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
443 |
self.assertEqual(len(cu.execute('Any X WHERE X in_state S, S name "todo", X eid %(x)s', {'x': note2.eid})), |
0 | 444 |
0) |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
445 |
cu.execute("SET X para 'chouette' WHERE X eid %(x)s", {'x': note2.eid}) |
0 | 446 |
self.assertRaises(Unauthorized, cnx.commit) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
447 |
note2.cw_adapt_to('IWorkflowable').fire_transition('redoit') |
0 | 448 |
cnx.commit() |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
449 |
cu.execute("SET X para 'chouette' WHERE X eid %(x)s", {'x': note2.eid}) |
0 | 450 |
cnx.commit() |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
451 |
cnx.close() |
0 | 452 |
|
453 |
def test_attribute_read_security(self): |
|
454 |
# anon not allowed to see users'login, but they can see users |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
455 |
self.repo.schema['CWUser'].set_action_permissions('read', ('guests', 'users', 'managers')) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
456 |
self.repo.schema['CWUser'].rdef('login').set_action_permissions('read', ('users', 'managers')) |
0 | 457 |
cnx = self.login('anon') |
458 |
cu = cnx.cursor() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
459 |
rset = cu.execute('CWUser X') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
460 |
self.assertTrue(rset) |
0 | 461 |
x = rset.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:
5890
diff
changeset
|
462 |
self.assertEqual(x.login, None) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
463 |
self.assertTrue(x.creation_date) |
0 | 464 |
x = rset.get_entity(1, 0) |
465 |
x.complete() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
466 |
self.assertEqual(x.login, None) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
467 |
self.assertTrue(x.creation_date) |
0 | 468 |
cnx.rollback() |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
469 |
cnx.close() |
0 | 470 |
|
471 |
class BaseSchemaSecurityTC(BaseSecurityTC): |
|
472 |
"""tests related to the base schema permission configuration""" |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
473 |
|
0 | 474 |
def test_user_can_delete_object_he_created(self): |
475 |
# even if some other user have changed object'state |
|
476 |
cnx = self.login('iaminusersgrouponly') |
|
477 |
cu = cnx.cursor() |
|
478 |
# due to security test, affaire has to concerne a societe the user owns |
|
479 |
cu.execute('INSERT Societe X: X nom "ARCTIA"') |
|
480 |
cu.execute('INSERT Affaire X: X ref "ARCT01", X concerne S WHERE S nom "ARCTIA"') |
|
481 |
cnx.commit() |
|
482 |
self.restore_connection() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
483 |
affaire = self.execute('Any X WHERE X ref "ARCT01"').get_entity(0, 0) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
484 |
affaire.cw_adapt_to('IWorkflowable').fire_transition('abort') |
0 | 485 |
self.commit() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
486 |
self.assertEqual(len(self.execute('TrInfo X WHERE X wf_info_for A, A ref "ARCT01"')), |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
487 |
1) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
488 |
self.assertEqual(len(self.execute('TrInfo X WHERE X wf_info_for A, A ref "ARCT01",' |
0 | 489 |
'X owned_by U, U login "admin"')), |
490 |
1) # TrInfo at the above state change |
|
491 |
cnx = self.login('iaminusersgrouponly') |
|
492 |
cu = cnx.cursor() |
|
493 |
cu.execute('DELETE Affaire X WHERE X ref "ARCT01"') |
|
494 |
cnx.commit() |
|
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
495 |
self.assertFalse(cu.execute('Affaire X')) |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
496 |
cnx.close() |
0 | 497 |
|
498 |
def test_users_and_groups_non_readable_by_guests(self): |
|
499 |
cnx = self.login('anon') |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
500 |
anon = cnx.user(self.session) |
0 | 501 |
cu = cnx.cursor() |
502 |
# anonymous user can only read itself |
|
503 |
rset = cu.execute('Any L WHERE X owned_by U, U login L') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
504 |
self.assertEqual(rset.rows, [['anon']]) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
505 |
rset = cu.execute('CWUser X') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
506 |
self.assertEqual(rset.rows, [[anon.eid]]) |
0 | 507 |
# anonymous user can read groups (necessary to check allowed transitions for instance) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
508 |
self.assert_(cu.execute('CWGroup X')) |
0 | 509 |
# should only be able to read the anonymous user, not another one |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
510 |
origuser = self.adminsession.user |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
511 |
self.assertRaises(Unauthorized, |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
512 |
cu.execute, 'CWUser X WHERE X eid %(x)s', {'x': origuser.eid}) |
0 | 513 |
# nothing selected, nothing updated, no exception raised |
514 |
#self.assertRaises(Unauthorized, |
|
515 |
# cu.execute, 'SET X login "toto" WHERE X eid %(x)s', |
|
516 |
# {'x': self.user.eid}) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
517 |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
518 |
rset = cu.execute('CWUser X WHERE X eid %(x)s', {'x': anon.eid}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
519 |
self.assertEqual(rset.rows, [[anon.eid]]) |
0 | 520 |
# but can't modify it |
4915
d657b89df9f4
fix test broken by recent rql rewrite / querier changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4787
diff
changeset
|
521 |
cu.execute('SET X login "toto" WHERE X eid %(x)s', {'x': anon.eid}) |
d657b89df9f4
fix test broken by recent rql rewrite / querier changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4787
diff
changeset
|
522 |
self.assertRaises(Unauthorized, cnx.commit) |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
523 |
cnx.close() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
524 |
|
0 | 525 |
def test_in_group_relation(self): |
526 |
cnx = self.login('iaminusersgrouponly') |
|
527 |
cu = cnx.cursor() |
|
528 |
rql = u"DELETE U in_group G WHERE U login 'admin'" |
|
529 |
self.assertRaises(Unauthorized, cu.execute, rql) |
|
530 |
rql = u"SET U in_group G WHERE U login 'admin', G name 'users'" |
|
531 |
self.assertRaises(Unauthorized, cu.execute, rql) |
|
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
532 |
cnx.close() |
0 | 533 |
|
534 |
def test_owned_by(self): |
|
535 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
536 |
self.commit() |
|
537 |
cnx = self.login('iaminusersgrouponly') |
|
538 |
cu = cnx.cursor() |
|
539 |
rql = u"SET X owned_by U WHERE U login 'iaminusersgrouponly', X is Personne" |
|
540 |
self.assertRaises(Unauthorized, cu.execute, rql) |
|
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
541 |
cnx.close() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
542 |
|
0 | 543 |
def test_bookmarked_by_guests_security(self): |
544 |
beid1 = self.execute('INSERT Bookmark B: B path "?vid=manage", B title "manage"')[0][0] |
|
545 |
beid2 = self.execute('INSERT Bookmark B: B path "?vid=index", B title "index", B bookmarked_by U WHERE U login "anon"')[0][0] |
|
546 |
self.commit() |
|
547 |
cnx = self.login('anon') |
|
548 |
cu = cnx.cursor() |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
549 |
anoneid = self.session.user.eid |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
550 |
self.assertEqual(cu.execute('Any T,P ORDERBY lower(T) WHERE B is Bookmark,B title T,B path P,' |
0 | 551 |
'B bookmarked_by U, U eid %s' % anoneid).rows, |
552 |
[['index', '?vid=index']]) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
553 |
self.assertEqual(cu.execute('Any T,P ORDERBY lower(T) WHERE B is Bookmark,B title T,B path P,' |
0 | 554 |
'B bookmarked_by U, U eid %(x)s', {'x': anoneid}).rows, |
555 |
[['index', '?vid=index']]) |
|
556 |
# can read others bookmarks as well |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
557 |
self.assertEqual(cu.execute('Any B where B is Bookmark, NOT B bookmarked_by U').rows, |
0 | 558 |
[[beid1]]) |
559 |
self.assertRaises(Unauthorized, cu.execute,'DELETE B bookmarked_by U') |
|
560 |
self.assertRaises(Unauthorized, |
|
561 |
cu.execute, 'SET B bookmarked_by U WHERE U eid %(x)s, B eid %(b)s', |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
562 |
{'x': anoneid, 'b': beid1}) |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
563 |
cnx.close() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
564 |
|
0 | 565 |
|
566 |
def test_ambigous_ordered(self): |
|
567 |
cnx = self.login('anon') |
|
568 |
cu = cnx.cursor() |
|
569 |
names = [t for t, in cu.execute('Any N ORDERBY lower(N) WHERE X name N')] |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
570 |
self.assertEqual(names, sorted(names, key=lambda x: x.lower())) |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
571 |
cnx.close() |
0 | 572 |
|
573 |
def test_in_state_without_update_perm(self): |
|
574 |
"""check a user change in_state without having update permission on the |
|
575 |
subject |
|
576 |
""" |
|
577 |
eid = self.execute('INSERT Affaire X: X ref "ARCT01"')[0][0] |
|
578 |
self.commit() |
|
579 |
cnx = self.login('iaminusersgrouponly') |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
580 |
session = self.session |
0 | 581 |
# needed to avoid check_perm error |
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:
7244
diff
changeset
|
582 |
session.set_cnxset() |
0 | 583 |
# needed to remove rql expr granting update perm to the user |
4691
ae468fae9965
[test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
584 |
affaire_perms = self.schema['Affaire'].permissions.copy() |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
585 |
self.schema['Affaire'].set_action_permissions('update', self.schema['Affaire'].get_groups('update')) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
586 |
try: |
4691
ae468fae9965
[test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
587 |
self.assertRaises(Unauthorized, |
ae468fae9965
[test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
588 |
self.schema['Affaire'].check_perm, session, 'update', eid=eid) |
ae468fae9965
[test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
589 |
cu = cnx.cursor() |
ae468fae9965
[test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
590 |
self.schema['Affaire'].set_action_permissions('read', ('users',)) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
591 |
aff = cu.execute('Any X WHERE X ref "ARCT01"').get_entity(0, 0) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
592 |
aff.cw_adapt_to('IWorkflowable').fire_transition('abort') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
593 |
cnx.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
594 |
# though changing a user state (even logged user) is reserved to managers |
3447 | 595 |
user = cnx.user(self.session) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
596 |
# XXX wether it should raise Unauthorized or ValidationError is not clear |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
597 |
# the best would probably ValidationError if the transition doesn't exist |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
598 |
# from the current state but Unauthorized if it exists but user can't pass it |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
599 |
self.assertRaises(ValidationError, |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
600 |
user.cw_adapt_to('IWorkflowable').fire_transition, 'deactivate') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
601 |
finally: |
4691
ae468fae9965
[test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
602 |
# restore orig perms |
ae468fae9965
[test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
603 |
for action, perms in affaire_perms.iteritems(): |
ae468fae9965
[test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4191
diff
changeset
|
604 |
self.schema['Affaire'].set_action_permissions(action, perms) |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
605 |
cnx.close() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
606 |
|
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
607 |
def test_trinfo_security(self): |
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
608 |
aff = self.execute('INSERT Affaire X: X ref "ARCT01"').get_entity(0, 0) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
609 |
iworkflowable = aff.cw_adapt_to('IWorkflowable') |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
610 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
611 |
iworkflowable.fire_transition('abort') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
612 |
self.commit() |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
613 |
# can change tr info comment |
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
614 |
self.execute('SET TI comment %(c)s WHERE TI wf_info_for X, X ref "ARCT01"', |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
615 |
{'c': u'bouh!'}) |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
616 |
self.commit() |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
617 |
aff.cw_clear_relation_cache('wf_info_for', 'object') |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
618 |
trinfo = iworkflowable.latest_trinfo() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
619 |
self.assertEqual(trinfo.comment, 'bouh!') |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
620 |
# but not from_state/to_state |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
621 |
aff.cw_clear_relation_cache('wf_info_for', role='object') |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
622 |
self.assertRaises(Unauthorized, |
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
623 |
self.execute, 'SET TI from_state S WHERE TI eid %(ti)s, S name "ben non"', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
624 |
{'ti': trinfo.eid}) |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
625 |
self.assertRaises(Unauthorized, |
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
626 |
self.execute, 'SET TI to_state S WHERE TI eid %(ti)s, S name "pitetre"', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
627 |
{'ti': trinfo.eid}) |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
628 |
|
0 | 629 |
if __name__ == '__main__': |
630 |
unittest_main() |