~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/https_server.py

  • Committer: Andrew Bennetts
  • Date: 2010-08-31 07:12:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5401.
  • Revision ID: andrew.bennetts@canonical.com-20100831071218-4kjieu3ejqcdmdom
Use has_id rather than __contains__; expand NEWS entry; add What's New entry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 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
21
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
 
            request.do_handshake()
52
 
        return serving
 
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
53
44
 
54
45
 
55
46
class TestingHTTPSServer(TestingHTTPSServerMixin,
61
52
        http_server.TestingHTTPServer.__init__(
62
53
            self, server_address, request_handler_class, test_case_server)
63
54
 
64
 
    def get_request(self):
65
 
        sock, addr = http_server.TestingHTTPServer.get_request(self)
66
 
        return self._get_ssl_request(sock, addr)
67
 
 
68
55
 
69
56
class TestingThreadingHTTPSServer(TestingHTTPSServerMixin,
70
57
                                  http_server.TestingThreadingHTTPServer):
75
62
        http_server.TestingThreadingHTTPServer.__init__(
76
63
            self, server_address, request_handler_class, test_case_server)
77
64
 
78
 
    def get_request(self):
79
 
        sock, addr = http_server.TestingThreadingHTTPServer.get_request(self)
80
 
        return self._get_ssl_request(sock, addr)
81
 
 
82
65
 
83
66
class HTTPSServer(http_server.HttpServer):
84
67
 
90
73
                         }
91
74
 
92
75
    # Provides usable defaults since an https server requires both a
93
 
    # private key and a certificate to work.
 
76
    # private key and certificate to work.
94
77
    def __init__(self, request_handler=http_server.TestingHTTPRequestHandler,
95
78
                 protocol_version=None,
96
79
                 key_file=ssl_certs.build_path('server_without_pass.key'),
101
84
        self.cert_file = cert_file
102
85
        self.temp_files = []
103
86
 
104
 
    def create_server(self):
105
 
        return self.server_class(
106
 
            (self.host, self.port), self.request_handler_class, self,
107
 
            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)
108
90
 
109
91
 
110
92
class HTTPSServer_urllib(HTTPSServer):