Rev 2939: Add a fake https server and test facilities. in file:///v/home/vila/src/bzr/experimental/https/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Nov 22 10:35:58 GMT 2007


At file:///v/home/vila/src/bzr/experimental/https/

------------------------------------------------------------
revno: 2939
revision-id:v.ladeuil+lp at free.fr-20071122103556-djp1gm22n2npztk0
parent: v.ladeuil+lp at free.fr-20071122102144-adjrfkg2q7edfu43
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: https
timestamp: Thu 2007-11-22 11:35:56 +0100
message:
  Add a fake https server and test facilities.
  
  * bzrlib/transport/http/_urllib2_wrappers.py:
  (HTTPSConnection.connect_to_origin): Disable ssl wrapping temporarily.
  
  * bzrlib/transport/http/_urllib.py:
  (get_test_permutations): Add https tests if a server is available.
  
  * bzrlib/tests/http_server.py:
  (TestingHTTPServer): Fix typo.
  (HttpServer.get_bogus_url): Use _url_protocol.
  
  * bzrlib/tests/__init__.py:
  (_HTTPSServerFeature): Define a feature since an https test server
  will have dependencies.
added:
  bzrlib/tests/https_server.py   https_server.py-20071121173708-aj8zczi0ziwbwz21-1
modified:
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/http_server.py    httpserver.py-20061012142527-m1yxdj1xazsf8d7s-1
  bzrlib/transport/http/_urllib.py _urlgrabber.py-20060113083826-0bbf7d992fbf090c
  bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
-------------- next part --------------
=== added file 'bzrlib/tests/https_server.py'
--- a/bzrlib/tests/https_server.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/https_server.py	2007-11-22 10:35:56 +0000
@@ -0,0 +1,38 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Fake HTTPS test server while installing the necessary plumbing."""
+
+from bzrlib.tests import http_server
+
+class TestingHTTPSServer(http_server.TestingHTTPServer):
+    pass
+
+
+class HTTPSServer(http_server.HttpServer):
+
+    _url_protocol = 'https'
+
+
+class HTTPSServer_urllib(HTTPSServer):
+    """Subclass of HTTPSServer that gives https+urllib urls.
+
+    This is for use in testing: connections to this server will always go
+    through urllib where possible.
+    """
+
+    # urls returned by this server should require the urllib client impl
+    _url_protocol = 'https+urllib'

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2007-11-20 16:33:39 +0000
+++ b/bzrlib/tests/__init__.py	2007-11-22 10:35:56 +0000
@@ -2754,4 +2754,21 @@
     def feature_name(self):
         return 'FTPServer'
 
+
 FTPServerFeature = _FTPServerFeature()
+
+
+class _HTTPSServerFeature(Feature):
+    """Some tests want an https Server, check if one is available.
+
+    Placeholder. We only implement an http server for now.
+    """
+
+    def _probe(self):
+        return True
+
+    def feature_name(self):
+        return 'HTTPSServer'
+
+
+HTTPSServerFeature = _HTTPSServerFeature()

=== modified file 'bzrlib/tests/http_server.py'
--- a/bzrlib/tests/http_server.py	2007-11-20 16:33:39 +0000
+++ b/bzrlib/tests/http_server.py	2007-11-22 10:35:56 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006 Canonical Ltd
+# Copyright (C) 2006, 2007 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -32,10 +32,6 @@
 from bzrlib.transport.local import LocalURLServer
 
 
-class WebserverNotAvailable(Exception):
-    pass
-
-
 class BadWebserverPath(ValueError):
     def __str__(self):
         return 'path %s is not in %s' % self.args
@@ -264,10 +260,10 @@
 
 class TestingHTTPServer(BaseHTTPServer.HTTPServer):
 
-    def __init__(self, server_address, RequestHandlerClass,
+    def __init__(self, server_address, request_handler_class,
                  test_case_server):
         BaseHTTPServer.HTTPServer.__init__(self, server_address,
-                                           RequestHandlerClass)
+                                           request_handler_class)
         # test_case_server can be used to communicate between the
         # tests and the server (or the request handler and the
         # server), allowing dynamic behaviors to be defined from
@@ -383,7 +379,7 @@
         """See bzrlib.transport.Server.get_bogus_url."""
         # this is chosen to try to prevent trouble with proxies, weird dns,
         # etc
-        return 'http://127.0.0.1:1/'
+        return self._url_protocol + '://127.0.0.1:1/'
 
 
 class HttpServer_urllib(HttpServer):

=== modified file 'bzrlib/transport/http/_urllib.py'
--- a/bzrlib/transport/http/_urllib.py	2007-11-20 16:33:39 +0000
+++ b/bzrlib/transport/http/_urllib.py	2007-11-22 10:35:56 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -177,6 +177,12 @@
 
 def get_test_permutations():
     """Return the permutations to be used in testing."""
-    from bzrlib.tests.http_server import HttpServer_urllib
-    return [(HttpTransport_urllib, HttpServer_urllib),
-            ]
+    from bzrlib import tests
+    from bzrlib.tests import http_server
+    permutations = [(HttpTransport_urllib, http_server.HttpServer_urllib),]
+    if tests.HTTPSServerFeature.available():
+        from bzrlib.tests import https_server
+        permutations.append((HttpTransport_urllib,
+                             https_server.HTTPSServer_urllib))
+    return permutations
+

=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
--- a/bzrlib/transport/http/_urllib2_wrappers.py	2007-11-22 10:21:44 +0000
+++ b/bzrlib/transport/http/_urllib2_wrappers.py	2007-11-22 10:35:56 +0000
@@ -162,8 +162,10 @@
             self.connect_to_origin()
 
     def connect_to_origin(self):
-        ssl = socket.ssl(self.sock, self.key_file, self.cert_file)
-        self.sock = httplib.FakeSocket(self.sock, ssl)
+        pass
+# Temporarily disabled to act as a true http connection
+#        ssl = socket.ssl(self.sock, self.key_file, self.cert_file)
+#        self.sock = httplib.FakeSocket(self.sock, ssl)
 
 
 class Request(urllib2.Request):



More information about the bazaar-commits mailing list