Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 140 lines (116 sloc) 4.252 kB
a163d5d @davidjb Use FCGI and Python instead of PHP for QA test 299
davidjb authored
1 import os
e6d7fa9 @davidjb Ensuring that HTTP methods accept request bodies in accordance with v…
davidjb authored
2 from base import *
3
a163d5d @davidjb Use FCGI and Python instead of PHP for QA test 299
davidjb authored
4 DIR = "/299-MethodsRequestBodyHandling/"
e6d7fa9 @davidjb Ensuring that HTTP methods accept request bodies in accordance with v…
davidjb authored
5 MAGIC = "Report bugs to http://bugs.cherokee-project.com"
a163d5d @davidjb Use FCGI and Python instead of PHP for QA test 299
davidjb authored
6 PORT = get_free_port()
7 PYTHON = look_for_python()
8 SOURCE = get_next_source()
e6d7fa9 @davidjb Ensuring that HTTP methods accept request bodies in accordance with v…
davidjb authored
9
10 METHODS = {
11 'required': [
12 'POST',
13 'PUT',
14 'MERGE',
15 'SEARCH',
16 'REPORT',
17 'PATCH',
18 'PROPFIND',
19 'PROPPATCH',
20 'UPDATE',
21 'LABEL',
22 ],
23 'optional': [
24 'OPTIONS',
25 'DELETE',
26 'MKCOL',
27 'COPY',
28 'MOVE',
29 'LOCK',
30 'UNLOCK',
31 'VERSION-CONTROL',
32 'CHECKOUT',
33 'UNCHECKOUT',
34 'CHECKIN',
35 'MKWORKSPACE',
36 'MKACTIVITY',
37 'BASELINE-CONTROL',
38 ]
39 }
40
41 CONF = """
a163d5d @davidjb Use FCGI and Python instead of PHP for QA test 299
davidjb authored
42 vserver!1!rule!2990!match = directory
43 vserver!1!rule!2990!match!directory = %(DIR)s
44 vserver!1!rule!2990!handler = fcgi
45 vserver!1!rule!2990!handler!check_file = 0
46 vserver!1!rule!2990!handler!balancer = round_robin
47 vserver!1!rule!2990!handler!balancer!source!1 = %(SOURCE)d
48
49 source!%(SOURCE)d!type = interpreter
50 source!%(SOURCE)d!host = localhost:%(PORT)d
51 source!%(SOURCE)d!interpreter = %(PYTHON)s %(fcgi_file)s
52 """
53
54 SCRIPT = """
55 from fcgi import *
56
57 def app (environ, start_response):
58 start_response('200 OK', [("Content-Type", "text/plain")])
59
60 response = "Method: %%s\\n" %% environ['REQUEST_METHOD']
61 if 'CONTENT_LENGTH' in environ:
62 request_body_size = int(environ.get('CONTENT_LENGTH', 0))
63 request_body = environ['wsgi.input'].read(request_body_size)
64 response += "Body: %%s\\n" %% request_body
65
66 return [response]
67
68 WSGIServer(app, bindAddress=("localhost",%d)).run()
69 """ % (PORT)
e6d7fa9 @davidjb Ensuring that HTTP methods accept request bodies in accordance with v…
davidjb authored
70
71
72 class TestEntry (TestBase):
73 """Test for HTTP methods with required and optional request bodies being
74 received and processed correctly by Cherokee.
75 """
76
77 def __init__ (self, method, send_input, input_required):
78 TestBase.__init__ (self, __file__)
a163d5d @davidjb Use FCGI and Python instead of PHP for QA test 299
davidjb authored
79 self.request = "%s %s HTTP/1.0\r\n" % (method, DIR) +\
e6d7fa9 @davidjb Ensuring that HTTP methods accept request bodies in accordance with v…
davidjb authored
80 "Content-type: text/xml\r\n"
81 self.expected_content = []
82
83 if input_required and not send_input:
84 self.expected_error = 411
85 else:
86 self.expected_error = 200
87 self.expected_content.append("Method: %s" % method)
88
89 if send_input:
90 self.request += "Content-length: %d\r\n" % (len(MAGIC))
91 self.post = MAGIC
92 self.expected_content.append("Body: %s" % MAGIC)
93 else:
94 self.forbidden_content = 'Body:'
95
96
97 class Test (TestCollection):
98
99 def __init__ (self):
100 TestCollection.__init__ (self, __file__)
101 self.name = "Method Request Body Handling"
102
103 def Prepare (self, www):
a163d5d @davidjb Use FCGI and Python instead of PHP for QA test 299
davidjb authored
104 fcgi_file = self.WriteFile (www, "fcgi_test_methods.cgi", 0444, SCRIPT)
105
106 fcgi = os.path.join (www, 'fcgi.py')
107 if not os.path.exists (fcgi):
108 self.CopyFile ('fcgi.py', fcgi)
109
110 vars = globals()
111 vars['fcgi_file'] = fcgi_file
112 self.conf = CONF % (vars)
e6d7fa9 @davidjb Ensuring that HTTP methods accept request bodies in accordance with v…
davidjb authored
113
114 def JustBefore (self, www):
115 # Create sub-request objects
116 self.Empty ()
117
118 # Create all tests with different methods - all methods
119 # should only work with request bodies. With no request
120 # body a 411 Length Required should result.
121 for method in METHODS['required']:
122 self.Add (TestEntry (method=method,
123 send_input=True,
124 input_required=True))
125 self.Add (TestEntry (method=method,
126 send_input=False,
127 input_required=True))
128
129 # Create all tests with different methods - all methods
130 # should work with and without request bodies.
131 for method in METHODS['optional']:
132 #Test method when for when sending a request body
133 self.Add (TestEntry (method=method,
134 send_input=True,
135 input_required=False))
136 #Test method when not sending a request body
137 self.Add (TestEntry (method=method,
138 send_input=False,
139 input_required=False))
Something went wrong with that request. Please try again.