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