13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""HTTPS test server, available when ssl python module is available"""
21
from bzrlib.tests import (
27
class TestingHTTPSServerMixin:
29
def __init__(self, key_file, cert_file):
30
self.key_file = key_file
31
self.cert_file = cert_file
33
def get_request (self):
34
"""Get the request and client address from the socket.
36
This is called in response to a connection issued to the server, we
37
wrap the socket with SSL.
39
sock, addr = self.socket.accept()
40
sslconn = ssl.wrap_socket(sock, server_side=True,
41
keyfile=self.key_file,
42
certfile=self.cert_file)
46
class TestingHTTPSServer(TestingHTTPSServerMixin,
47
http_server.TestingHTTPServer):
49
def __init__(self, server_address, request_handler_class,
50
test_case_server, key_file, cert_file):
51
TestingHTTPSServerMixin.__init__(self, key_file, cert_file)
52
http_server.TestingHTTPServer.__init__(
53
self, server_address, request_handler_class, test_case_server)
56
class TestingThreadingHTTPSServer(TestingHTTPSServerMixin,
57
http_server.TestingThreadingHTTPServer):
59
def __init__(self, server_address, request_handler_class,
60
test_case_server, key_file, cert_file):
61
TestingHTTPSServerMixin.__init__(self, key_file, cert_file)
62
http_server.TestingThreadingHTTPServer.__init__(
63
self, server_address, request_handler_class, test_case_server)
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Fake HTTPS test server while installing the necessary plumbing."""
19
from bzrlib.tests import http_server
21
class TestingHTTPSServer(http_server.TestingHTTPServer):
66
25
class HTTPSServer(http_server.HttpServer):
68
27
_url_protocol = 'https'
70
# The real servers depending on the protocol
71
http_server_class = {'HTTP/1.0': TestingHTTPSServer,
72
'HTTP/1.1': TestingThreadingHTTPSServer,
75
# Provides usable defaults since an https server requires both a
76
# private key and certificate to work.
77
def __init__(self, request_handler=http_server.TestingHTTPRequestHandler,
78
protocol_version=None,
79
key_file=ssl_certs.build_path('server_without_pass.key'),
80
cert_file=ssl_certs.build_path('server.crt')):
81
http_server.HttpServer.__init__(self, request_handler=request_handler,
82
protocol_version=protocol_version)
83
self.key_file = key_file
84
self.cert_file = cert_file
87
def create_httpd(self, serv_cls, rhandler_cls):
88
return serv_cls((self.host, self.port), self.request_handler,
89
self, self.key_file, self.cert_file)
92
30
class HTTPSServer_urllib(HTTPSServer):
93
31
"""Subclass of HTTPSServer that gives https+urllib urls.