author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Wed, 01 Dec 2010 16:52:02 +0100 | |
branch | oldstable |
changeset 6716 | 494d4465f032 |
parent 6410 | 2e7a7b0829ed |
child 7072 | bcf96f2a4c5d |
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 |
|
30 |
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
|
31 |
CubicWebTC.setUp(self) |
0 | 32 |
self.create_user('iaminusersgrouponly') |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
33 |
self.readoriggroups = self.schema['Personne'].permissions['read'] |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
34 |
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
|
35 |
|
0 | 36 |
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
|
37 |
CubicWebTC.tearDown(self) |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
38 |
self.schema['Personne'].set_action_permissions('read', self.readoriggroups) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
39 |
self.schema['Personne'].set_action_permissions('add', self.addoriggroups) |
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) |
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
|
78 |
BaseSecurityTC.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
|
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') |
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
|
89 |
|
0 | 90 |
class SecurityTC(BaseSecurityTC): |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
91 |
|
0 | 92 |
def setUp(self): |
93 |
BaseSecurityTC.setUp(self) |
|
94 |
# implicitly test manager can add some entities |
|
95 |
self.execute("INSERT Affaire X: X sujet 'cool'") |
|
96 |
self.execute("INSERT Societe X: X nom 'logilab'") |
|
97 |
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
|
98 |
self.execute('INSERT CWGroup X: X name "staff"') |
0 | 99 |
self.commit() |
100 |
||
101 |
def test_insert_security(self): |
|
102 |
cnx = self.login('anon') |
|
103 |
cu = cnx.cursor() |
|
104 |
cu.execute("INSERT Personne X: X nom 'bidule'") |
|
105 |
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
|
106 |
self.assertEqual(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
|
107 |
|
0 | 108 |
def test_insert_rql_permission(self): |
109 |
# test user can only add une affaire related to a societe he owns |
|
110 |
cnx = self.login('iaminusersgrouponly') |
|
111 |
cu = cnx.cursor() |
|
112 |
cu.execute("INSERT Affaire X: X sujet 'cool'") |
|
113 |
self.assertRaises(Unauthorized, cnx.commit) |
|
114 |
# test nothing has actually been inserted |
|
115 |
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
|
116 |
self.assertEqual(self.execute('Affaire X').rowcount, 1) |
0 | 117 |
cnx = self.login('iaminusersgrouponly') |
118 |
cu = cnx.cursor() |
|
119 |
cu.execute("INSERT Affaire X: X sujet 'cool'") |
|
120 |
cu.execute("INSERT Societe X: X nom 'chouette'") |
|
121 |
cu.execute("SET A concerne S WHERE A sujet 'cool', S nom 'chouette'") |
|
122 |
cnx.commit() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
123 |
|
0 | 124 |
def test_update_security_1(self): |
125 |
cnx = self.login('anon') |
|
126 |
cu = cnx.cursor() |
|
127 |
# local security check |
|
128 |
cu.execute( "SET X nom 'bidulechouette' WHERE X is Personne") |
|
129 |
self.assertRaises(Unauthorized, cnx.commit) |
|
130 |
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
|
131 |
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
|
132 |
|
0 | 133 |
def test_update_security_2(self): |
134 |
cnx = self.login('anon') |
|
135 |
cu = cnx.cursor() |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
136 |
self.repo.schema['Personne'].set_action_permissions('read', ('users', 'managers')) |
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
137 |
self.repo.schema['Personne'].set_action_permissions('add', ('guests', 'users', 'managers')) |
0 | 138 |
self.assertRaises(Unauthorized, cu.execute, "SET X nom 'bidulechouette' WHERE X is Personne") |
139 |
#self.assertRaises(Unauthorized, cnx.commit) |
|
140 |
# test nothing has actually been inserted |
|
141 |
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
|
142 |
self.assertEqual(self.execute('Personne X WHERE X nom "bidulechouette"').rowcount, 0) |
0 | 143 |
|
144 |
def test_update_security_3(self): |
|
145 |
cnx = self.login('iaminusersgrouponly') |
|
146 |
cu = cnx.cursor() |
|
147 |
cu.execute("INSERT Personne X: X nom 'biduuule'") |
|
148 |
cu.execute("INSERT Societe X: X nom 'looogilab'") |
|
149 |
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
|
150 |
|
0 | 151 |
def test_update_rql_permission(self): |
152 |
self.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
153 |
self.commit() |
|
154 |
# test user can only update une affaire related to a societe he owns |
|
155 |
cnx = self.login('iaminusersgrouponly') |
|
156 |
cu = cnx.cursor() |
|
157 |
cu.execute("SET X sujet 'pascool' WHERE X is Affaire") |
|
158 |
# this won't actually do anything since the selection query won't return anything |
|
159 |
cnx.commit() |
|
160 |
# to actually get Unauthorized exception, try to update an entity we can read |
|
161 |
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
|
162 |
self.assertRaises(Unauthorized, cnx.commit) |
0 | 163 |
cu.execute("INSERT Affaire X: X sujet 'pascool'") |
164 |
cu.execute("INSERT Societe X: X nom 'chouette'") |
|
165 |
cu.execute("SET A concerne S WHERE A sujet 'pascool', S nom 'chouette'") |
|
166 |
cu.execute("SET X sujet 'habahsicestcool' WHERE X sujet 'pascool'") |
|
167 |
cnx.commit() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
168 |
|
0 | 169 |
def test_delete_security(self): |
170 |
# FIXME: sample below fails because we don't detect "owner" can't delete |
|
171 |
# user anyway, and since no user with login == 'bidule' exists, no |
|
172 |
# exception is raised |
|
173 |
#user._groups = {'guests':1} |
|
174 |
#self.assertRaises(Unauthorized, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
175 |
# self.o.execute, user, "DELETE CWUser X WHERE X login 'bidule'") |
0 | 176 |
# check local security |
177 |
cnx = self.login('iaminusersgrouponly') |
|
178 |
cu = cnx.cursor() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
179 |
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
|
180 |
|
0 | 181 |
def test_delete_rql_permission(self): |
182 |
self.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
183 |
self.commit() |
|
184 |
# test user can only dele une affaire related to a societe he owns |
|
185 |
cnx = self.login('iaminusersgrouponly') |
|
186 |
cu = cnx.cursor() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
187 |
# this won't actually do anything since the selection query won't return anything |
0 | 188 |
cu.execute("DELETE Affaire X") |
189 |
cnx.commit() |
|
190 |
# to actually get Unauthorized exception, try to delete an entity we can read |
|
191 |
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
|
192 |
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
|
193 |
cnx.rollback() # required after Unauthorized |
0 | 194 |
cu.execute("INSERT Affaire X: X sujet 'pascool'") |
195 |
cu.execute("INSERT Societe X: X nom 'chouette'") |
|
196 |
cu.execute("SET A concerne S WHERE A sujet 'pascool', S nom 'chouette'") |
|
197 |
cnx.commit() |
|
198 |
## # this one should fail since it will try to delete two affaires, one authorized |
|
199 |
## # and the other not |
|
200 |
## self.assertRaises(Unauthorized, cu.execute, "DELETE Affaire X") |
|
201 |
cu.execute("DELETE Affaire X WHERE X sujet 'pascool'") |
|
202 |
cnx.commit() |
|
203 |
||
204 |
||
205 |
def test_insert_relation_rql_permission(self): |
|
206 |
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
|
207 |
session = self.session |
0 | 208 |
cu = cnx.cursor(session) |
209 |
cu.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
210 |
# should raise Unauthorized since user don't own S |
|
211 |
# though this won't actually do anything since the selection query won't return anything |
|
212 |
cnx.commit() |
|
213 |
# to actually get Unauthorized exception, try to insert a relation were we can read both entities |
|
214 |
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
|
215 |
self.assertEqual(len(rset), 1) |
0 | 216 |
ent = rset.get_entity(0, 0) |
217 |
session.set_pool() # necessary |
|
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
218 |
self.assertRaises(Unauthorized, ent.cw_check_perm, 'update') |
0 | 219 |
self.assertRaises(Unauthorized, |
220 |
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
|
221 |
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
|
222 |
cnx.rollback() |
0 | 223 |
# 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
|
224 |
self.assertEqual(cu.execute('Any P,S WHERE P travaille S,P is Personne, S is Societe').rowcount, 0) |
0 | 225 |
cu.execute("INSERT Societe X: X nom 'chouette'") |
226 |
cu.execute("SET A concerne S WHERE A is Affaire, S nom 'chouette'") |
|
227 |
cnx.commit() |
|
228 |
||
229 |
def test_delete_relation_rql_permission(self): |
|
230 |
self.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
231 |
self.commit() |
|
232 |
cnx = self.login('iaminusersgrouponly') |
|
233 |
cu = cnx.cursor() |
|
234 |
# this won't actually do anything since the selection query won't return anything |
|
235 |
cu.execute("DELETE A concerne S") |
|
236 |
cnx.commit() |
|
237 |
# to actually get Unauthorized exception, try to delete a relation we can read |
|
238 |
self.restore_connection() |
|
239 |
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
|
240 |
self.execute('SET X owned_by U WHERE X eid %(x)s, U login "iaminusersgrouponly"', {'x': eid}) |
0 | 241 |
self.execute("SET A concerne S WHERE A sujet 'pascool', S is Societe") |
242 |
self.commit() |
|
243 |
cnx = self.login('iaminusersgrouponly') |
|
244 |
cu = cnx.cursor() |
|
245 |
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
|
246 |
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
|
247 |
cnx.rollback() # required after Unauthorized |
0 | 248 |
cu.execute("INSERT Societe X: X nom 'chouette'") |
249 |
cu.execute("SET A concerne S WHERE A is Affaire, S nom 'chouette'") |
|
250 |
cnx.commit() |
|
251 |
cu.execute("DELETE A concerne S WHERE S nom 'chouette'") |
|
252 |
||
253 |
||
254 |
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
|
255 |
ueid = self.create_user('user').eid |
0 | 256 |
cnx = self.login('user') |
257 |
cu = cnx.cursor() |
|
258 |
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
|
259 |
{'x': ueid, 'passwd': 'newpwd'}) |
0 | 260 |
cnx.commit() |
261 |
cnx.close() |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
262 |
cnx = self.login('user', password='newpwd') |
0 | 263 |
|
264 |
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
|
265 |
ueid = self.create_user('otheruser').eid |
0 | 266 |
cnx = self.login('iaminusersgrouponly') |
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 |
self.assertRaises(Unauthorized, cnx.commit) |
271 |
||
272 |
# read security test |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
273 |
|
0 | 274 |
def test_read_base(self): |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
275 |
self.schema['Personne'].set_action_permissions('read', ('users', 'managers')) |
0 | 276 |
cnx = self.login('anon') |
277 |
cu = cnx.cursor() |
|
278 |
self.assertRaises(Unauthorized, |
|
279 |
cu.execute, 'Personne U where U nom "managers"') |
|
280 |
||
321
247947250382
fix security bug w/ query using 'NOT X eid 123'
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
281 |
def test_read_erqlexpr_base(self): |
0 | 282 |
eid = self.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
283 |
self.commit() |
|
284 |
cnx = self.login('iaminusersgrouponly') |
|
285 |
cu = cnx.cursor() |
|
286 |
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
|
287 |
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
|
288 |
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
|
289 |
# cache test |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
290 |
self.assertRaises(Unauthorized, cu.execute, 'Any X WHERE X eid %(x)s', {'x': eid}) |
0 | 291 |
aff2 = cu.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
292 |
soc1 = cu.execute("INSERT Societe X: X nom 'chouette'")[0][0] |
|
293 |
cu.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
294 |
cnx.commit() |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
295 |
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
|
296 |
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
|
297 |
# 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
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
self.assertEqual(rset.rows, []) |
4765 | 302 |
# 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
|
303 |
self.assertRaises(Unauthorized, cu.execute, 'SET X sujet "hacked" WHERE X eid %(x)s', {'x': eid}) |
4765 | 304 |
|
305 |
||
306 |
def test_entity_created_in_transaction(self): |
|
307 |
affschema = self.schema['Affaire'] |
|
308 |
origperms = affschema.permissions['read'] |
|
309 |
affschema.set_action_permissions('read', affschema.permissions['add']) |
|
310 |
try: |
|
311 |
cnx = self.login('iaminusersgrouponly') |
|
312 |
cu = cnx.cursor() |
|
313 |
aff2 = cu.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
|
314 |
# 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
|
315 |
self.failUnless(cu.execute('Any X WHERE X eid %(x)s', {'x':aff2})) |
4765 | 316 |
# XXX would be nice if it worked |
317 |
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
|
318 |
self.assertEqual(len(rset), 0) |
4765 | 319 |
finally: |
320 |
affschema.set_action_permissions('read', origperms) |
|
321 |
cnx.close() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
322 |
|
0 | 323 |
def test_read_erqlexpr_has_text1(self): |
324 |
aff1 = self.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
|
325 |
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
|
326 |
self.execute('SET X owned_by U WHERE X eid %(x)s, U login "iaminusersgrouponly"', {'x': card1}) |
0 | 327 |
self.commit() |
328 |
cnx = self.login('iaminusersgrouponly') |
|
329 |
cu = cnx.cursor() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
330 |
aff2 = cu.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
0 | 331 |
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
|
332 |
cu.execute("SET A concerne S WHERE A eid %(a)s, S eid %(s)s", {'a': aff2, 's': soc1}) |
0 | 333 |
cnx.commit() |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
334 |
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
|
335 |
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
|
336 |
self.failUnless(cu.execute('Any X WHERE X eid %(x)s', {'x':card1})) |
0 | 337 |
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
|
338 |
self.assertEqual(sorted(eid for eid, in rset.rows), |
0 | 339 |
[card1, aff2]) |
340 |
||
341 |
def test_read_erqlexpr_has_text2(self): |
|
342 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
343 |
self.execute("INSERT Societe X: X nom 'bidule'") |
|
344 |
self.commit() |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
345 |
self.schema['Personne'].set_action_permissions('read', ('managers',)) |
0 | 346 |
cnx = self.login('iaminusersgrouponly') |
347 |
cu = cnx.cursor() |
|
348 |
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
|
349 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
0 | 350 |
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
|
351 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
0 | 352 |
|
353 |
def test_read_erqlexpr_optional_rel(self): |
|
354 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
355 |
self.execute("INSERT Societe X: X nom 'bidule'") |
|
356 |
self.commit() |
|
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
357 |
self.schema['Personne'].set_action_permissions('read', ('managers',)) |
0 | 358 |
cnx = self.login('anon') |
359 |
cu = cnx.cursor() |
|
360 |
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
|
361 |
self.assertEqual(len(rset.rows), 1, rset.rows) |
0 | 362 |
|
363 |
def test_read_erqlexpr_aggregat(self): |
|
364 |
self.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
|
365 |
self.commit() |
|
366 |
cnx = self.login('iaminusersgrouponly') |
|
367 |
cu = cnx.cursor() |
|
368 |
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
|
369 |
self.assertEqual(rset.rows, [[0]]) |
0 | 370 |
aff2 = cu.execute("INSERT Affaire X: X sujet 'cool'")[0][0] |
371 |
soc1 = cu.execute("INSERT Societe X: X nom 'chouette'")[0][0] |
|
372 |
cu.execute("SET A concerne S WHERE A is Affaire, S is Societe") |
|
373 |
cnx.commit() |
|
374 |
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
|
375 |
self.assertEqual(rset.rows, [[1]]) |
0 | 376 |
rset = cu.execute('Any ETN, COUNT(X) GROUPBY ETN WHERE X is ET, ET name ETN') |
377 |
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
|
378 |
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
|
379 |
self.assertEqual(values['Societe'], 2) |
0 | 380 |
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
|
381 |
self.assertEqual(len(rset), 2) |
0 | 382 |
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
|
383 |
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
|
384 |
self.assertEqual(values['Societe'], 2) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
385 |
|
0 | 386 |
|
387 |
def test_attribute_security(self): |
|
388 |
# only managers should be able to edit the 'test' attribute of Personne entities |
|
389 |
eid = self.execute("INSERT Personne X: X nom 'bidule', X web 'http://www.debian.org', X test TRUE")[0][0] |
|
390 |
self.commit() |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
391 |
self.execute('SET X test FALSE WHERE X eid %(x)s', {'x': eid}) |
0 | 392 |
self.commit() |
393 |
cnx = self.login('iaminusersgrouponly') |
|
394 |
cu = cnx.cursor() |
|
395 |
cu.execute("INSERT Personne X: X nom 'bidule', X web 'http://www.debian.org', X test TRUE") |
|
396 |
self.assertRaises(Unauthorized, cnx.commit) |
|
397 |
cu.execute("INSERT Personne X: X nom 'bidule', X web 'http://www.debian.org', X test FALSE") |
|
398 |
self.assertRaises(Unauthorized, cnx.commit) |
|
399 |
eid = cu.execute("INSERT Personne X: X nom 'bidule', X web 'http://www.debian.org'")[0][0] |
|
400 |
cnx.commit() |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
401 |
cu.execute('SET X test FALSE WHERE X eid %(x)s', {'x': eid}) |
0 | 402 |
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
|
403 |
cu.execute('SET X test TRUE WHERE X eid %(x)s', {'x': eid}) |
0 | 404 |
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
|
405 |
cu.execute('SET X web "http://www.logilab.org" WHERE X eid %(x)s', {'x': eid}) |
0 | 406 |
cnx.commit() |
407 |
cnx.close() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
408 |
|
0 | 409 |
def test_attribute_security_rqlexpr(self): |
410 |
# 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
|
411 |
note = self.execute("INSERT Note X: X para 'bidule'").get_entity(0, 0) |
0 | 412 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
413 |
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
|
414 |
self.execute('SET X para "truc" WHERE X eid %(x)s', {'x': note.eid}) |
0 | 415 |
self.commit() |
416 |
cnx = self.login('iaminusersgrouponly') |
|
417 |
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
|
418 |
cu.execute("SET X para 'chouette' WHERE X eid %(x)s", {'x': note.eid}) |
0 | 419 |
self.assertRaises(Unauthorized, cnx.commit) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
420 |
note2 = cu.execute("INSERT Note X: X para 'bidule'").get_entity(0, 0) |
0 | 421 |
cnx.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
422 |
note2.cw_adapt_to('IWorkflowable').fire_transition('markasdone') |
0 | 423 |
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
|
424 |
self.assertEqual(len(cu.execute('Any X WHERE X in_state S, S name "todo", X eid %(x)s', {'x': note2.eid})), |
0 | 425 |
0) |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
426 |
cu.execute("SET X para 'chouette' WHERE X eid %(x)s", {'x': note2.eid}) |
0 | 427 |
self.assertRaises(Unauthorized, cnx.commit) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
428 |
note2.cw_adapt_to('IWorkflowable').fire_transition('redoit') |
0 | 429 |
cnx.commit() |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
430 |
cu.execute("SET X para 'chouette' WHERE X eid %(x)s", {'x': note2.eid}) |
0 | 431 |
cnx.commit() |
432 |
||
433 |
def test_attribute_read_security(self): |
|
434 |
# 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
|
435 |
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
|
436 |
self.repo.schema['CWUser'].rdef('login').set_action_permissions('read', ('users', 'managers')) |
0 | 437 |
cnx = self.login('anon') |
438 |
cu = cnx.cursor() |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
389
diff
changeset
|
439 |
rset = cu.execute('CWUser X') |
0 | 440 |
self.failUnless(rset) |
441 |
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
|
442 |
self.assertEqual(x.login, None) |
0 | 443 |
self.failUnless(x.creation_date) |
444 |
x = rset.get_entity(1, 0) |
|
445 |
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
|
446 |
self.assertEqual(x.login, None) |
0 | 447 |
self.failUnless(x.creation_date) |
448 |
cnx.rollback() |
|
449 |
||
450 |
class BaseSchemaSecurityTC(BaseSecurityTC): |
|
451 |
"""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
|
452 |
|
0 | 453 |
def test_user_can_delete_object_he_created(self): |
454 |
# even if some other user have changed object'state |
|
455 |
cnx = self.login('iaminusersgrouponly') |
|
456 |
cu = cnx.cursor() |
|
457 |
# due to security test, affaire has to concerne a societe the user owns |
|
458 |
cu.execute('INSERT Societe X: X nom "ARCTIA"') |
|
459 |
cu.execute('INSERT Affaire X: X ref "ARCT01", X concerne S WHERE S nom "ARCTIA"') |
|
460 |
cnx.commit() |
|
461 |
self.restore_connection() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
462 |
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
|
463 |
affaire.cw_adapt_to('IWorkflowable').fire_transition('abort') |
0 | 464 |
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
|
465 |
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
|
466 |
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
|
467 |
self.assertEqual(len(self.execute('TrInfo X WHERE X wf_info_for A, A ref "ARCT01",' |
0 | 468 |
'X owned_by U, U login "admin"')), |
469 |
1) # TrInfo at the above state change |
|
470 |
cnx = self.login('iaminusersgrouponly') |
|
471 |
cu = cnx.cursor() |
|
472 |
cu.execute('DELETE Affaire X WHERE X ref "ARCT01"') |
|
473 |
cnx.commit() |
|
474 |
self.failIf(cu.execute('Affaire X')) |
|
475 |
||
476 |
def test_users_and_groups_non_readable_by_guests(self): |
|
477 |
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
|
478 |
anon = cnx.user(self.session) |
0 | 479 |
cu = cnx.cursor() |
480 |
# anonymous user can only read itself |
|
481 |
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
|
482 |
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
|
483 |
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
|
484 |
self.assertEqual(rset.rows, [[anon.eid]]) |
0 | 485 |
# 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
|
486 |
self.assert_(cu.execute('CWGroup X')) |
0 | 487 |
# 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
|
488 |
origuser = self.adminsession.user |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
489 |
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
|
490 |
cu.execute, 'CWUser X WHERE X eid %(x)s', {'x': origuser.eid}) |
0 | 491 |
# nothing selected, nothing updated, no exception raised |
492 |
#self.assertRaises(Unauthorized, |
|
493 |
# cu.execute, 'SET X login "toto" WHERE X eid %(x)s', |
|
494 |
# {'x': self.user.eid}) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
495 |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4915
diff
changeset
|
496 |
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
|
497 |
self.assertEqual(rset.rows, [[anon.eid]]) |
0 | 498 |
# 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
|
499 |
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
|
500 |
self.assertRaises(Unauthorized, cnx.commit) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
501 |
|
0 | 502 |
def test_in_group_relation(self): |
503 |
cnx = self.login('iaminusersgrouponly') |
|
504 |
cu = cnx.cursor() |
|
505 |
rql = u"DELETE U in_group G WHERE U login 'admin'" |
|
506 |
self.assertRaises(Unauthorized, cu.execute, rql) |
|
507 |
rql = u"SET U in_group G WHERE U login 'admin', G name 'users'" |
|
508 |
self.assertRaises(Unauthorized, cu.execute, rql) |
|
509 |
||
510 |
def test_owned_by(self): |
|
511 |
self.execute("INSERT Personne X: X nom 'bidule'") |
|
512 |
self.commit() |
|
513 |
cnx = self.login('iaminusersgrouponly') |
|
514 |
cu = cnx.cursor() |
|
515 |
rql = u"SET X owned_by U WHERE U login 'iaminusersgrouponly', X is Personne" |
|
516 |
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
|
517 |
|
0 | 518 |
def test_bookmarked_by_guests_security(self): |
519 |
beid1 = self.execute('INSERT Bookmark B: B path "?vid=manage", B title "manage"')[0][0] |
|
520 |
beid2 = self.execute('INSERT Bookmark B: B path "?vid=index", B title "index", B bookmarked_by U WHERE U login "anon"')[0][0] |
|
521 |
self.commit() |
|
522 |
cnx = self.login('anon') |
|
523 |
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
|
524 |
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
|
525 |
self.assertEqual(cu.execute('Any T,P ORDERBY lower(T) WHERE B is Bookmark,B title T,B path P,' |
0 | 526 |
'B bookmarked_by U, U eid %s' % anoneid).rows, |
527 |
[['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
|
528 |
self.assertEqual(cu.execute('Any T,P ORDERBY lower(T) WHERE B is Bookmark,B title T,B path P,' |
0 | 529 |
'B bookmarked_by U, U eid %(x)s', {'x': anoneid}).rows, |
530 |
[['index', '?vid=index']]) |
|
531 |
# 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
|
532 |
self.assertEqual(cu.execute('Any B where B is Bookmark, NOT B bookmarked_by U').rows, |
0 | 533 |
[[beid1]]) |
534 |
self.assertRaises(Unauthorized, cu.execute,'DELETE B bookmarked_by U') |
|
535 |
self.assertRaises(Unauthorized, |
|
536 |
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
|
537 |
{'x': anoneid, 'b': beid1}) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
538 |
|
0 | 539 |
|
540 |
def test_ambigous_ordered(self): |
|
541 |
cnx = self.login('anon') |
|
542 |
cu = cnx.cursor() |
|
543 |
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
|
544 |
self.assertEqual(names, sorted(names, key=lambda x: x.lower())) |
0 | 545 |
|
546 |
def test_in_state_without_update_perm(self): |
|
547 |
"""check a user change in_state without having update permission on the |
|
548 |
subject |
|
549 |
""" |
|
550 |
eid = self.execute('INSERT Affaire X: X ref "ARCT01"')[0][0] |
|
551 |
self.commit() |
|
552 |
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
|
553 |
session = self.session |
0 | 554 |
# needed to avoid check_perm error |
555 |
session.set_pool() |
|
556 |
# 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
|
557 |
affaire_perms = self.schema['Affaire'].permissions.copy() |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3252
diff
changeset
|
558 |
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
|
559 |
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
|
560 |
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
|
561 |
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
|
562 |
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
|
563 |
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
|
564 |
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
|
565 |
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
|
566 |
cnx.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
567 |
# though changing a user state (even logged user) is reserved to managers |
3447 | 568 |
user = cnx.user(self.session) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
569 |
# 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
|
570 |
# 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
|
571 |
# 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
|
572 |
self.assertRaises(ValidationError, |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
573 |
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
|
574 |
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
|
575 |
# 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
|
576 |
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
|
577 |
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
|
578 |
|
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
579 |
def test_trinfo_security(self): |
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
580 |
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
|
581 |
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
|
582 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
583 |
iworkflowable.fire_transition('abort') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2608
diff
changeset
|
584 |
self.commit() |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
585 |
# can change tr info comment |
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
586 |
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
|
587 |
{'c': u'bouh!'}) |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
588 |
self.commit() |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
589 |
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
|
590 |
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
|
591 |
self.assertEqual(trinfo.comment, 'bouh!') |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
592 |
# 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
|
593 |
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
|
594 |
self.assertRaises(Unauthorized, |
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
595 |
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
|
596 |
{'ti': trinfo.eid}) |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
597 |
self.assertRaises(Unauthorized, |
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
598 |
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
|
599 |
{'ti': trinfo.eid}) |
2501
fa86d99c2c3a
test and fix wf history security
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2500
diff
changeset
|
600 |
|
0 | 601 |
if __name__ == '__main__': |
602 |
unittest_main() |