/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/https_server.py

  • Committer: Vincent Ladeuil
  • Date: 2008-01-05 22:09:47 UTC
  • mto: (3928.1.1 bzr.integration)
  • mto: This revision was merged to the branch mainline in revision 3929.
  • Revision ID: v.ladeuil+lp@free.fr-20080105220947-t2kymulzeqf1g5n5
Fix the server name in script and ssl files.

* bzrlib/tests/ssl_certs/create_ssls.py:
(ssl_params): We use localhost, not 127.0.0.1.

* bzrlib/tests/ssl_certs/server_without_pass.key,
bzrlib/tests/ssl_certs/server_with_pass.key,
bzrlib/tests/ssl_certs/server.csr,
bzrlib/tests/ssl_certs/server.crt:
Re-generated since the server name was wrong.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""HTTPS test server, available when ssl python module is available"""
18
18
 
19
 
import ssl
20
 
 
21
19
from bzrlib.tests import (
22
20
    http_server,
23
21
    ssl_certs,
24
22
    )
25
23
 
26
24
 
27
 
class TestingHTTPSServerMixin:
 
25
class TestingHTTPSServer(http_server.TestingHTTPServer):
28
26
 
29
 
    def __init__(self, key_file, cert_file):
 
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)
30
31
        self.key_file = key_file
31
32
        self.cert_file = cert_file
32
33
 
36
37
        This is called in response to a connection issued to the server, we
37
38
        wrap the socket with SSL.
38
39
        """
 
40
        import ssl
39
41
        sock, addr = self.socket.accept()
40
42
        sslconn = ssl.wrap_socket(sock, server_side=True,
41
43
                                  keyfile=self.key_file,
43
45
        return sslconn, addr
44
46
 
45
47
 
46
 
class TestingHTTPSServer(TestingHTTPSServerMixin,
47
 
                         http_server.TestingHTTPServer):
48
 
 
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)
54
 
 
55
 
 
56
 
class TestingThreadingHTTPSServer(TestingHTTPSServerMixin,
57
 
                                  http_server.TestingThreadingHTTPServer):
58
 
 
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)
64
 
 
65
 
 
66
48
class HTTPSServer(http_server.HttpServer):
67
49
 
68
50
    _url_protocol = 'https'
69
51
 
70
 
    # The real servers depending on the protocol
71
 
    http_server_class = {'HTTP/1.0': TestingHTTPSServer,
72
 
                         'HTTP/1.1': TestingThreadingHTTPSServer,
73
 
                         }
74
 
 
75
52
    # Provides usable defaults since an https server requires both a
76
53
    # private key and certificate to work.
77
54
    def __init__(self, request_handler=http_server.TestingHTTPRequestHandler,
78
 
                 protocol_version=None,
79
55
                 key_file=ssl_certs.build_path('server_without_pass.key'),
80
56
                 cert_file=ssl_certs.build_path('server.crt')):
81
 
        http_server.HttpServer.__init__(self, request_handler=request_handler,
82
 
                                        protocol_version=protocol_version)
 
57
        http_server.HttpServer.__init__(self, request_handler)
83
58
        self.key_file = key_file
84
59
        self.cert_file = cert_file
85
60
        self.temp_files = []
86
61
 
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)
 
62
    def create_httpd(self):
 
63
        return TestingHTTPSServer((self.host, self.port), self.request_handler,
 
64
                                  self, self.key_file, self.cert_file)
90
65
 
91
66
 
92
67
class HTTPSServer_urllib(HTTPSServer):
99
74
    # urls returned by this server should require the urllib client impl
100
75
    _url_protocol = 'https+urllib'
101
76
 
102
 
 
103
 
class HTTPSServer_PyCurl(HTTPSServer):
104
 
    """Subclass of HTTPSServer that gives http+pycurl urls.
105
 
 
106
 
    This is for use in testing: connections to this server will always go
107
 
    through pycurl where possible.
108
 
    """
109
 
 
110
 
    # We don't care about checking the pycurl availability as
111
 
    # this server will be required only when pycurl is present
112
 
 
113
 
    # urls returned by this server should require the pycurl client impl
114
 
    _url_protocol = 'https+pycurl'