From e50b68c0d28cb00fa627525f23bb0c0f614b9312 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Fri, 11 Jan 2013 00:10:56 -0500 Subject: Support for SSL in wsgi.Service Enable support for SSL as well using code from glance. We have some new options for configuring the SSL support. test_app starts wsgi.Service with a test app, then creates a url to make sure the http requests are actually served properly test_app_using_router adds wsgi.Router and Mapper() to the mix along with using the wsgify annotation for serving the http requests Fixes LP# 979488 (partial) Fixes LP# 869884 (partial) DocImpact Change-Id: Iae47b13b50e00c102c8c36f4a3e73b24fa4e6303 --- tests/unit/test_wsgi.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'tests/unit') diff --git a/tests/unit/test_wsgi.py b/tests/unit/test_wsgi.py index 749d524..e4f975e 100644 --- a/tests/unit/test_wsgi.py +++ b/tests/unit/test_wsgi.py @@ -16,12 +16,20 @@ # under the License. import mock +import os +import routes +import ssl +import urllib2 import webob from openstack.common import exception from openstack.common import wsgi +from openstack.common import cfg from tests import utils +TEST_VAR_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), + '..', 'var')) + class RequestTest(utils.BaseTestCase): @@ -471,3 +479,64 @@ class WSGIServerTest(utils.BaseTestCase): self.assertEqual("0.0.0.0", server.host) self.assertNotEqual(0, server.port) server.stop() + + def test_app(self): + greetings = 'Hello, World!!!' + + def hello_world(env, start_response): + if env['PATH_INFO'] != '/': + start_response('404 Not Found', + [('Content-Type', 'text/plain')]) + return ['Not Found\r\n'] + start_response('200 OK', [('Content-Type', 'text/plain')]) + return [greetings] + + server = wsgi.Service(hello_world, 0) + server.start() + + response = urllib2.urlopen('http://127.0.0.1:%d/' % server.port) + self.assertEquals(greetings, response.read()) + + server.stop() + + def test_app_using_router(self): + greetings = 'Hello, World!!!' + + @webob.dec.wsgify + def hello(req): + return greetings + + mapper = routes.Mapper() + mapper.connect(None, "/v1.0/{path_info:.*}", controller=hello) + router = wsgi.Router(mapper) + server = wsgi.Service(router, 0) + server.start() + + response = urllib2.urlopen('http://127.0.0.1:%d/v1.0/' % server.port) + self.assertEquals(greetings, response.read()) + + server.stop() + + def test_app_using_router_ssl(self): + + self.config(cert_file=os.path.join(TEST_VAR_DIR, 'certificate.crt'), + group="ssl") + self.config(key_file=os.path.join(TEST_VAR_DIR, 'privatekey.key'), + group="ssl") + + greetings = 'Hello, World!!!' + + @webob.dec.wsgify + def hello(req): + return greetings + + mapper = routes.Mapper() + mapper.connect(None, "/v1.0/{path_info:.*}", controller=hello) + router = wsgi.Router(mapper) + server = wsgi.Service(router, 0, host="127.0.0.1") + server.start() + + response = urllib2.urlopen('https://127.0.0.1:%d/v1.0/' % server.port) + self.assertEquals(greetings, response.read()) + + server.stop() -- cgit