author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 20 Apr 2010 16:31:53 +0200 | |
changeset 5355 | 3c703f3245dc |
parent 5174 | 78438ad513ca |
child 5423 | e15abfdcce38 |
permissions | -rw-r--r-- |
0 | 1 |
"""functional tests for server'security |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
2 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 3 |
""" |
4 |
import sys |
|
5 |
||
6 |
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
|
7 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 8 |
|
9 |
from cubicweb import Unauthorized, ValidationError |
|
10 |
from cubicweb.server.querier import check_read_access |
|
11 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
12 |
class BaseSecurityTC(CubicWebTC): |
0 | 13 |
|
14 |
def setUp(self): |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
15 |
CubicWebTC.setUp(self) |
0 | 16 |
self.create_user('iaminusersgrouponly') |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
17 |
self.readoriggroups = self.schema['Personne'].permissions['read'] |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
18 |
self.addoriggroups = self.schema['Personne'].permissions['add'] |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
19 |
|
0 | 20 |
def tearDown(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
21 |
CubicWebTC.tearDown(self) |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
22 |
self.schema['Personne'].set_action_permissions('read', self.readoriggroups) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
23 |
self.schema['Personne'].set_action_permissions('add', self.addoriggroups) |
0 | 24 |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
25 |
|
0 | 26 |
class LowLevelSecurityFunctionTC(BaseSecurityTC): |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
27 |
|
0 | 28 |
def test_check_read_access(self): |
29 |
rql = u'Personne U where U nom "managers"' |
|
3252
c0e10da6f1cf
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
30 |
rqlst = self.repo.vreg.rqlhelper.parse(rql).children[0] |
0 | 31 |
origgroups = self.schema['Personne'].get_groups('read') |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
32 |
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
|
33 |
self.repo.vreg.solutions(self.session, rqlst, None) |
0 | 34 |
solution = rqlst.solutions[0] |
35 |
check_read_access(self.schema, self.session.user, rqlst, solution) |
|
36 |
cnx = self.login('anon') |
|
37 |
cu = cnx.cursor() |
|
38 |
self.assertRaises(Unauthorized, |
|
39 |
check_read_access, |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
40 |
self.schema, cnx.user(self.session), rqlst, solution) |
0 | 41 |
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
|
42 |
|
0 | 43 |
def test_upassword_not_selectable(self): |
44 |
self.assertRaises(Unauthorized, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
45 |
self.execute, 'Any X,P WHERE X is CWUser, X upassword P') |
0 | 46 |
self.rollback() |
47 |
cnx = self.login('iaminusersgrouponly') |
|
48 |
cu = cnx.cursor() |
|
49 |
self.assertRaises(Unauthorized, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
50 |
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
|
51 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
52 |
|
0 | 53 |
class SecurityTC(BaseSecurityTC): |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
54 |
|
0 | 55 |
def setUp(self): |
56 |
BaseSecurityTC.setUp(self) |
|
57 |
# implicitly test manager can add some entities |
|
58 |
self.execute("INSERT Affaire X: X sujet 'cool'") |
|
59 |
self.execute("INSERT Societe X: X nom 'logilab'") |
|
60 |
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
|
61 |
self.execute('INSERT CWGroup X: X name "staff"') |
0 | 62 |
self.commit() |
63 |
||
64 |
def test_insert_security(self): |
|
65 |
cnx = self.login('anon') |
|
66 |
cu = cnx.cursor() |
|
67 |
cu.execute("INSERT Personne X: X nom 'bidule'") |
|
68 |
self.assertRaises(Unauthorized, cnx.commit) |
|
69 |
self.assertEquals(cu.execute('Personne X').rowcount, 1) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
70 |
|
0 | 71 |
def test_insert_rql_permission(self): |
72 |
# test user can only add une affaire related to a societe he owns |
|
73 |
cnx = self.login('iaminusersgrouponly') |
|
74 |
cu = cnx.cursor() |
|
75 |
cu.execute("INSERT Affaire X: X sujet 'cool'") |
|
76 |
self.assertRaises(Unauthorized, cnx.commit) |
|
77 |
# test nothing has actually been inserted |
|
78 |
self.restore_connection() |
|
79 |
self.assertEquals(self.execute('Affaire X').rowcount, 1) |
|
80 |
cnx = self.login('iaminusersgrouponly') |
|
81 |
cu = cnx.cursor() |
|
82 |
cu.execute("INSERT Affaire X: X sujet 'cool'") |
|
83 |
cu.execute("INSERT Societe X: X nom 'chouette'") |
|
84 |
cu.execute("SET A concerne S WHERE A sujet 'cool', S nom 'chouette'") |
|
85 |
cnx.commit() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
86 |
|
0 | 87 |
def test_update_security_1(self): |
88 |
cnx = self.login('anon') |
|
89 |
cu = cnx.cursor() |
|
90 |
# local security check |
|
91 |
cu.execute( "SET X nom 'bidulechouette' WHERE X is Personne") |
|
92 |
self.assertRaises(Unauthorized, cnx.commit) |
|
93 |
self.restore_connection() |
|
94 |
self.assertEquals(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
|
95 |
|
0 | 96 |
def test_update_security_2(self): |
97 |
cnx = self.login('anon') |
|
98 |
cu = cnx.cursor() |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
99 |
self.repo.schema['Personne'].set_action_permissions('read', ('users', 'managers')) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
100 |
self.repo.schema['Personne'].set_action_permissions('add', ('guests', 'users', 'managers')) |
0 | 101 |
self.assertRaises(Unauthorized, cu.execute, "SET X nom 'bidulechouette' WHERE X is Personne") |
102 |
#self.assertRaises(Unauthorized, cnx.commit) |
|
103 |
# test nothing has actually been inserted |
|
104 |
self.restore_connection() |
|
105 |
self.assertEquals(self.execute('Personne X WHERE X nom "bidulechouette"').rowcount, 0) |
|
106 |
||
107 |
def test_update_security_3(self): |
|
108 |
cnx = self.login('iaminusersgrouponly') |
|
109 |
cu = cnx.cursor() |
|
110 |
cu.execute("INSERT Personne X: X nom 'biduuule'") |
|
111 |
cu.execute("INSERT Societe X: X nom 'looogilab'") |
|
112 |
cu.execute("SET X travaille S WHERE X nom 'biduuule', S nom 'looogilab'") |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
113 |
|
0 | 114 |
def test_update_rql_permission(self): |
115 |
self.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
116 |
self.commit() |
|
117 |
# test user can only update une affaire related to a societe he owns |
|
118 |
cnx = self.login('iaminusersgrouponly') |
|
119 |
cu = cnx.cursor() |
|
120 |
cu.execute("SET X sujet 'pascool' WHERE X is Affaire") |
|
121 |
# this won't actually do anything since the selection query won't return anything |
|
122 |
cnx.commit() |
|
123 |
# to actually get Unauthorized exception, try to update an entity we can read |
|
124 |
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
|
125 |
self.assertRaises(Unauthorized, cnx.commit) |
0 | 126 |
cu.execute("INSERT Affaire X: X sujet 'pascool'") |
127 |
cu.execute("INSERT Societe X: X nom 'chouette'") |
|
128 |
cu.execute("SET A concerne S WHERE A sujet 'pascool', S nom 'chouette'") |
|
129 |
cu.execute("SET X sujet 'habahsicestcool' WHERE X sujet 'pascool'") |
|
130 |
cnx.commit() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
131 |
|
0 | 132 |
def test_delete_security(self): |
133 |
# FIXME: sample below fails because we don't detect "owner" can't delete |
|
134 |
# user anyway, and since no user with login == 'bidule' exists, no |
|
135 |
# exception is raised |
|
136 |
#user._groups = {'guests':1} |
|
137 |
#self.assertRaises(Unauthorized, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
138 |
# self.o.execute, user, "DELETE CWUser X WHERE X login 'bidule'") |
0 | 139 |
# check local security |
140 |
cnx = self.login('iaminusersgrouponly') |
|
141 |
cu = cnx.cursor() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
142 |
self.assertRaises(Unauthorized, cu.execute, "DELETE CWGroup Y WHERE Y name 'staff'") |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
143 |
|
0 | 144 |
def test_delete_rql_permission(self): |
145 |
self.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
146 |
self.commit() |
|
147 |
# test user can only dele une affaire related to a societe he owns |
|
148 |
cnx = self.login('iaminusersgrouponly') |
|
149 |
cu = cnx.cursor() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
150 |
# this won't actually do anything since the selection query won't return anything |
0 | 151 |
cu.execute("DELETE Affaire X") |
152 |
cnx.commit() |
|
153 |
# to actually get Unauthorized exception, try to delete an entity we can read |
|
154 |
self.assertRaises(Unauthorized, cu.execute, "DELETE Societe S") |
|
155 |
cu.execute("INSERT Affaire X: X sujet 'pascool'") |
|
156 |
cu.execute("INSERT Societe X: X nom 'chouette'") |
|
157 |
cu.execute("SET A concerne S WHERE A sujet 'pascool', S nom 'chouette'") |
|
158 |
cnx.commit() |
|
159 |
## # this one should fail since it will try to delete two affaires, one authorized |
|
160 |
## # and the other not |
|
161 |
## self.assertRaises(Unauthorized, cu.execute, "DELETE Affaire X") |
|
162 |
cu.execute("DELETE Affaire X WHERE X sujet 'pascool'") |
|
163 |
cnx.commit() |
|
164 |
||
165 |
||
166 |
def test_insert_relation_rql_permission(self): |
|
167 |
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
|
168 |
session = self.session |
0 | 169 |
cu = cnx.cursor(session) |
170 |
cu.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
171 |
# should raise Unauthorized since user don't own S |
|
172 |
# though this won't actually do anything since the selection query won't return anything |
|
173 |
cnx.commit() |
|
174 |
# to actually get Unauthorized exception, try to insert a relation were we can read both entities |
|
175 |
rset = cu.execute('Personne P') |
|
176 |
self.assertEquals(len(rset), 1) |
|
177 |
ent = rset.get_entity(0, 0) |
|
178 |
session.set_pool() # necessary |
|
179 |
self.assertRaises(Unauthorized, |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
180 |
ent.e_schema.check_perm, session, 'update', eid=ent.eid) |
0 | 181 |
self.assertRaises(Unauthorized, |
182 |
cu.execute, "SET P travaille S WHERE P is Personne, S is Societe") |
|
183 |
# test nothing has actually been inserted: |
|
184 |
self.assertEquals(cu.execute('Any P,S WHERE P travaille S,P is Personne, S is Societe').rowcount, 0) |
|
185 |
cu.execute("INSERT Societe X: X nom 'chouette'") |
|
186 |
cu.execute("SET A concerne S WHERE A is Affaire, S nom 'chouette'") |
|
187 |
cnx.commit() |
|
188 |
||
189 |
def test_delete_relation_rql_permission(self): |
|
190 |
self.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
191 |
self.commit() |
|
192 |
cnx = self.login('iaminusersgrouponly') |
|
193 |
cu = cnx.cursor() |
|
194 |
# this won't actually do anything since the selection query won't return anything |
|
195 |
cu.execute("DELETE A concerne S") |
|
196 |
cnx.commit() |
|
197 |
# to actually get Unauthorized exception, try to delete a relation we can read |
|
198 |
self.restore_connection() |
|
199 |
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
|
200 |
self.execute('SET X owned_by U WHERE X eid %(x)s, U login "iaminusersgrouponly"', {'x': eid}) |
0 | 201 |
self.execute("SET A concerne S WHERE A sujet 'pascool', S is Societe") |
202 |
self.commit() |
|
203 |
cnx = self.login('iaminusersgrouponly') |
|
204 |
cu = cnx.cursor() |
|
205 |
self.assertRaises(Unauthorized, cu.execute, "DELETE A concerne S") |
|
206 |
cu.execute("INSERT Societe X: X nom 'chouette'") |
|
207 |
cu.execute("SET A concerne S WHERE A is Affaire, S nom 'chouette'") |
|
208 |
cnx.commit() |
|
209 |
cu.execute("DELETE A concerne S WHERE S nom 'chouette'") |
|
210 |
||
211 |
||
212 |
def test_user_can_change_its_upassword(self): |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
213 |
ueid = self.create_user('user').eid |
0 | 214 |
cnx = self.login('user') |
215 |
cu = cnx.cursor() |
|
216 |
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
|
217 |
{'x': ueid, 'passwd': 'newpwd'}) |
0 | 218 |
cnx.commit() |
219 |
cnx.close() |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
220 |
cnx = self.login('user', password='newpwd') |
0 | 221 |
|
222 |
def test_user_cant_change_other_upassword(self): |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
223 |
ueid = self.create_user('otheruser').eid |
0 | 224 |
cnx = self.login('iaminusersgrouponly') |
225 |
cu = cnx.cursor() |
|
226 |
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
|
227 |
{'x': ueid, 'passwd': 'newpwd'}) |
0 | 228 |
self.assertRaises(Unauthorized, cnx.commit) |
229 |
||
230 |
# read security test |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
231 |
|
0 | 232 |
def test_read_base(self): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
233 |
self.schema['Personne'].set_action_permissions('read', ('users', 'managers')) |
0 | 234 |
cnx = self.login('anon') |
235 |
cu = cnx.cursor() |
|
236 |
self.assertRaises(Unauthorized, |
|
237 |
cu.execute, 'Personne U where U nom "managers"') |
|
238 |
||
321
247947250382
fix security bug w/ query using 'NOT X eid 123'
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
239 |
def test_read_erqlexpr_base(self): |
0 | 240 |
eid = self.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
241 |
self.commit() |
|
242 |
cnx = self.login('iaminusersgrouponly') |
|
243 |
cu = cnx.cursor() |
|
244 |
rset = cu.execute('Affaire X') |
|
245 |
self.assertEquals(rset.rows, []) |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
246 |
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
|
247 |
# cache test |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
248 |
self.assertRaises(Unauthorized, cu.execute, 'Any X WHERE X eid %(x)s', {'x': eid}) |
0 | 249 |
aff2 = cu.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
250 |
soc1 = cu.execute("INSERT Societe X: X nom 'chouette'")[0][0] |
|
251 |
cu.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
252 |
cnx.commit() |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
253 |
rset = cu.execute('Any X WHERE X eid %(x)s', {'x': aff2}) |
0 | 254 |
self.assertEquals(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
|
255 |
# 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
|
256 |
rset = cu.execute('Affaire X WHERE NOT X eid %(x)s', {'x': eid}) |
389 | 257 |
self.assertEquals(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
|
258 |
rset = cu.execute('Affaire X WHERE NOT X eid %(x)s', {'x': aff2}) |
321
247947250382
fix security bug w/ query using 'NOT X eid 123'
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
259 |
self.assertEquals(rset.rows, []) |
4765 | 260 |
# 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
|
261 |
self.assertRaises(Unauthorized, cu.execute, 'SET X sujet "hacked" WHERE X eid %(x)s', {'x': eid}) |
4765 | 262 |
|
263 |
||
264 |
def test_entity_created_in_transaction(self): |
|
265 |
affschema = self.schema['Affaire'] |
|
266 |
origperms = affschema.permissions['read'] |
|
267 |
affschema.set_action_permissions('read', affschema.permissions['add']) |
|
268 |
try: |
|
269 |
cnx = self.login('iaminusersgrouponly') |
|
270 |
cu = cnx.cursor() |
|
271 |
aff2 = cu.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
|
272 |
# entity created in transaction are readable *by eid* |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
273 |
self.failUnless(cu.execute('Any X WHERE X eid %(x)s', {'x':aff2})) |
4765 | 274 |
# XXX would be nice if it worked |
275 |
rset = cu.execute("Affaire X WHERE X sujet 'cool'") |
|
276 |
self.assertEquals(len(rset), 0) |
|
277 |
finally: |
|
278 |
affschema.set_action_permissions('read', origperms) |
|
279 |
cnx.close() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
280 |
|
0 | 281 |
def test_read_erqlexpr_has_text1(self): |
282 |
aff1 = self.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
|
283 |
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
|
284 |
self.execute('SET X owned_by U WHERE X eid %(x)s, U login "iaminusersgrouponly"', {'x': card1}) |
0 | 285 |
self.commit() |
286 |
cnx = self.login('iaminusersgrouponly') |
|
287 |
cu = cnx.cursor() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
288 |
aff2 = cu.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
0 | 289 |
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
|
290 |
cu.execute("SET A concerne S WHERE A eid %(a)s, S eid %(s)s", {'a': aff2, 's': soc1}) |
0 | 291 |
cnx.commit() |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
292 |
self.assertRaises(Unauthorized, cu.execute, 'Any X WHERE X eid %(x)s', {'x':aff1}) |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
293 |
self.failUnless(cu.execute('Any X WHERE X eid %(x)s', {'x':aff2})) |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
294 |
self.failUnless(cu.execute('Any X WHERE X eid %(x)s', {'x':card1})) |
0 | 295 |
rset = cu.execute("Any X WHERE X has_text 'cool'") |
296 |
self.assertEquals(sorted(eid for eid, in rset.rows), |
|
297 |
[card1, aff2]) |
|
298 |
||
299 |
def test_read_erqlexpr_has_text2(self): |
|
300 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
301 |
self.execute("INSERT Societe X: X nom 'bidule'") |
|
302 |
self.commit() |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
303 |
self.schema['Personne'].set_action_permissions('read', ('managers',)) |
0 | 304 |
cnx = self.login('iaminusersgrouponly') |
305 |
cu = cnx.cursor() |
|
306 |
rset = cu.execute('Any N WHERE N has_text "bidule"') |
|
307 |
self.assertEquals(len(rset.rows), 1, rset.rows) |
|
308 |
rset = cu.execute('Any N WITH N BEING (Any N WHERE N has_text "bidule")') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
309 |
self.assertEquals(len(rset.rows), 1, rset.rows) |
0 | 310 |
|
311 |
def test_read_erqlexpr_optional_rel(self): |
|
312 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
313 |
self.execute("INSERT Societe X: X nom 'bidule'") |
|
314 |
self.commit() |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
315 |
self.schema['Personne'].set_action_permissions('read', ('managers',)) |
0 | 316 |
cnx = self.login('anon') |
317 |
cu = cnx.cursor() |
|
318 |
rset = cu.execute('Any N,U WHERE N has_text "bidule", N owned_by U?') |
|
319 |
self.assertEquals(len(rset.rows), 1, rset.rows) |
|
320 |
||
321 |
def test_read_erqlexpr_aggregat(self): |
|
322 |
self.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
|
323 |
self.commit() |
|
324 |
cnx = self.login('iaminusersgrouponly') |
|
325 |
cu = cnx.cursor() |
|
326 |
rset = cu.execute('Any COUNT(X) WHERE X is Affaire') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
327 |
self.assertEquals(rset.rows, [[0]]) |
0 | 328 |
aff2 = cu.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
329 |
soc1 = cu.execute("INSERT Societe X: X nom 'chouette'")[0][0] |
|
330 |
cu.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
331 |
cnx.commit() |
|
332 |
rset = cu.execute('Any COUNT(X) WHERE X is Affaire') |
|
333 |
self.assertEquals(rset.rows, [[1]]) |
|
334 |
rset = cu.execute('Any ETN, COUNT(X) GROUPBY ETN WHERE X is ET, ET name ETN') |
|
335 |
values = dict(rset) |
|
336 |
self.assertEquals(values['Affaire'], 1) |
|
337 |
self.assertEquals(values['Societe'], 2) |
|
338 |
rset = cu.execute('Any ETN, COUNT(X) GROUPBY ETN WHERE X is ET, ET name ETN WITH X BEING ((Affaire X) UNION (Societe X))') |
|
339 |
self.assertEquals(len(rset), 2) |
|
340 |
values = dict(rset) |
|
341 |
self.assertEquals(values['Affaire'], 1) |
|
342 |
self.assertEquals(values['Societe'], 2) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
343 |
|
0 | 344 |
|
345 |
def test_attribute_security(self): |
|
346 |
# only managers should be able to edit the 'test' attribute of Personne entities |
|
347 |
eid = self.execute("INSERT Personne X: X nom 'bidule', X web 'http://www.debian.org', X test TRUE")[0][0] |
|
348 |
self.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.execute('SET X test FALSE WHERE X eid %(x)s', {'x': eid}) |
0 | 350 |
self.commit() |
351 |
cnx = self.login('iaminusersgrouponly') |
|
352 |
cu = cnx.cursor() |
|
353 |
cu.execute("INSERT Personne X: X nom 'bidule', X web 'http://www.debian.org', X test TRUE") |
|
354 |
self.assertRaises(Unauthorized, cnx.commit) |
|
355 |
cu.execute("INSERT Personne X: X nom 'bidule', X web 'http://www.debian.org', X test FALSE") |
|
356 |
self.assertRaises(Unauthorized, cnx.commit) |
|
357 |
eid = cu.execute("INSERT Personne X: X nom 'bidule', X web 'http://www.debian.org'")[0][0] |
|
358 |
cnx.commit() |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
359 |
cu.execute('SET X test FALSE WHERE X eid %(x)s', {'x': eid}) |
0 | 360 |
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
|
361 |
cu.execute('SET X test TRUE WHERE X eid %(x)s', {'x': eid}) |
0 | 362 |
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
|
363 |
cu.execute('SET X web "http://www.logilab.org" WHERE X eid %(x)s', {'x': eid}) |
0 | 364 |
cnx.commit() |
365 |
cnx.close() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
366 |
|
0 | 367 |
def test_attribute_security_rqlexpr(self): |
368 |
# 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
|
369 |
note = self.execute("INSERT Note X: X para 'bidule'").get_entity(0, 0) |
0 | 370 |
self.commit() |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
371 |
note.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
|
372 |
self.execute('SET X para "truc" WHERE X eid %(x)s', {'x': note.eid}) |
0 | 373 |
self.commit() |
374 |
cnx = self.login('iaminusersgrouponly') |
|
375 |
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
|
376 |
cu.execute("SET X para 'chouette' WHERE X eid %(x)s", {'x': note.eid}) |
0 | 377 |
self.assertRaises(Unauthorized, cnx.commit) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
378 |
note2 = cu.execute("INSERT Note X: X para 'bidule'").get_entity(0, 0) |
0 | 379 |
cnx.commit() |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
380 |
note2.fire_transition('markasdone') |
0 | 381 |
cnx.commit() |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
382 |
self.assertEquals(len(cu.execute('Any X WHERE X in_state S, S name "todo", X eid %(x)s', {'x': note2.eid})), |
0 | 383 |
0) |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
384 |
cu.execute("SET X para 'chouette' WHERE X eid %(x)s", {'x': note2.eid}) |
0 | 385 |
self.assertRaises(Unauthorized, cnx.commit) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
386 |
note2.fire_transition('redoit') |
0 | 387 |
cnx.commit() |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
388 |
cu.execute("SET X para 'chouette' WHERE X eid %(x)s", {'x': note2.eid}) |
0 | 389 |
cnx.commit() |
390 |
||
391 |
def test_attribute_read_security(self): |
|
392 |
# 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
|
393 |
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
|
394 |
self.repo.schema['CWUser'].rdef('login').set_action_permissions('read', ('users', 'managers')) |
0 | 395 |
cnx = self.login('anon') |
396 |
cu = cnx.cursor() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
397 |
rset = cu.execute('CWUser X') |
0 | 398 |
self.failUnless(rset) |
399 |
x = rset.get_entity(0, 0) |
|
400 |
self.assertEquals(x.login, None) |
|
401 |
self.failUnless(x.creation_date) |
|
402 |
x = rset.get_entity(1, 0) |
|
403 |
x.complete() |
|
404 |
self.assertEquals(x.login, None) |
|
405 |
self.failUnless(x.creation_date) |
|
406 |
cnx.rollback() |
|
407 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
408 |
|
0 | 409 |
class BaseSchemaSecurityTC(BaseSecurityTC): |
410 |
"""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
|
411 |
|
0 | 412 |
def test_user_can_delete_object_he_created(self): |
413 |
# even if some other user have changed object'state |
|
414 |
cnx = self.login('iaminusersgrouponly') |
|
415 |
cu = cnx.cursor() |
|
416 |
# due to security test, affaire has to concerne a societe the user owns |
|
417 |
cu.execute('INSERT Societe X: X nom "ARCTIA"') |
|
418 |
cu.execute('INSERT Affaire X: X ref "ARCT01", X concerne S WHERE S nom "ARCTIA"') |
|
419 |
cnx.commit() |
|
420 |
self.restore_connection() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
421 |
affaire = self.execute('Any X WHERE X ref "ARCT01"').get_entity(0, 0) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
422 |
affaire.fire_transition('abort') |
0 | 423 |
self.commit() |
424 |
self.assertEquals(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
|
425 |
1) |
0 | 426 |
self.assertEquals(len(self.execute('TrInfo X WHERE X wf_info_for A, A ref "ARCT01",' |
427 |
'X owned_by U, U login "admin"')), |
|
428 |
1) # TrInfo at the above state change |
|
429 |
cnx = self.login('iaminusersgrouponly') |
|
430 |
cu = cnx.cursor() |
|
431 |
cu.execute('DELETE Affaire X WHERE X ref "ARCT01"') |
|
432 |
cnx.commit() |
|
433 |
self.failIf(cu.execute('Affaire X')) |
|
434 |
||
435 |
def test_users_and_groups_non_readable_by_guests(self): |
|
436 |
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
|
437 |
anon = cnx.user(self.session) |
0 | 438 |
cu = cnx.cursor() |
439 |
# anonymous user can only read itself |
|
440 |
rset = cu.execute('Any L WHERE X owned_by U, U login L') |
|
441 |
self.assertEquals(rset.rows, [['anon']]) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
442 |
rset = cu.execute('CWUser X') |
0 | 443 |
self.assertEquals(rset.rows, [[anon.eid]]) |
444 |
# 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
|
445 |
self.assert_(cu.execute('CWGroup X')) |
0 | 446 |
# 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
|
447 |
origuser = self.adminsession.user |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
448 |
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
|
449 |
cu.execute, 'CWUser X WHERE X eid %(x)s', {'x': origuser.eid}) |
0 | 450 |
# nothing selected, nothing updated, no exception raised |
451 |
#self.assertRaises(Unauthorized, |
|
452 |
# cu.execute, 'SET X login "toto" WHERE X eid %(x)s', |
|
453 |
# {'x': self.user.eid}) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
454 |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
455 |
rset = cu.execute('CWUser X WHERE X eid %(x)s', {'x': anon.eid}) |
0 | 456 |
self.assertEquals(rset.rows, [[anon.eid]]) |
457 |
# 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
|
458 |
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
|
459 |
self.assertRaises(Unauthorized, cnx.commit) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
460 |
|
0 | 461 |
def test_in_group_relation(self): |
462 |
cnx = self.login('iaminusersgrouponly') |
|
463 |
cu = cnx.cursor() |
|
464 |
rql = u"DELETE U in_group G WHERE U login 'admin'" |
|
465 |
self.assertRaises(Unauthorized, cu.execute, rql) |
|
466 |
rql = u"SET U in_group G WHERE U login 'admin', G name 'users'" |
|
467 |
self.assertRaises(Unauthorized, cu.execute, rql) |
|
468 |
||
469 |
def test_owned_by(self): |
|
470 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
471 |
self.commit() |
|
472 |
cnx = self.login('iaminusersgrouponly') |
|
473 |
cu = cnx.cursor() |
|
474 |
rql = u"SET X owned_by U WHERE U login 'iaminusersgrouponly', X is Personne" |
|
475 |
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
|
476 |
|
0 | 477 |
def test_bookmarked_by_guests_security(self): |
478 |
beid1 = self.execute('INSERT Bookmark B: B path "?vid=manage", B title "manage"')[0][0] |
|
479 |
beid2 = self.execute('INSERT Bookmark B: B path "?vid=index", B title "index", B bookmarked_by U WHERE U login "anon"')[0][0] |
|
480 |
self.commit() |
|
481 |
cnx = self.login('anon') |
|
482 |
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
|
483 |
anoneid = self.session.user.eid |
0 | 484 |
self.assertEquals(cu.execute('Any T,P ORDERBY lower(T) WHERE B is Bookmark,B title T,B path P,' |
485 |
'B bookmarked_by U, U eid %s' % anoneid).rows, |
|
486 |
[['index', '?vid=index']]) |
|
487 |
self.assertEquals(cu.execute('Any T,P ORDERBY lower(T) WHERE B is Bookmark,B title T,B path P,' |
|
488 |
'B bookmarked_by U, U eid %(x)s', {'x': anoneid}).rows, |
|
489 |
[['index', '?vid=index']]) |
|
490 |
# can read others bookmarks as well |
|
491 |
self.assertEquals(cu.execute('Any B where B is Bookmark, NOT B bookmarked_by U').rows, |
|
492 |
[[beid1]]) |
|
493 |
self.assertRaises(Unauthorized, cu.execute,'DELETE B bookmarked_by U') |
|
494 |
self.assertRaises(Unauthorized, |
|
495 |
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
|
496 |
{'x': anoneid, 'b': beid1}) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
497 |
|
0 | 498 |
|
499 |
def test_ambigous_ordered(self): |
|
500 |
cnx = self.login('anon') |
|
501 |
cu = cnx.cursor() |
|
502 |
names = [t for t, in cu.execute('Any N ORDERBY lower(N) WHERE X name N')] |
|
503 |
self.assertEquals(names, sorted(names, key=lambda x: x.lower())) |
|
504 |
||
505 |
def test_in_state_without_update_perm(self): |
|
506 |
"""check a user change in_state without having update permission on the |
|
507 |
subject |
|
508 |
""" |
|
509 |
eid = self.execute('INSERT Affaire X: X ref "ARCT01"')[0][0] |
|
510 |
self.commit() |
|
511 |
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
|
512 |
session = self.session |
0 | 513 |
# needed to avoid check_perm error |
514 |
session.set_pool() |
|
515 |
# 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
|
516 |
affaire_perms = self.schema['Affaire'].permissions.copy() |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
517 |
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
|
518 |
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
|
519 |
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
|
520 |
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
|
521 |
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
|
522 |
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
|
523 |
aff = cu.execute('Any X WHERE X ref "ARCT01"').get_entity(0, 0) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
524 |
aff.fire_transition('abort') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
525 |
cnx.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
526 |
# though changing a user state (even logged user) is reserved to managers |
3447 | 527 |
user = cnx.user(self.session) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
528 |
# 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
|
529 |
# 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
|
530 |
# from the current state but Unauthorized if it exists but user can't pass it |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
531 |
self.assertRaises(ValidationError, user.fire_transition, 'deactivate') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
532 |
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
|
533 |
# 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
|
534 |
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
|
535 |
self.schema['Affaire'].set_action_permissions(action, perms) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
536 |
|
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
537 |
def test_trinfo_security(self): |
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
538 |
aff = self.execute('INSERT Affaire X: X ref "ARCT01"').get_entity(0, 0) |
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
539 |
self.commit() |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
540 |
aff.fire_transition('abort') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
541 |
self.commit() |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
542 |
# can change tr info comment |
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
543 |
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
|
544 |
{'c': u'bouh!'}) |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
545 |
self.commit() |
2608
21856eda34f6
[F repo tests] tests have to be updated:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2501
diff
changeset
|
546 |
aff.clear_related_cache('wf_info_for', 'object') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
547 |
trinfo = aff.latest_trinfo() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
548 |
self.assertEquals(trinfo.comment, 'bouh!') |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
549 |
# but not from_state/to_state |
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
550 |
aff.clear_related_cache('wf_info_for', role='object') |
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
551 |
self.assertRaises(Unauthorized, |
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
552 |
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
|
553 |
{'ti': trinfo.eid}) |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
554 |
self.assertRaises(Unauthorized, |
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
555 |
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
|
556 |
{'ti': trinfo.eid}) |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
557 |
|
0 | 558 |
if __name__ == '__main__': |
559 |
unittest_main() |