| 1 |
""" |
|---|
| 2 |
Copyright (c) 2004, CherryPy Team (team@cherrypy.org) |
|---|
| 3 |
All rights reserved. |
|---|
| 4 |
|
|---|
| 5 |
Redistribution and use in source and binary forms, with or without modification, |
|---|
| 6 |
are permitted provided that the following conditions are met: |
|---|
| 7 |
|
|---|
| 8 |
* Redistributions of source code must retain the above copyright notice, |
|---|
| 9 |
this list of conditions and the following disclaimer. |
|---|
| 10 |
* Redistributions in binary form must reproduce the above copyright notice, |
|---|
| 11 |
this list of conditions and the following disclaimer in the documentation |
|---|
| 12 |
and/or other materials provided with the distribution. |
|---|
| 13 |
* Neither the name of the CherryPy Team nor the names of its contributors |
|---|
| 14 |
may be used to endorse or promote products derived from this software |
|---|
| 15 |
without specific prior written permission. |
|---|
| 16 |
|
|---|
| 17 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|---|
| 18 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|---|
| 19 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|---|
| 20 |
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
|---|
| 21 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|---|
| 22 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|---|
| 23 |
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|---|
| 24 |
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|---|
| 25 |
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|---|
| 26 |
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 27 |
""" |
|---|
| 28 |
|
|---|
| 29 |
import cherrypy |
|---|
| 30 |
|
|---|
| 31 |
class Root: |
|---|
| 32 |
def index(self): |
|---|
| 33 |
yield "Hello, world" |
|---|
| 34 |
index.exposed = True |
|---|
| 35 |
|
|---|
| 36 |
def bug326(self, file): |
|---|
| 37 |
return "OK" |
|---|
| 38 |
bug326.exposed = True |
|---|
| 39 |
|
|---|
| 40 |
cherrypy.root = Root() |
|---|
| 41 |
|
|---|
| 42 |
cherrypy.config.update({ |
|---|
| 43 |
'session.storageType': 'ram', |
|---|
| 44 |
'session.timeout': 60, |
|---|
| 45 |
'session.cleanUpDelay': 60, |
|---|
| 46 |
'session.cookieName': 'CherryPySession', |
|---|
| 47 |
'session.storageFileDir': '', |
|---|
| 48 |
|
|---|
| 49 |
'server.logToScreen': False, |
|---|
| 50 |
'server.environment': 'production', |
|---|
| 51 |
'logDebugInfoFilter.on': True, |
|---|
| 52 |
}) |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
import helper |
|---|
| 57 |
|
|---|
| 58 |
class LogDebugInfoFilterTest(helper.CPWebCase): |
|---|
| 59 |
|
|---|
| 60 |
def testLogDebugInfoFilter(self): |
|---|
| 61 |
self.getPage('/') |
|---|
| 62 |
self.assertInBody('Build time') |
|---|
| 63 |
self.assertInBody('Page size') |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
def testBug326(self): |
|---|
| 68 |
httpcls = cherrypy.server.httpserverclass |
|---|
| 69 |
if httpcls and httpcls.__name__ == "WSGIServer": |
|---|
| 70 |
h = [("Content-type", "multipart/form-data; boundary=x"), |
|---|
| 71 |
("Content-Length", "110")] |
|---|
| 72 |
b = """--x |
|---|
| 73 |
Content-Disposition: form-data; name="file"; filename="hello.txt" |
|---|
| 74 |
Content-Type: text/plain |
|---|
| 75 |
|
|---|
| 76 |
hello |
|---|
| 77 |
--x-- |
|---|
| 78 |
""" |
|---|
| 79 |
cherrypy.config.update({ |
|---|
| 80 |
'/bug326': {'server.maxRequestBodySize': 3, |
|---|
| 81 |
'server.environment': 'development', |
|---|
| 82 |
} |
|---|
| 83 |
}) |
|---|
| 84 |
ignore = helper.webtest.ignored_exceptions |
|---|
| 85 |
ignore.append(AttributeError) |
|---|
| 86 |
try: |
|---|
| 87 |
self.getPage('/bug326', h, "POST", b) |
|---|
| 88 |
self.assertStatus("413 Request Entity Too Large") |
|---|
| 89 |
finally: |
|---|
| 90 |
ignore.pop() |
|---|
| 91 |
|
|---|
| 92 |
if __name__ == "__main__": |
|---|
| 93 |
helper.testmain() |
|---|