author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 07 Mar 2011 10:41:04 +0100 | |
branch | stable |
changeset 7039 | df0e8581b06f |
parent 6750 | ef513c03a224 |
child 7888 | e257b4476454 |
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:
4891
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:
4891
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:
4891
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:
4891
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:
4891
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:
4891
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:
4891
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:
4891
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:
4891
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:
4891
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:
4891
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:
4891
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:
4891
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:
4891
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:
4891
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:
4891
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
4891
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
18 |
from logilab.common.testlib import TestCase, unittest_main |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
19 |
from cubicweb.req import RequestSessionBase |
6321
a8a33679f4dd
[req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5424
diff
changeset
|
20 |
from cubicweb.devtools.testlib import CubicWebTC |
6747
63bf61e4e130
[security] fix access control problem
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
21 |
from cubicweb import Unauthorized |
4891
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
22 |
|
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
23 |
class RebuildURLTC(TestCase): |
6321
a8a33679f4dd
[req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5424
diff
changeset
|
24 |
def test_rebuild_url(self): |
4891
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
25 |
rebuild_url = RequestSessionBase(None).rebuild_url |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6321
diff
changeset
|
26 |
self.assertEqual(rebuild_url('http://logilab.fr?__message=pouet', __message='hop'), |
4891
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
27 |
'http://logilab.fr?__message=hop') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6321
diff
changeset
|
28 |
self.assertEqual(rebuild_url('http://logilab.fr', __message='hop'), |
4891
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
29 |
'http://logilab.fr?__message=hop') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6321
diff
changeset
|
30 |
self.assertEqual(rebuild_url('http://logilab.fr?vid=index', __message='hop'), |
4891
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
31 |
'http://logilab.fr?__message=hop&vid=index') |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
32 |
|
6321
a8a33679f4dd
[req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5424
diff
changeset
|
33 |
def test_build_url(self): |
a8a33679f4dd
[req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5424
diff
changeset
|
34 |
req = RequestSessionBase(None) |
a8a33679f4dd
[req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5424
diff
changeset
|
35 |
req.from_controller = lambda : 'view' |
a8a33679f4dd
[req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5424
diff
changeset
|
36 |
req.relative_path = lambda includeparams=True: None |
a8a33679f4dd
[req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5424
diff
changeset
|
37 |
req.base_url = lambda : 'http://testing.fr/cubicweb/' |
a8a33679f4dd
[req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5424
diff
changeset
|
38 |
self.assertEqual(req.build_url(), u'http://testing.fr/cubicweb/view') |
a8a33679f4dd
[req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5424
diff
changeset
|
39 |
self.assertEqual(req.build_url(None), u'http://testing.fr/cubicweb/view') |
a8a33679f4dd
[req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5424
diff
changeset
|
40 |
self.assertEqual(req.build_url('one'), u'http://testing.fr/cubicweb/one') |
a8a33679f4dd
[req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5424
diff
changeset
|
41 |
self.assertEqual(req.build_url(param='ok'), u'http://testing.fr/cubicweb/view?param=ok') |
a8a33679f4dd
[req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5424
diff
changeset
|
42 |
self.assertRaises(AssertionError, req.build_url, 'one', 'two not allowed') |
6595
00cd0b273cf5
[test] fix test to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
43 |
self.assertRaises(AssertionError, req.build_url, 'view', test=None) |
6321
a8a33679f4dd
[req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5424
diff
changeset
|
44 |
|
6747
63bf61e4e130
[security] fix access control problem
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
45 |
def test_ensure_no_rql(self): |
63bf61e4e130
[security] fix access control problem
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
46 |
req = RequestSessionBase(None) |
63bf61e4e130
[security] fix access control problem
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
47 |
self.assertEqual(req.ensure_ro_rql('Any X WHERE X is CWUser'), None) |
63bf61e4e130
[security] fix access control problem
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
48 |
self.assertEqual(req.ensure_ro_rql(' Any X WHERE X is CWUser '), None) |
63bf61e4e130
[security] fix access control problem
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
49 |
self.assertRaises(Unauthorized, req.ensure_ro_rql, 'SET X login "toto" WHERE X is CWUser') |
63bf61e4e130
[security] fix access control problem
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
50 |
self.assertRaises(Unauthorized, req.ensure_ro_rql, ' SET X login "toto" WHERE X is CWUser ') |
4891
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
51 |
|
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
52 |
if __name__ == '__main__': |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
53 |
unittest_main() |