1 """Tests for the CherryPy configuration system."""
4 localDir
= os
.path
.join(os
.getcwd(), os
.path
.dirname(__file__
))
13 from cherrypy
.test
import helper
15 class ServerConfigTests(helper
.CPWebCase
):
21 return cherrypy
.request
.wsgi_environ
['SERVER_PORT']
24 def upload(self
, file):
25 return "Size: %s" % len(file.file.read())
29 return cherrypy
.request
.body
.read()
30 tinyupload
.exposed
= True
31 tinyupload
._cp
_config
= {'request.body.maxbytes': 100}
33 cherrypy
.tree
.mount(Root())
35 cherrypy
.config
.update({
36 'server.socket_host': '0.0.0.0',
37 'server.socket_port': 9876,
38 'server.max_request_body_size': 200,
39 'server.max_request_header_size': 500,
40 'server.socket_timeout': 0.5,
42 # Test explicit server.instance
43 'server.2.instance': 'cherrypy._cpwsgi_server.CPWSGIServer',
44 'server.2.socket_port': 9877,
46 # Test non-numeric <servername>
47 # Also test default server.instance = builtin server
48 'server.yetanother.socket_port': 9878,
50 setup_server
= staticmethod(setup_server
)
54 def testBasicConfig(self
):
56 self
.assertBody(str(self
.PORT
))
58 def testAdditionalServers(self
):
59 if self
.scheme
== 'https':
60 return self
.skip("not available under ssl")
63 self
.assertBody(str(self
.PORT
))
66 self
.assertBody(str(self
.PORT
))
68 def testMaxRequestSizePerHandler(self
):
69 if getattr(cherrypy
.server
, "using_apache", False):
70 return self
.skip("skipped due to known Apache differences... ")
72 self
.getPage('/tinyupload', method
="POST",
73 headers
=[('Content-Type', 'text/plain'),
74 ('Content-Length', '100')],
76 self
.assertStatus(200)
77 self
.assertBody("x" * 100)
79 self
.getPage('/tinyupload', method
="POST",
80 headers
=[('Content-Type', 'text/plain'),
81 ('Content-Length', '101')],
83 self
.assertStatus(413)
85 def testMaxRequestSize(self
):
86 if getattr(cherrypy
.server
, "using_apache", False):
87 return self
.skip("skipped due to known Apache differences... ")
89 for size
in (500, 5000, 50000):
90 self
.getPage("/", headers
=[('From', "x" * 500)])
91 self
.assertStatus(413)
93 # Test for http://www.cherrypy.org/ticket/421
94 # (Incorrect border condition in readline of SizeCheckWrapper).
95 # This hangs in rev 891 and earlier.
98 headers
=[('Host', '%s:%s' % (self
.HOST
, self
.PORT
)),
104 'Content-Disposition: form-data; name="file"; filename="hello.txt"',
105 'Content-Type: text/plain',
109 partlen
= 200 - len(body
)
110 b
= body
% ("x" * partlen
)
111 h
= [("Content-type", "multipart/form-data; boundary=x"),
112 ("Content-Length", "%s" % len(b
))]
113 self
.getPage('/upload', h
, "POST", b
)
114 self
.assertBody('Size: %d' % partlen
)
116 b
= body
% ("x" * 200)
117 h
= [("Content-type", "multipart/form-data; boundary=x"),
118 ("Content-Length", "%s" % len(b
))]
119 self
.getPage('/upload', h
, "POST", b
)
120 self
.assertStatus(413)