/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: Robert Collins
  • Date: 2010-05-05 00:05:29 UTC
  • mto: This revision was merged to the branch mainline in revision 5206.
  • Revision ID: robertc@robertcollins.net-20100505000529-ltmllyms5watqj5u
Make 'pydoc bzrlib.tests.build_tree_shape' useful.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2011 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
 
19
19
import ssl
20
20
 
21
 
from . import (
 
21
from bzrlib.tests import (
22
22
    http_server,
23
23
    ssl_certs,
24
 
    test_server,
25
24
    )
26
25
 
27
26
 
31
30
        self.key_file = key_file
32
31
        self.cert_file = cert_file
33
32
 
34
 
    def _get_ssl_request(self, sock, addr):
35
 
        """Wrap the socket with SSL"""
36
 
        ssl_sock = ssl.wrap_socket(sock, server_side=True,
37
 
                                   keyfile=self.key_file,
38
 
                                   certfile=self.cert_file,
39
 
                                   do_handshake_on_connect=False)
40
 
        return ssl_sock, addr
41
 
 
42
 
    def verify_request(self, request, client_address):
43
 
        """Verify the request.
44
 
 
45
 
        Return True if we should proceed with this request, False if we should
46
 
        not even touch a single byte in the socket !
 
33
    def get_request (self):
 
34
        """Get the request and client address from the socket.
 
35
 
 
36
        This is called in response to a connection issued to the server, we
 
37
        wrap the socket with SSL.
47
38
        """
48
 
        serving = test_server.TestingTCPServerMixin.verify_request(
49
 
            self, request, client_address)
50
 
        if serving:
51
 
            try:
52
 
                request.do_handshake()
53
 
            except ssl.SSLError:
54
 
                # FIXME: We proabaly want more tests to capture which ssl
55
 
                # errors are worth reporting but mostly our tests want an https
56
 
                # server that works -- vila 2012-01-19
57
 
                return False
58
 
        return serving
59
 
 
60
 
    def ignored_exceptions_during_shutdown(self, e):
61
 
        base = test_server.TestingTCPServerMixin
62
 
        return base.ignored_exceptions_during_shutdown(self, e)
 
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)
 
43
        return sslconn, addr
63
44
 
64
45
 
65
46
class TestingHTTPSServer(TestingHTTPSServerMixin,
71
52
        http_server.TestingHTTPServer.__init__(
72
53
            self, server_address, request_handler_class, test_case_server)
73
54
 
74
 
    def get_request(self):
75
 
        sock, addr = http_server.TestingHTTPServer.get_request(self)
76
 
        return self._get_ssl_request(sock, addr)
77
 
 
78
55
 
79
56
class TestingThreadingHTTPSServer(TestingHTTPSServerMixin,
80
57
                                  http_server.TestingThreadingHTTPServer):
85
62
        http_server.TestingThreadingHTTPServer.__init__(
86
63
            self, server_address, request_handler_class, test_case_server)
87
64
 
88
 
    def get_request(self):
89
 
        sock, addr = http_server.TestingThreadingHTTPServer.get_request(self)
90
 
        return self._get_ssl_request(sock, addr)
91
 
 
92
65
 
93
66
class HTTPSServer(http_server.HttpServer):
94
67
 
100
73
                         }
101
74
 
102
75
    # Provides usable defaults since an https server requires both a
103
 
    # private key and a certificate to work.
 
76
    # private key and certificate to work.
104
77
    def __init__(self, request_handler=http_server.TestingHTTPRequestHandler,
105
78
                 protocol_version=None,
106
79
                 key_file=ssl_certs.build_path('server_without_pass.key'),
111
84
        self.cert_file = cert_file
112
85
        self.temp_files = []
113
86
 
114
 
    def create_server(self):
115
 
        return self.server_class(
116
 
            (self.host, self.port), self.request_handler_class, self,
117
 
            self.key_file, self.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)
118
90
 
119
91
 
120
92
class HTTPSServer_urllib(HTTPSServer):
126
98
 
127
99
    # urls returned by this server should require the urllib client impl
128
100
    _url_protocol = 'https+urllib'
 
101
 
 
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'