Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change QA test 299 to use Python/FCGI rather than PHP #30

Merged
merged 1 commit into from Sep 3, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 43 additions & 21 deletions qa/299-MethodsRequestBodyHandling.py
@@ -1,7 +1,11 @@
import os
from base import *

DIR = "299-MethodsRequestBodyHandling"
DIR = "/299-MethodsRequestBodyHandling/"
MAGIC = "Report bugs to http://bugs.cherokee-project.com"
PORT = get_free_port()
PYTHON = look_for_python()
SOURCE = get_next_source()

METHODS = {
'required': [
Expand Down Expand Up @@ -35,10 +39,34 @@
}

CONF = """
vserver!1!rule!1280!match = directory
vserver!1!rule!1280!match!directory = /%s
vserver!1!rule!1280!handler = common
""" % (DIR)
vserver!1!rule!2990!match = directory
vserver!1!rule!2990!match!directory = %(DIR)s
vserver!1!rule!2990!handler = fcgi
vserver!1!rule!2990!handler!check_file = 0
vserver!1!rule!2990!handler!balancer = round_robin
vserver!1!rule!2990!handler!balancer!source!1 = %(SOURCE)d

source!%(SOURCE)d!type = interpreter
source!%(SOURCE)d!host = localhost:%(PORT)d
source!%(SOURCE)d!interpreter = %(PYTHON)s %(fcgi_file)s
"""

SCRIPT = """
from fcgi import *

def app (environ, start_response):
start_response('200 OK', [("Content-Type", "text/plain")])

response = "Method: %%s\\n" %% environ['REQUEST_METHOD']
if 'CONTENT_LENGTH' in environ:
request_body_size = int(environ.get('CONTENT_LENGTH', 0))
request_body = environ['wsgi.input'].read(request_body_size)
response += "Body: %%s\\n" %% request_body

return [response]

WSGIServer(app, bindAddress=("localhost",%d)).run()
""" % (PORT)


class TestEntry (TestBase):
Expand All @@ -48,7 +76,7 @@ class TestEntry (TestBase):

def __init__ (self, method, send_input, input_required):
TestBase.__init__ (self, __file__)
self.request = "%s /%s/ HTTP/1.0\r\n" % (method, DIR) +\
self.request = "%s %s HTTP/1.0\r\n" % (method, DIR) +\
"Content-type: text/xml\r\n"
self.expected_content = []

Expand All @@ -70,24 +98,18 @@ class Test (TestCollection):

def __init__ (self):
TestCollection.__init__ (self, __file__)

self.name = "Method Request Body Handling"
self.conf = CONF
self.proxy_suitable = True

def Prepare (self, www):
d = self.Mkdir (www, DIR)
f = self.WriteFile (d, "test_index.php", 0444,
"""
<?php echo 'Method: '.$_SERVER['REQUEST_METHOD']; ?>

<?php
$body = @file_get_contents('php://input');
if (strlen($body) > 0):
echo "Body: $body";
endif;
?>
""")
fcgi_file = self.WriteFile (www, "fcgi_test_methods.cgi", 0444, SCRIPT)

fcgi = os.path.join (www, 'fcgi.py')
if not os.path.exists (fcgi):
self.CopyFile ('fcgi.py', fcgi)

vars = globals()
vars['fcgi_file'] = fcgi_file
self.conf = CONF % (vars)

def JustBefore (self, www):
# Create sub-request objects
Expand Down