author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Fri, 22 Mar 2013 20:10:19 +0100 | |
changeset 8773 | 21edcb0a5ed7 |
parent 8695 | 358d8bed9626 |
child 9809 | 29d52a785729 |
permissions | -rw-r--r-- |
8605
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
1 |
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
3 |
# |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
4 |
# This file is part of CubicWeb. |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
5 |
# |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
9 |
# any later version. |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
10 |
# |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
14 |
# details. |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
15 |
# |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
18 |
|
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
19 |
from logilab.common.testlib import unittest_main |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
20 |
from logilab.mtconverter import html_unescape |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
21 |
|
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
22 |
from cubicweb import Forbidden, ValidationError |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
23 |
from cubicweb.devtools.testlib import CubicWebTC |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
24 |
from cubicweb.utils import json |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
25 |
from cubicweb.view import StartupView, TRANSITIONAL_DOCTYPE_NOEXT |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
26 |
from cubicweb.web import Redirect |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
27 |
from cubicweb.web.htmlwidgets import TableWidget |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
28 |
from cubicweb.web.views import vid_from_rset |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
29 |
|
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
30 |
import re |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
31 |
import hmac |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
32 |
|
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
33 |
class ErrorViewTC(CubicWebTC): |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
34 |
def setUp(self): |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
35 |
super(ErrorViewTC, self).setUp() |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
36 |
self.req = self.request() |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
37 |
self.vreg.config['submit-mail'] = "test@logilab.fr" |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
38 |
self.vreg.config['print-traceback'] = "yes" |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
39 |
|
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
40 |
def test_error_generation(self): |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
41 |
""" |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
42 |
tests |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
43 |
""" |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
44 |
|
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
45 |
class MyWrongView(StartupView): |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
46 |
__regid__ = 'my-view' |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
47 |
def call(self): |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
48 |
raise ValueError('This is wrong') |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
49 |
|
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
50 |
with self.temporary_appobjects(MyWrongView): |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
51 |
try: |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
52 |
self.view('my-view') |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8694
diff
changeset
|
53 |
except Exception as e: |
8605
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
54 |
import sys |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
55 |
self.req.data['excinfo'] = sys.exc_info() |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
56 |
self.req.data['ex'] = e |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
57 |
html = self.view('error', req=self.req) |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
58 |
self.failUnless(re.search(r'^<input name="__signature" type="hidden" value="[0-9a-f]{32}" />$', |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
59 |
html.source, re.M)) |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
60 |
|
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
61 |
|
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
62 |
def test_error_submit_nosig(self): |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
63 |
""" |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
64 |
tests that the reportbug controller refuses submission if |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
65 |
there is not content signature |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
66 |
""" |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
67 |
|
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
68 |
self.req.form = {'description': u'toto', |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
69 |
} |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
70 |
with self.assertRaises(Forbidden) as cm: |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
71 |
self.ctrl_publish(self.req, 'reportbug') |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
72 |
|
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
73 |
def test_error_submit_wrongsig(self): |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
74 |
""" |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
75 |
tests that the reportbug controller refuses submission if the |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
76 |
content signature is invalid |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
77 |
""" |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
78 |
|
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
79 |
self.req.form = {'__signature': 'X', |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
80 |
'description': u'toto', |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
81 |
} |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
82 |
with self.assertRaises(Forbidden) as cm: |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
83 |
self.ctrl_publish(self.req, 'reportbug') |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
84 |
|
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
85 |
def test_error_submit_ok(self): |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
86 |
""" |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
87 |
tests that the reportbug controller accept the email submission if the |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
88 |
content signature is valid |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
89 |
""" |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
90 |
|
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
91 |
sign = self.vreg.config.sign_text('toto') |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
92 |
self.req.form = {'__signature': sign, |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
93 |
'description': u'toto', |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
94 |
} |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
95 |
with self.assertRaises(Redirect) as cm: |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
96 |
self.ctrl_publish(self.req, 'reportbug') |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
97 |
|
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
98 |
if __name__ == '__main__': |
797fc2e2fb78
[web] add a digital signature to error form (closes #2522526)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
99 |
unittest_main() |