~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/https_server.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-29 22:03:03 UTC
  • mfrom: (5416.2.6 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100929220303-cr95h8iwtggco721
(mbp) Add 'break-lock --force'

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007-2010 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,
24
25
    )
25
26
 
26
27
 
30
31
        self.key_file = key_file
31
32
        self.cert_file = cert_file
32
33
 
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.
 
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 !
38
47
        """
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
 
48
        serving = test_server.TestingTCPServerMixin.verify_request(
 
49
            self, request, client_address)
 
50
        if serving:
 
51
            request.do_handshake()
 
52
        return serving
44
53
 
45
54
 
46
55
class TestingHTTPSServer(TestingHTTPSServerMixin,
52
61
        http_server.TestingHTTPServer.__init__(
53
62
            self, server_address, request_handler_class, test_case_server)
54
63
 
 
64
    def get_request(self):
 
65
        sock, addr = http_server.TestingHTTPServer.get_request(self)
 
66
        return self._get_ssl_request(sock, addr)
 
67
 
55
68
 
56
69
class TestingThreadingHTTPSServer(TestingHTTPSServerMixin,
57
70
                                  http_server.TestingThreadingHTTPServer):
62
75
        http_server.TestingThreadingHTTPServer.__init__(
63
76
            self, server_address, request_handler_class, test_case_server)
64
77
 
 
78
    def get_request(self):
 
79
        sock, addr = http_server.TestingThreadingHTTPServer.get_request(self)
 
80
        return self._get_ssl_request(sock, addr)
 
81
 
65
82
 
66
83
class HTTPSServer(http_server.HttpServer):
67
84
 
73
90
                         }
74
91
 
75
92
    # Provides usable defaults since an https server requires both a
76
 
    # private key and certificate to work.
 
93
    # private key and a certificate to work.
77
94
    def __init__(self, request_handler=http_server.TestingHTTPRequestHandler,
78
95
                 protocol_version=None,
79
96
                 key_file=ssl_certs.build_path('server_without_pass.key'),
84
101
        self.cert_file = cert_file
85
102
        self.temp_files = []
86
103
 
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)
 
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)
90
108
 
91
109
 
92
110
class HTTPSServer_urllib(HTTPSServer):