diff options
Diffstat (limited to 'pecan/tests')
-rw-r--r-- | pecan/tests/test_base.py | 17 | ||||
-rw-r--r-- | pecan/tests/test_rest.py | 26 |
2 files changed, 41 insertions, 2 deletions
diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py index cca494c..1369837 100644 --- a/pecan/tests/test_base.py +++ b/pecan/tests/test_base.py @@ -146,6 +146,23 @@ class TestAppIterFile(PecanTestCase): assert len(r.body) == 0 +class TestInvalidURLEncoding(PecanTestCase): + + @property + def app_(self): + class RootController(object): + + @expose() + def _route(self, args, request): + assert request.path + + return TestApp(Pecan(RootController())) + + def test_rest_with_non_utf_8_body(self): + r = self.app_.get('/%aa/', expect_errors=True) + assert r.status_int == 400 + + class TestIndexRouting(PecanTestCase): @property diff --git a/pecan/tests/test_rest.py b/pecan/tests/test_rest.py index d839084..391b7d0 100644 --- a/pecan/tests/test_rest.py +++ b/pecan/tests/test_rest.py @@ -1,11 +1,12 @@ -from webtest import TestApp +import struct import warnings try: from simplejson import dumps, loads except: from json import dumps, loads # noqa -from six import b as b_ +from six import b as b_, PY3 +from webtest import TestApp from pecan import abort, expose, make_app, response, redirect from pecan.rest import RestController @@ -1359,6 +1360,27 @@ class TestRestController(PecanTestCase): assert r.status_int == 200 assert r.body == b_("DEFAULT missing") + def test_rest_with_non_utf_8_body(self): + if PY3: + # webob+PY3 doesn't suffer from this bug; the POST parsing in PY3 + # seems to more gracefully detect the bytestring + return + + class FooController(RestController): + + @expose() + def post(self): + return "POST" + + class RootController(RestController): + foo = FooController() + + app = TestApp(make_app(RootController())) + + data = struct.pack('255h', *range(0, 255)) + r = app.post('/foo/', data, expect_errors=True) + assert r.status_int == 400 + def test_dynamic_rest_lookup(self): class BarController(RestController): @expose() |