17
17
"""HTTPS test server, available when ssl python module is available"""
19
21
from bzrlib.tests import (
25
class TestingHTTPSServer(http_server.TestingHTTPServer):
27
class TestingHTTPSServerMixin:
27
def __init__(self, server_address, request_handler_class,
28
test_case_server, key_file, cert_file):
29
http_server.TestingHTTPServer.__init__(
30
self, server_address, request_handler_class, test_case_server)
29
def __init__(self, key_file, cert_file):
31
30
self.key_file = key_file
32
31
self.cert_file = cert_file
37
36
This is called in response to a connection issued to the server, we
38
37
wrap the socket with SSL.
41
39
sock, addr = self.socket.accept()
42
40
sslconn = ssl.wrap_socket(sock, server_side=True,
43
41
keyfile=self.key_file,
44
42
certfile=self.cert_file)
45
43
return sslconn, addr
45
class TestingHTTPSServer(TestingHTTPSServerMixin,
46
http_server.TestingHTTPServer):
48
def __init__(self, server_address, request_handler_class,
49
test_case_server, key_file, cert_file):
50
TestingHTTPSServerMixin.__init__(self, key_file, cert_file)
51
http_server.TestingHTTPServer.__init__(
52
self, server_address, request_handler_class, test_case_server)
55
class TestingThreadingHTTPSServer(TestingHTTPSServerMixin,
56
http_server.TestingThreadingHTTPServer):
58
def __init__(self, server_address, request_handler_class,
59
test_case_server, key_file, cert_file):
60
TestingHTTPSServerMixin.__init__(self, key_file, cert_file)
61
http_server.TestingThreadingHTTPServer.__init__(
62
self, server_address, request_handler_class, test_case_server)
48
65
class HTTPSServer(http_server.HttpServer):
50
67
_url_protocol = 'https'
69
# The real servers depending on the protocol
70
http_server_class = {'HTTP/1.0': TestingHTTPSServer,
71
'HTTP/1.1': TestingThreadingHTTPSServer,
52
74
# Provides usable defaults since an https server requires both a
53
75
# private key and certificate to work.
54
76
def __init__(self, request_handler=http_server.TestingHTTPRequestHandler,
59
81
self.cert_file = cert_file
60
82
self.temp_files = []
62
def create_httpd(self):
63
return TestingHTTPSServer((self.host, self.port), self.request_handler,
64
self, self.key_file, self.cert_file)
84
def create_httpd(self, serv_cls, rhandler_cls):
85
return serv_cls((self.host, self.port), self.request_handler,
86
self, self.key_file, self.cert_file)
67
89
class HTTPSServer_urllib(HTTPSServer):
74
96
# urls returned by this server should require the urllib client impl
75
97
_url_protocol = 'https+urllib'
100
class HTTPSServer_PyCurl(HTTPSServer):
101
"""Subclass of HTTPSServer that gives http+pycurl urls.
103
This is for use in testing: connections to this server will always go
104
through pycurl where possible.
107
# We don't care about checking the pycurl availability as
108
# this server will be required only when pycurl is present
110
# urls returned by this server should require the pycurl client impl
111
_url_protocol = 'https+pycurl'