Rev 3432: Make both http implementations raise appropriate exceptions when posting smart requests(#230223) in http://bazaar.launchpad.net/%7Evila/bzr/bzr.integration

Vincent Ladeuil v.ladeuil+lp at free.fr
Mon May 19 11:31:05 BST 2008


At http://bazaar.launchpad.net/%7Evila/bzr/bzr.integration

------------------------------------------------------------
revno: 3432
revision-id: v.ladeuil+lp at free.fr-20080519103037-jyr12jvojfgdpxfq
parent: pqm at pqm.ubuntu.com-20080518104127-7dezgqfdvymf4xvu
parent: v.ladeuil+lp at free.fr-20080519100415-ap9998ql5tmbp1b5
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: trunk
timestamp: Mon 2008-05-19 12:30:37 +0200
message:
  Make both http implementations raise appropriate exceptions when posting smart requests(#230223)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/test_http.py      testhttp.py-20051018020158-b2eef6e867c514d9
  bzrlib/transport/http/_pycurl.py pycurlhttp.py-20060110060940-4e2a705911af77a6
  bzrlib/transport/http/_urllib.py _urlgrabber.py-20060113083826-0bbf7d992fbf090c
  bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
    ------------------------------------------------------------
    revno: 3430.3.5
    revision-id: v.ladeuil+lp at free.fr-20080519100415-ap9998ql5tmbp1b5
    parent: v.ladeuil+lp at free.fr-20080519075049-wkmkwtcieevu2sh4
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 230223-hpss-probing
    timestamp: Mon 2008-05-19 12:04:15 +0200
    message:
      Fixed as per Andrew's review.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/transport/http/_urllib.py _urlgrabber.py-20060113083826-0bbf7d992fbf090c
    ------------------------------------------------------------
    revno: 3430.3.4
    revision-id: v.ladeuil+lp at free.fr-20080519075049-wkmkwtcieevu2sh4
    parent: v.ladeuil+lp at free.fr-20080518145023-dmf02uvyxk4mybs0
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 230223-hpss-probing
    timestamp: Mon 2008-05-19 09:50:49 +0200
    message:
      Of course we can write tests !
      
      * bzrlib/tests/test_http.py:
      (ForbiddenRequestHandler, SmartClientAgainstNotSmartServer): New
      classes allowing smart client testing against a not smart http
      server.
    modified:
      bzrlib/tests/test_http.py      testhttp.py-20051018020158-b2eef6e867c514d9
    ------------------------------------------------------------
    revno: 3430.3.3
    revision-id: v.ladeuil+lp at free.fr-20080518145023-dmf02uvyxk4mybs0
    parent: v.ladeuil+lp at free.fr-20080518141654-b717luef4acilrhc
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 230223-hpss-probing
    timestamp: Sun 2008-05-18 16:50:23 +0200
    message:
      Simplify fix.
      
      * bzrlib/transport/http/_urllib.py:
      (HttpTransport_urllib._post): Leave send_http_smart_request catch
      the 403.
    modified:
      bzrlib/transport/http/_urllib.py _urlgrabber.py-20060113083826-0bbf7d992fbf090c
    ------------------------------------------------------------
    revno: 3430.3.2
    revision-id: v.ladeuil+lp at free.fr-20080518141654-b717luef4acilrhc
    parent: v.ladeuil+lp at free.fr-20080518135954-o8v3f69soqztpg0f
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 230223-hpss-probing
    timestamp: Sun 2008-05-18 16:16:54 +0200
    message:
      Update NEWS
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3430.3.1
    revision-id: v.ladeuil+lp at free.fr-20080518135954-o8v3f69soqztpg0f
    parent: pqm at pqm.ubuntu.com-20080517004133-6476aqcg9uf8zn0c
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 230223-hpss-probing
    timestamp: Sun 2008-05-18 15:59:54 +0200
    message:
      Fix #230223 by making both http implementations raise appropriate exceptions.
      
      * _urllib2_wrappers.py:
      (HTTPDefaultErrorHandler.http_error_default): Fix the spelling
      error and also mentioned the url.
      
      * _urllib.py:
      (HttpTransport_urllib._post): Since the error handling differs from
      pycurl and we are used only by the smart client, treats 403 as a
      SmartProtocolError,
      
      * _pycurl.py:
      (PyCurlTransport._raise_curl_http_error): Fix the spelling error and
      also mentioned the url.
    modified:
      bzrlib/transport/http/_pycurl.py pycurlhttp.py-20060110060940-4e2a705911af77a6
      bzrlib/transport/http/_urllib.py _urlgrabber.py-20060113083826-0bbf7d992fbf090c
      bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2008-05-17 17:53:47 +0000
+++ b/NEWS	2008-05-19 10:30:37 +0000
@@ -31,6 +31,10 @@
       used for an ssh scheme (sftp or bzr+ssh).
       (Vincent Ladeuil, #203186)
 
+    * Make both http implementations raise appropriate exceptions on 403
+      Forbidden when POSTing smart requests.
+      (Vincent Ladeuil, #230223)
+
     * Properly *title* header names in http requests instead of capitalizing
       them.
       (Vincent Ladeuil, #229076)

=== modified file 'bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py	2008-05-16 07:05:26 +0000
+++ b/bzrlib/tests/test_http.py	2008-05-19 07:50:49 +0000
@@ -1719,3 +1719,24 @@
         self.assertEndsWith(response, expected_end_of_response)
 
 
+class ForbiddenRequestHandler(http_server.TestingHTTPRequestHandler):
+    """No smart server here request handler."""
+
+    def do_POST(self):
+        self.send_error(403, "Forbidden")
+
+
+class SmartClientAgainstNotSmartServer(TestSpecificRequestHandler):
+    """Test smart client behaviour against an http server without smarts."""
+
+    _req_handler_class = ForbiddenRequestHandler
+
+    def test_probe_smart_server(self):
+        """Test error handling against server refusing smart requests."""
+        server = self.get_readonly_server()
+        t = self._transport(server.get_url())
+        # No need to build a valid smart request here, the server will not even
+        # try to interpret it.
+        self.assertRaises(errors.SmartProtocolError,
+                          t.send_http_smart_request, 'whatever')
+

=== modified file 'bzrlib/transport/http/_pycurl.py'
--- a/bzrlib/transport/http/_pycurl.py	2007-12-20 16:36:44 +0000
+++ b/bzrlib/transport/http/_pycurl.py	2008-05-18 13:59:54 +0000
@@ -278,7 +278,8 @@
         # requests
         if code == 403:
             raise errors.TransportError(
-                'Server refuses to fullfil the request for: %s' % url)
+                'Server refuses to fulfill the request (403 Forbidden)'
+                ' for %s' % url)
         else:
             if info is None:
                 msg = ''

=== modified file 'bzrlib/transport/http/_urllib.py'
--- a/bzrlib/transport/http/_urllib.py	2008-03-05 15:48:27 +0000
+++ b/bzrlib/transport/http/_urllib.py	2008-05-19 10:04:15 +0000
@@ -133,7 +133,10 @@
 
     def _post(self, body_bytes):
         abspath = self._remote_path('.bzr/smart')
-        response = self._perform(Request('POST', abspath, body_bytes))
+        # We include 403 in accepted_errors so that send_http_smart_request can
+        # handle a 403.  Otherwise a 403 causes an unhandled TransportError.
+        response = self._perform(Request('POST', abspath, body_bytes,
+                                         accepted_errors=[200, 403]))
         code = response.code
         data = handle_response(abspath, code, response.info(), response)
         return code, data

=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
--- a/bzrlib/transport/http/_urllib2_wrappers.py	2008-05-18 07:34:22 +0000
+++ b/bzrlib/transport/http/_urllib2_wrappers.py	2008-05-19 10:30:37 +0000
@@ -1341,7 +1341,9 @@
 
     def http_error_default(self, req, fp, code, msg, hdrs):
         if code == 403:
-            raise errors.TransportError('Server refuses to fullfil the request')
+            raise errors.TransportError(
+                'Server refuses to fulfill the request (403 Forbidden)'
+                ' for %s' % req.get_full_url())
         else:
             raise errors.InvalidHttpResponse(req.get_full_url(),
                                              'Unable to handle http code %d: %s'



More information about the bazaar-commits mailing list