bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
5247.1.1
by Vincent Ladeuil
Merge previous attempt into current trunk |
1 |
# Copyright (C) 2007-2010 Canonical Ltd
|
|
2929.3.10
by Vincent Ladeuil
Add a fake https server and test facilities. |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
2929.3.10
by Vincent Ladeuil
Add a fake https server and test facilities. |
16 |
|
|
2929.3.12
by Vincent Ladeuil
Implement an https server passing the same tests than http. Except |
17 |
"""HTTPS test server, available when ssl python module is available"""
|
18 |
||
|
2929.3.19
by Vincent Ladeuil
Fix 1.1 related bugs in HTTP server, add HTTPS passing tests (by temporarily disabling pycurl certificate verification). |
19 |
import ssl |
20 |
||
|
2929.3.12
by Vincent Ladeuil
Implement an https server passing the same tests than http. Except |
21 |
from bzrlib.tests import ( |
22 |
http_server, |
|
23 |
ssl_certs, |
|
24 |
)
|
|
25 |
||
|
2929.3.10
by Vincent Ladeuil
Add a fake https server and test facilities. |
26 |
|
|
2929.3.19
by Vincent Ladeuil
Fix 1.1 related bugs in HTTP server, add HTTPS passing tests (by temporarily disabling pycurl certificate verification). |
27 |
class TestingHTTPSServerMixin: |
|
2929.3.12
by Vincent Ladeuil
Implement an https server passing the same tests than http. Except |
28 |
|
|
2929.3.19
by Vincent Ladeuil
Fix 1.1 related bugs in HTTP server, add HTTPS passing tests (by temporarily disabling pycurl certificate verification). |
29 |
def __init__(self, key_file, cert_file): |
|
2929.3.12
by Vincent Ladeuil
Implement an https server passing the same tests than http. Except |
30 |
self.key_file = key_file |
31 |
self.cert_file = cert_file |
|
32 |
||
|
4731.2.12
by Vincent Ladeuil
Start adding a more precise synchronization between the various test threads. |
33 |
def _get_ssl_request (self, sock, addr): |
34 |
"""Wrap the socket with SSL""" |
|
35 |
ssl_sock = ssl.wrap_socket(sock, server_side=True, |
|
36 |
keyfile=self.key_file, |
|
37 |
certfile=self.cert_file, |
|
38 |
do_handshake_on_connect=False) |
|
39 |
return ssl_sock, addr |
|
40 |
||
41 |
def verify_request(self, request, client_address): |
|
42 |
"""Verify the request. |
|
43 |
||
44 |
Return True if we should proceed with this request, False if we should
|
|
45 |
not even touch a single byte in the socket !
|
|
|
2929.3.12
by Vincent Ladeuil
Implement an https server passing the same tests than http. Except |
46 |
"""
|
|
5247.5.31
by Vincent Ladeuil
Use a boolean for server.serving, a threading.Event() is not needed here. |
47 |
serving = self.serving |
|
4731.2.12
by Vincent Ladeuil
Start adding a more precise synchronization between the various test threads. |
48 |
if serving: |
49 |
request.do_handshake() |
|
50 |
return serving |
|
|
2929.3.27
by Vincent Ladeuil
Fixed as per Ian's review. |
51 |
|
|
2929.3.19
by Vincent Ladeuil
Fix 1.1 related bugs in HTTP server, add HTTPS passing tests (by temporarily disabling pycurl certificate verification). |
52 |
class TestingHTTPSServer(TestingHTTPSServerMixin, |
53 |
http_server.TestingHTTPServer): |
|
54 |
||
55 |
def __init__(self, server_address, request_handler_class, |
|
56 |
test_case_server, key_file, cert_file): |
|
57 |
TestingHTTPSServerMixin.__init__(self, key_file, cert_file) |
|
58 |
http_server.TestingHTTPServer.__init__( |
|
59 |
self, server_address, request_handler_class, test_case_server) |
|
60 |
||
|
4731.2.12
by Vincent Ladeuil
Start adding a more precise synchronization between the various test threads. |
61 |
def _get_request (self): |
62 |
sock, addr = http_server.TestingHTTPServer._get_request(self) |
|
63 |
return self._get_ssl_request(sock, addr) |
|
64 |
||
|
2929.3.19
by Vincent Ladeuil
Fix 1.1 related bugs in HTTP server, add HTTPS passing tests (by temporarily disabling pycurl certificate verification). |
65 |
|
66 |
class TestingThreadingHTTPSServer(TestingHTTPSServerMixin, |
|
67 |
http_server.TestingThreadingHTTPServer): |
|
68 |
||
69 |
def __init__(self, server_address, request_handler_class, |
|
70 |
test_case_server, key_file, cert_file): |
|
71 |
TestingHTTPSServerMixin.__init__(self, key_file, cert_file) |
|
72 |
http_server.TestingThreadingHTTPServer.__init__( |
|
73 |
self, server_address, request_handler_class, test_case_server) |
|
74 |
||
|
4731.2.12
by Vincent Ladeuil
Start adding a more precise synchronization between the various test threads. |
75 |
def _get_request (self): |
76 |
sock, addr = http_server.TestingThreadingHTTPServer._get_request(self) |
|
77 |
return self._get_ssl_request(sock, addr) |
|
78 |
||
|
2929.3.10
by Vincent Ladeuil
Add a fake https server and test facilities. |
79 |
|
80 |
class HTTPSServer(http_server.HttpServer): |
|
81 |
||
82 |
_url_protocol = 'https' |
|
83 |
||
|
2929.3.19
by Vincent Ladeuil
Fix 1.1 related bugs in HTTP server, add HTTPS passing tests (by temporarily disabling pycurl certificate verification). |
84 |
# The real servers depending on the protocol
|
85 |
http_server_class = {'HTTP/1.0': TestingHTTPSServer, |
|
86 |
'HTTP/1.1': TestingThreadingHTTPSServer, |
|
87 |
}
|
|
88 |
||
|
2929.3.12
by Vincent Ladeuil
Implement an https server passing the same tests than http. Except |
89 |
# Provides usable defaults since an https server requires both a
|
|
4731.2.12
by Vincent Ladeuil
Start adding a more precise synchronization between the various test threads. |
90 |
# private key and a certificate to work.
|
|
2929.3.12
by Vincent Ladeuil
Implement an https server passing the same tests than http. Except |
91 |
def __init__(self, request_handler=http_server.TestingHTTPRequestHandler, |
|
3945.1.7
by Vincent Ladeuil
Test against https. |
92 |
protocol_version=None, |
|
2929.3.12
by Vincent Ladeuil
Implement an https server passing the same tests than http. Except |
93 |
key_file=ssl_certs.build_path('server_without_pass.key'), |
94 |
cert_file=ssl_certs.build_path('server.crt')): |
|
|
3945.1.7
by Vincent Ladeuil
Test against https. |
95 |
http_server.HttpServer.__init__(self, request_handler=request_handler, |
96 |
protocol_version=protocol_version) |
|
|
2929.3.12
by Vincent Ladeuil
Implement an https server passing the same tests than http. Except |
97 |
self.key_file = key_file |
98 |
self.cert_file = cert_file |
|
99 |
self.temp_files = [] |
|
100 |
||
|
2929.3.19
by Vincent Ladeuil
Fix 1.1 related bugs in HTTP server, add HTTPS passing tests (by temporarily disabling pycurl certificate verification). |
101 |
def create_httpd(self, serv_cls, rhandler_cls): |
102 |
return serv_cls((self.host, self.port), self.request_handler, |
|
103 |
self, self.key_file, self.cert_file) |
|
|
2929.3.12
by Vincent Ladeuil
Implement an https server passing the same tests than http. Except |
104 |
|
|
2929.3.10
by Vincent Ladeuil
Add a fake https server and test facilities. |
105 |
|
106 |
class HTTPSServer_urllib(HTTPSServer): |
|
107 |
"""Subclass of HTTPSServer that gives https+urllib urls. |
|
108 |
||
109 |
This is for use in testing: connections to this server will always go
|
|
110 |
through urllib where possible.
|
|
111 |
"""
|
|
112 |
||
113 |
# urls returned by this server should require the urllib client impl
|
|
114 |
_url_protocol = 'https+urllib' |
|
|
2929.3.12
by Vincent Ladeuil
Implement an https server passing the same tests than http. Except |
115 |
|
|
2929.3.19
by Vincent Ladeuil
Fix 1.1 related bugs in HTTP server, add HTTPS passing tests (by temporarily disabling pycurl certificate verification). |
116 |
|
117 |
class HTTPSServer_PyCurl(HTTPSServer): |
|
118 |
"""Subclass of HTTPSServer that gives http+pycurl urls. |
|
119 |
||
120 |
This is for use in testing: connections to this server will always go
|
|
121 |
through pycurl where possible.
|
|
122 |
"""
|
|
123 |
||
124 |
# We don't care about checking the pycurl availability as
|
|
125 |
# this server will be required only when pycurl is present
|
|
126 |
||
127 |
# urls returned by this server should require the pycurl client impl
|
|
128 |
_url_protocol = 'https+pycurl' |