1
"""Basic tests for the CherryPy core: request handling."""
3
from cherrypy.test import test
4
test.prefer_parent_path()
11
from cherrypy.lib import safemime
16
def flashupload(self, Filedata, Upload, Filename):
17
return ("Upload: %r, Filename: %r, Filedata: %r" %
18
(Upload, Filename, Filedata.file.read()))
19
flashupload.exposed = True
20
flashupload._cp_config = {'tools.safe_multipart.on': True}
22
cherrypy.config.update({
23
'environment': 'test_suite',
24
'server.max_request_body_size': 0,
26
cherrypy.tree.mount(Root())
31
from cherrypy.test import helper
33
class SafeMultipartHandlingTest(helper.CPWebCase):
35
def test_Flash_Upload(self):
38
('Content-Type', 'multipart/form-data; '
39
'boundary=----------KM7Ij5cH2KM7Ef1gL6ae0ae0cH2gL6'),
40
('User-Agent', 'Shockwave Flash'),
41
('Host', 'www.example.com:8080'),
42
('Content-Length', '499'),
43
('Connection', 'Keep-Alive'),
44
('Cache-Control', 'no-cache'),
46
filedata = ('<?xml version="1.0" encoding="UTF-8"?>\r\n'
47
'<projectDescription>\r\n'
48
'</projectDescription>\r\n')
50
'------------KM7Ij5cH2KM7Ef1gL6ae0ae0cH2gL6\r\n'
51
'Content-Disposition: form-data; name="Filename"\r\n'
54
'------------KM7Ij5cH2KM7Ef1gL6ae0ae0cH2gL6\r\n'
55
'Content-Disposition: form-data; '
56
'name="Filedata"; filename=".project"\r\n'
57
'Content-Type: application/octet-stream\r\n'
61
'------------KM7Ij5cH2KM7Ef1gL6ae0ae0cH2gL6\r\n'
62
'Content-Disposition: form-data; name="Upload"\r\n'
65
# Flash apps omit the trailing \r\n on the last line:
66
'------------KM7Ij5cH2KM7Ef1gL6ae0ae0cH2gL6--'
68
self.getPage('/flashupload', headers, "POST", body)
69
self.assertBody("Upload: 'Submit Query', Filename: '.project', "
70
"Filedata: %r" % filedata)
73
if __name__ == '__main__':