~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/https_server.py

  • Committer: Vincent Ladeuil
  • Date: 2008-01-05 22:19:04 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-20080105221904-185q2vl2hjbeul3d
Fix 1.1 related bugs in HTTP server, add HTTPS passing tests (by temporarily disabling pycurl certificate verification).

* doc/developers/authentication-ring.txt
(verify_certificates): Fix typo, obviously only apply to HTTPS 

* bzrlib/transport/http/ca_bundle.py:
(get_ca_path): Fix too long lines.

* bzrlib/transport/http/_pycurl.py:
(CURLE_SSL_CACERT): New error code.
(PyCurlTransport._set_curl_options): Temporarily disable peer
verification to make tests pass.
(PyCurlTransport._curl_perform): Catch CURLE_SSL_CACERT as a
connection error.
(get_test_permutations): Add HTTPS tests.

* bzrlib/tests/https_server.py:
(TestingHTTPSServer, TestingThreadingHTTPSServer): HTTPS test
servers.
(HTTPSServer_PyCurl): New class for pycurl HTTPS test server.

* bzrlib/tests/http_server.py:
(TestingHTTPRequestHandler.send_error): Overrides python version
since we need to specify a Content-Length.
(TestingHTTPRequestHandler.get_multiple_ranges): Sabotage !
Off-by-one error caused a buggy comment ! Went unnoticed until
pycurl+https hang.
(HttpServer.create_httpd): Allow server creation overriding.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""HTTPS test server, available when ssl python module is available"""
18
18
 
 
19
import ssl
 
20
 
19
21
from bzrlib.tests import (
20
22
    http_server,
21
23
    ssl_certs,
22
24
    )
23
25
 
24
26
 
25
 
class TestingHTTPSServer(http_server.TestingHTTPServer):
 
27
class TestingHTTPSServerMixin:
26
28
 
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
33
32
 
37
36
        This is called in response to a connection issued to the server, we
38
37
        wrap the socket with SSL.
39
38
        """
40
 
        import 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
46
44
 
 
45
class TestingHTTPSServer(TestingHTTPSServerMixin,
 
46
                         http_server.TestingHTTPServer):
 
47
 
 
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)
 
53
 
 
54
 
 
55
class TestingThreadingHTTPSServer(TestingHTTPSServerMixin,
 
56
                                  http_server.TestingThreadingHTTPServer):
 
57
 
 
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)
 
63
 
47
64
 
48
65
class HTTPSServer(http_server.HttpServer):
49
66
 
50
67
    _url_protocol = 'https'
51
68
 
 
69
    # The real servers depending on the protocol
 
70
    http_server_class = {'HTTP/1.0': TestingHTTPSServer,
 
71
                         'HTTP/1.1': TestingThreadingHTTPSServer,
 
72
                         }
 
73
 
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 = []
61
83
 
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)
65
87
 
66
88
 
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'
76
98
 
 
99
 
 
100
class HTTPSServer_PyCurl(HTTPSServer):
 
101
    """Subclass of HTTPSServer that gives http+pycurl urls.
 
102
 
 
103
    This is for use in testing: connections to this server will always go
 
104
    through pycurl where possible.
 
105
    """
 
106
 
 
107
    # We don't care about checking the pycurl availability as
 
108
    # this server will be required only when pycurl is present
 
109
 
 
110
    # urls returned by this server should require the pycurl client impl
 
111
    _url_protocol = 'https+pycurl'