Rev 2941: Implement an https server passing the same tests than http. Except in file:///v/home/vila/src/bzr/experimental/https/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Sat Nov 24 14:57:27 GMT 2007
At file:///v/home/vila/src/bzr/experimental/https/
------------------------------------------------------------
revno: 2941
revision-id:v.ladeuil+lp at free.fr-20071124145725-vy1kdhey2jusaj04
parent: v.ladeuil+lp at free.fr-20071124142059-2114qtsgfdv8g9p1
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: https
timestamp: Sat 2007-11-24 15:57:25 +0100
message:
Implement an https server passing the same tests than http. Except
for test_readv_with_adjust_for_latency of course (hi robert
;-). There is a nasty bug there already triggered in the #158972
days, but nastier this time.
* bzrlib/transport/http/_urllib2_wrappers.py:
(HTTPSConnection.connect_to_origin): Takes python2.6 ssl
implementation into account if available.
* bzrlib/tests/https_server.py:
(TestingHTTPSServer): Real implementation for https.
(HTTPSServer): Real implementation with test ssl files.
* bzrlib/tests/http_server.py:
(HttpServer.create_httpd): New method allowing daughter classes to
create specific servers.
modified:
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/http_server.py httpserver.py-20061012142527-m1yxdj1xazsf8d7s-1
bzrlib/tests/https_server.py https_server.py-20071121173708-aj8zczi0ziwbwz21-1
bzrlib/tests/test_http.py testhttp.py-20051018020158-b2eef6e867c514d9
bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2007-11-22 10:35:56 +0000
+++ b/bzrlib/tests/__init__.py 2007-11-24 14:57:25 +0000
@@ -2761,11 +2761,16 @@
class _HTTPSServerFeature(Feature):
"""Some tests want an https Server, check if one is available.
- Placeholder. We only implement an http server for now.
+ Right now, the only way this is available is under python2.6 which provides
+ an ssl module.
"""
def _probe(self):
- return True
+ try:
+ import ssl
+ return True
+ except ImportError:
+ return False
def feature_name(self):
return 'HTTPSServer'
=== modified file 'bzrlib/tests/http_server.py'
--- a/bzrlib/tests/http_server.py 2007-11-22 10:35:56 +0000
+++ b/bzrlib/tests/http_server.py 2007-11-24 14:57:25 +0000
@@ -66,7 +66,6 @@
and e.args[0] in (errno.EPIPE, errno.ECONNRESET,
errno.ECONNABORTED,)):
self.close_connection = 1
- pass
else:
raise
@@ -301,19 +300,20 @@
self.port = 0
self._httpd = None
+ def create_httpd(self):
+ return TestingHTTPServer((self.host, self.port), self.request_handler,
+ self)
+
def _get_httpd(self):
if self._httpd is None:
- self._httpd = TestingHTTPServer((self.host, self.port),
- self.request_handler,
- self)
+ self._httpd = self.create_httpd()
host, self.port = self._httpd.socket.getsockname()
return self._httpd
def _http_start(self):
httpd = self._get_httpd()
self._http_base_url = '%s://%s:%s/' % (self._url_protocol,
- self.host,
- self.port)
+ self.host, self.port)
self._http_starting.release()
while self._http_running:
=== modified file 'bzrlib/tests/https_server.py'
--- a/bzrlib/tests/https_server.py 2007-11-22 10:35:56 +0000
+++ b/bzrlib/tests/https_server.py 2007-11-24 14:57:25 +0000
@@ -14,18 +14,55 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-"""Fake HTTPS test server while installing the necessary plumbing."""
-
-from bzrlib.tests import http_server
+"""HTTPS test server, available when ssl python module is available"""
+
+from bzrlib.tests import (
+ http_server,
+ ssl_certs,
+ )
+
class TestingHTTPSServer(http_server.TestingHTTPServer):
- pass
+
+ def __init__(self, server_address, request_handler_class,
+ test_case_server, key_file, cert_file):
+ http_server.TestingHTTPServer.__init__(
+ self, server_address, request_handler_class, test_case_server)
+ self.key_file = key_file
+ self.cert_file = cert_file
+
+ def get_request (self):
+ """Get the request and client address from the socket.
+
+ This is called in response to a connection issued to the server, we
+ wrap the socket with SSL.
+ """
+ import ssl
+ sock, addr = self.socket.accept()
+ sslconn = ssl.wrap_socket(sock, server_side=True,
+ keyfile=self.key_file,
+ certfile=self.cert_file)
+ return sslconn, addr
class HTTPSServer(http_server.HttpServer):
_url_protocol = 'https'
+ # Provides usable defaults since an https server requires both a
+ # private key and certificate to work.
+ def __init__(self, request_handler=http_server.TestingHTTPRequestHandler,
+ key_file=ssl_certs.build_path('server_without_pass.key'),
+ cert_file=ssl_certs.build_path('server.crt')):
+ http_server.HttpServer.__init__(self, request_handler)
+ self.key_file = key_file
+ self.cert_file = cert_file
+ self.temp_files = []
+
+ def create_httpd(self):
+ return TestingHTTPSServer((self.host, self.port), self.request_handler,
+ self, self.key_file, self.cert_file)
+
class HTTPSServer_urllib(HTTPSServer):
"""Subclass of HTTPSServer that gives https+urllib urls.
@@ -36,3 +73,4 @@
# urls returned by this server should require the urllib client impl
_url_protocol = 'https+urllib'
+
=== modified file 'bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py 2007-11-20 18:02:02 +0000
+++ b/bzrlib/tests/test_http.py 2007-11-24 14:57:25 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
--- a/bzrlib/transport/http/_urllib2_wrappers.py 2007-11-22 10:35:56 +0000
+++ b/bzrlib/transport/http/_urllib2_wrappers.py 2007-11-24 14:57:25 +0000
@@ -146,7 +146,16 @@
self.proxied_host = proxied_host
-# FIXME: Should test for ssl availability
+# Build the appropriate socket wrapper for ssl
+try:
+ import ssl # python 2.6
+ _ssl_wrap_socket = ssl.wrap_socket
+except ImportError:
+ def _ssl_wrap_socket(sock, key_file, cert_file):
+ ssl_sock = socket.ssl(sock, key_file, cert_file)
+ return httplib.FakeSocket(sock, ssl_sock)
+
+
class HTTPSConnection(AbstractHTTPConnection, httplib.HTTPSConnection):
def __init__(self, host, port=None, key_file=None, cert_file=None,
@@ -162,10 +171,7 @@
self.connect_to_origin()
def connect_to_origin(self):
- pass
-# Temporarily disabled to act as a true http connection
-# ssl = socket.ssl(self.sock, self.key_file, self.cert_file)
-# self.sock = httplib.FakeSocket(self.sock, ssl)
+ self.sock = _ssl_wrap_socket(self.sock, self.key_file, self.cert_file)
class Request(urllib2.Request):
More information about the bazaar-commits
mailing list