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