Rev 50: Setup an apache2 based https test server. in http://bazaar.launchpad.net/%7Evila/bzr/local-test-server
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Feb 9 13:09:21 GMT 2009
At http://bazaar.launchpad.net/%7Evila/bzr/local-test-server
------------------------------------------------------------
revno: 50
revision-id: v.ladeuil+lp at free.fr-20090209130917-mmm5019gm67kcgo7
parent: v.ladeuil+lp at free.fr-20090209110313-1iy63hc7j8ceov8i
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: local-test-server
timestamp: Mon 2009-02-09 14:09:17 +0100
message:
Setup an apache2 based https test server.
* tests/test_utils.py:
(full_scenarios): The apache2 https variant.
* tests/test_config.py:
(TestConfigApache2HTTPS): Dedicated tests.
* test_server.py:
(Apache2HTTPSFeature): Dedicated feature.
(Apache2HTTPS, Apache2HTTPS_urllib): Dedicated test servers for
pycurl and urllib.
(get_test_permutations): Inject test permutations if an https
server is available.
* server.py:
(Apache2HTTPS): An apache2 based https server, we copy the
certificate and its key just before the server starts, so it's
still possible to define different servers with different
certificates from there.
* configs/apache2-https.conf:
A simple https apache2 server. Note that the certificate and its
key are still definitions are still outside this
configutation (i.e. that configuraton doesn't make assumptions
about them).
* config.py:
(Apache2HTTPS): Add https to an apache2 configuration.
-------------- next part --------------
=== modified file 'config.py'
--- a/config.py 2008-10-01 12:51:07 +0000
+++ b/config.py 2009-02-09 13:09:17 +0000
@@ -89,6 +89,7 @@
except ValueError, e:
# FIXME: This need tests (and a traceback is ugly)
raise SyntaxError('At line %d Error: %s' % (line_num + 1, e))
+
def ensure_required_dirs_exist(self):
for dir in self.required_dirs.keys():
try:
@@ -129,6 +130,20 @@
required_dirs=self._required_dirs, _base_dir=_base_dir,)
+class Apache2HTTPS(Apache2):
+
+ def __init__(self, _base_dir=None):
+ super(Apache2HTTPS, self).__init__(
+ 'apache2-https',
+ required_dirs=self._required_dirs, _base_dir=_base_dir,)
+ crt = 'server.crt'
+ key = 'server_without_pass.key'
+ self.values['certificate_name'] = crt
+ self.values['certificate_key_name'] = key
+ self.values['certificate_path'] = self.abspath('etc/%s' % crt)
+ self.values['certificate_key_path'] = self.abspath('etc/%s' % key)
+
+
class Apache2SVN(Apache2):
def __init__(self, _base_dir=None):
=== added file 'configs/apache2-https.conf'
--- a/configs/apache2-https.conf 1970-01-01 00:00:00 +0000
+++ b/configs/apache2-https.conf 2009-02-09 13:09:17 +0000
@@ -0,0 +1,55 @@
+#
+# Based on /etc/apache2/apache2.conf in Ubuntu Gusty
+#
+
+# This file will be interpolated by python see plugin source for
+# details.
+
+# Note that most of the directories below are usually owned by
+# root. We want directories writable by the user running the
+# tests.
+
+ServerRoot "%(base_dir)s"
+
+LockFile "%(var_lock_dir)s/accept.lock
+
+PidFile %(pid_file)s
+
+ErrorLog %(log_file)s
+LogFormat "%%h %%l %%u %%t \"%%r\" %%>s %%b \"%%{Referer}i\" \"%%{User-Agent}i\"" combined
+CustomLog %(var_log_dir)s/access.log combined
+LogLevel debug
+
+ServerName %(host)s
+Listen %(port)s
+
+# The following directives seems to activate the smallest apache2
+# server possible. If you know better, comments are very welcome.
+# More info at
+# http://localhost/doc/apache2-doc/manual/mod/worker.html
+StartServers 1
+MaxClients 5
+ThreadsPerChild 5
+
+# Tests will create symlinks in that directory to point to the
+# appropriate location
+DocumentRoot %(data_dir)s
+
+# required for
+#bzrlib.tests.test_transport_implementations.TransportTests.test_has_root_works
+LoadModule dir_module /usr/lib/apache2/modules/mod_dir.so
+LoadModule autoindex_module /usr/lib/apache2/modules/mod_autoindex.so
+
+# the following may help for debug
+ServerSignature On
+
+# SSL
+LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so
+<VirtualHost *:%(port)s>
+ ServerName %(host)s
+ SSLEngine On
+ # The following are copied from bzrlib/tests/ssl_certs when available
+ # (the server is *not* available if these files aren't)
+ SSLCertificateFile %(certificate_path)s
+ SSLCertificateKeyFile %(certificate_key_path)s
+</VirtualHost>
=== modified file 'server.py'
--- a/server.py 2008-10-01 12:51:07 +0000
+++ b/server.py 2009-02-09 13:09:17 +0000
@@ -32,6 +32,7 @@
from bzrlib import (
errors,
osutils,
+ tests,
)
@@ -90,6 +91,7 @@
else:
self.extra = ''
+
def locate_program(name, PATH=None):
"""Locates a program in PATH.
@@ -116,6 +118,7 @@
return full_path
return None
+
class Server(object):
# The command used to start the server
@@ -428,6 +431,53 @@
self.output_config_path = self.config.abspath('etc/apache2-dav.conf')
+class Apache2HTTPS(Apache2):
+
+ def __init__(self, port, _conf=None):
+ if _conf is None:
+ _conf = config.Apache2HTTPS()
+ super(Apache2HTTPS, self).__init__(port, _conf=_conf)
+ self.output_config_path = self.config.abspath('etc/apache2-https.conf')
+
+ def _start(self):
+ # We must provide the server certificate and key files before we can
+ # start, if we can't provide them, we can't start
+ try:
+ from bzrlib.tests import ssl_certs
+ except ImportError:
+ raise LTSCantStartError(
+ self, extra='Cannot import bzrlib.tests.ssl_certs,'
+ ' try a more recent bzr version')
+ crt_path = ssl_certs.build_path(
+ self.get_config_value('certificate_name'))
+ key_path = ssl_certs.build_path(
+ self.get_config_value('certificate_key_name'))
+ try:
+ crt = self._get_file_content(crt_path)
+ except NosuchFile:
+ raise LTSCantStartError(
+ self, extra='Cannot find server certificate: %s' % crt_path)
+ try:
+ key = self._get_file_content(key_path)
+ except NosuchFile:
+ raise LTSCantStartError(
+ self, extra='Cannot find server certificate key: %s' % key_path)
+
+ out = open(self.get_config_value('certificate_path'), 'wb')
+ try:
+ out.write(crt)
+ finally:
+ out.close()
+ out = open(self.get_config_value('certificate_key_path'), 'wb')
+ try:
+ out.write(key)
+ finally:
+ out.close()
+
+ # We can start now
+ super(Apache2HTTPS, self)._start()
+
+
class Apache2SVN(Apache2):
def __init__(self, port, _conf=None):
@@ -637,6 +687,7 @@
_servers['apache2-svn'] = Apache2SVN(37005)
#_servers['vsftpd'] = Vsftpd(37006)
#_servers['proftpd'] = Proftpd(37007)
+_servers['apache2-https'] = Apache2HTTPS(37008)
def get_server(name):
=== modified file 'test_server.py'
--- a/test_server.py 2008-10-01 12:51:07 +0000
+++ b/test_server.py 2009-02-09 13:09:17 +0000
@@ -70,6 +70,11 @@
_server_name = 'apache2-dav'
+class Apache2HTTPSFeature(LocalTestServerFeature):
+
+ _server_name = 'apache2-https'
+
+
class Apache2SVNFeature(LocalTestServerFeature):
_server_name = 'apache2-svn'
@@ -212,6 +217,21 @@
_url_protocol = 'http+pycurl'
+class Apache2HTTPS(Apache2):
+
+ _server_name = 'apache2-https'
+
+
+class Apache2HTTPS_urllib(Apache2HTTPS):
+
+ _url_protocol = 'https+urllib'
+
+
+class Apache2HTTPS_pycurl(Apache2HTTPS):
+
+ _url_protocol = 'https+pycurl'
+
+
class Apache2DAV(Apache2):
_server_name = 'apache2-dav'
@@ -320,6 +340,18 @@
permutations.append((HttpTransport_urllib, Apache2_urllib))
if pycurl_present:
permutations.append((PyCurlTransport, Apache2_pycurl))
+ if Apache2HTTPSFeature().available():
+ permutations.append((HttpTransport_urllib, Apache2HTTPS_urllib))
+ if pycurl_present:
+ from bzrlib.tests import ssl_certs
+ class HTTPS_pycurl_transport(PyCurlTransport):
+
+ def __init__(self, base, _from_transport=None):
+ super(HTTPS_pycurl_transport, self).__init__(
+ base, _from_transport)
+ self.cabundle = str(ssl_certs.build_path('ca.crt'))
+
+ permutations.append((HTTPS_pycurl_transport, Apache2HTTPS_pycurl))
if CherokeeFeature().available():
permutations.append((HttpTransport_urllib, Cherokee_urllib))
if pycurl_present:
=== modified file 'tests/test_config.py'
--- a/tests/test_config.py 2009-02-09 11:03:13 +0000
+++ b/tests/test_config.py 2009-02-09 13:09:17 +0000
@@ -125,3 +125,17 @@
def test_config_defines_keywords(self):
conf = self._get_config()
self._check_conf_path(conf, 'var_lock_dir', 'var/lock')
+
+
+class TestConfigApache2HTTPS(tests.TestCaseInTempDir, test_utils.TestConfig,
+ TestConfigMixin):
+
+ _server_name = 'apache2-https'
+ _config_class = config.Apache2HTTPS
+
+ def test_config_defines_keywords(self):
+ conf = self._get_config()
+ self._check_conf_path(conf, 'certificate_path',
+ 'etc/%s' % conf.get_value('certificate_name'))
+ self._check_conf_path(conf, 'certificate_key_path',
+ 'etc/%s' % conf.get_value('certificate_key_name'))
=== modified file 'tests/test_utils.py'
--- a/tests/test_utils.py 2009-02-09 11:03:13 +0000
+++ b/tests/test_utils.py 2009-02-09 13:09:17 +0000
@@ -114,6 +114,13 @@
_server_feature_class=test_server.Apache2DAVFeature,
_test_server_class=test_server.Apache2DAV,
)),
+ ('apache2-https', dict(
+ _server_name='apache2-https',
+ _config_class=config.Apache2HTTPS,
+ _server_class=server.Apache2HTTPS,
+ _server_feature_class=test_server.Apache2HTTPSFeature,
+ _test_server_class=test_server.Apache2HTTPS,
+ )),
('apache2-svn', dict(
_server_name='apache2-svn',
_config_class=config.Apache2SVN,
More information about the bazaar-commits
mailing list