Rev 3921: (vila) Fix bug #300347 by allowing authentication.conf to be used in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Mon Dec 29 14:29:20 GMT 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3921
revision-id: pqm at pqm.ubuntu.com-20081229142916-z08eu2alga2acrh6
parent: pqm at pqm.ubuntu.com-20081224050842-15xix09apawzgs05
parent: v.ladeuil+lp at free.fr-20081229135119-qtwcuq4ueepvhy5z
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2008-12-29 14:29:16 +0000
message:
  (vila) Fix bug #300347 by allowing authentication.conf to be used
  	even if no user appears in HTTP[S] urls
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/test_http.py      testhttp.py-20051018020158-b2eef6e867c514d9
  bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
    ------------------------------------------------------------
    revno: 3920.1.1
    revision-id: v.ladeuil+lp at free.fr-20081229135119-qtwcuq4ueepvhy5z
    parent: pqm at pqm.ubuntu.com-20081224050842-15xix09apawzgs05
    parent: v.ladeuil+lp at free.fr-20081229134515-k6vilia46la239dz
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: bzr.integration
    timestamp: Mon 2008-12-29 14:51:19 +0100
    message:
      Fix bug #300347 by allowing authentication.conf to be used even if no user appears in HTTP[S] urls
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/tests/test_http.py      testhttp.py-20051018020158-b2eef6e867c514d9
      bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
    ------------------------------------------------------------
    revno: 3910.2.4
    revision-id: v.ladeuil+lp at free.fr-20081229134515-k6vilia46la239dz
    parent: aogail at w007.org-20081223231216-2wt2wokz59af10cf
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 300347-http-user-by-auth-conf
    timestamp: Mon 2008-12-29 14:45:15 +0100
    message:
      Fixed as per John's review.
      
      * bzrlib/transport/http/_urllib2_wrappers.py:
      (AbstractAuthHandler.get_user_password): Better explain parameter
      content.
      
      * bzrlib/tests/test_http.py:
      (TestAuth.get_user_url, TestAuth.get_user_transport,
      TestProxyAuth.get_user_transport): Make the parameters mandatory
      so that the tests carry more meaning.
    modified:
      bzrlib/tests/test_http.py      testhttp.py-20051018020158-b2eef6e867c514d9
      bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
    ------------------------------------------------------------
    revno: 3910.2.3
    revision-id: aogail at w007.org-20081223231216-2wt2wokz59af10cf
    parent: v.ladeuil+lp at free.fr-20081219103742-3jgozfsnv5ojjyu4
    committer: Ben Jansen <aogail at w007.org>
    branch nick: bzr.httpauth
    timestamp: Tue 2008-12-23 15:12:16 -0800
    message:
      Made tweaks requested by John Arbash Meinel.
    modified:
      bzrlib/tests/test_http.py      testhttp.py-20051018020158-b2eef6e867c514d9
      bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
    ------------------------------------------------------------
    revno: 3910.2.2
    revision-id: v.ladeuil+lp at free.fr-20081219103742-3jgozfsnv5ojjyu4
    parent: aogail at w007.org-20081217192646-eejsyi056lo4w75r
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 300347-http-user-by-auth-conf
    timestamp: Fri 2008-12-19 11:37:42 +0100
    message:
      Fix bug #300347 by allowing querying authentication.conf if no
      user is supplied.
      
      * bzrlib/transport/http/_urllib2_wrappers.py:
      (AbstractAuthHandler.auth_required): Restore the no user/no auth
      check.
      (AbstractAuthHandler.auth_match): Don't try to get a password if
      we couldn't get a user.
      
      * bzrlib/tests/test_http.py:
      (TestAuth.test_user_from_auth_conf): Reproduce bug #300347.
      
      * NEWS: 
      Point to the right bug number. Give credit to Ben for pointing the
      root bug in _urllib2_wrappers.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/tests/test_http.py      testhttp.py-20051018020158-b2eef6e867c514d9
      bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
    ------------------------------------------------------------
    revno: 3910.2.1
    revision-id: aogail at w007.org-20081217192646-eejsyi056lo4w75r
    parent: pqm at pqm.ubuntu.com-20081217102138-pz7pfli9o3k50zq7
    committer: Ben Jansen <aogail at w007.org>
    branch nick: bzr.httpauth
    timestamp: Wed 2008-12-17 11:26:46 -0800
    message:
      Changed HTTP transport auth so that URLs no longer need to include the username for HTTP Auth to work. Now, if bzr gets a 401 HTTP response, it looks in the authentication config for an appropriate username and password. If it doesn't find a username, it defaults to the local user. If it doesn't find a password, it prompts.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
=== modified file 'NEWS'
--- a/NEWS	2008-12-24 03:01:07 +0000
+++ b/NEWS	2008-12-29 13:51:19 +0000
@@ -50,6 +50,9 @@
       that's in a stackable shared repository to a location with default
       stack-on location.  (Andrew Bennetts, #291046)
 
+    * Don't require embedding user in HTTP(S) URLs do use authentication.conf.
+      (Ben Jansen, Vincent Ladeuil, #300347)
+
     * Fix compilation error in ``_dirstate_helpers_c`` on SunOS/Solaris.
       (Jari Aalto)
 

=== modified file 'bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py	2008-12-04 16:02:51 +0000
+++ b/bzrlib/tests/test_http.py	2008-12-29 13:45:15 +0000
@@ -1447,7 +1447,7 @@
     def _testing_pycurl(self):
         return pycurl_present and self._transport == PyCurlTransport
 
-    def get_user_url(self, user=None, password=None):
+    def get_user_url(self, user, password):
         """Build an url embedding user and password"""
         url = '%s://' % self.server._url_protocol
         if user is not None:
@@ -1458,12 +1458,12 @@
         url += '%s:%s/' % (self.server.host, self.server.port)
         return url
 
-    def get_user_transport(self, user=None, password=None):
+    def get_user_transport(self, user, password):
         return self._transport(self.get_user_url(user, password))
 
     def test_no_user(self):
         self.server.add_user('joe', 'foo')
-        t = self.get_user_transport()
+        t = self.get_user_transport(None, None)
         self.assertRaises(errors.InvalidHttpResponse, t.get, 'a')
         # Only one 'Authentication Required' error should occur
         self.assertEqual(1, self.server.auth_required_errors)
@@ -1557,6 +1557,25 @@
         # Only one 'Authentication Required' error should occur
         self.assertEqual(1, self.server.auth_required_errors)
 
+    def test_user_from_auth_conf(self):
+        if self._testing_pycurl():
+            raise tests.TestNotApplicable(
+                'pycurl does not support authentication.conf')
+        user = 'joe'
+        password = 'foo'
+        self.server.add_user(user, password)
+        # Create a minimal config file with the right password
+        conf = config.AuthenticationConfig()
+        conf._get_config().update(
+            {'httptest': {'scheme': 'http', 'port': self.server.port,
+                          'user': user, 'password': password}})
+        conf._save()
+        t = self.get_user_transport(None, None)
+        # Issue a request to the server to connect
+        self.assertEqual('contents of a\n', t.get('a').read())
+        # Only one 'Authentication Required' error should occur
+        self.assertEqual(1, self.server.auth_required_errors)
+
     def test_changing_nonce(self):
         if self._auth_scheme != 'digest':
             raise tests.TestNotApplicable('HTTP auth digest only test')
@@ -1608,7 +1627,7 @@
                 protocol_version=self._protocol_version)
         return server
 
-    def get_user_transport(self, user=None, password=None):
+    def get_user_transport(self, user, password):
         self._install_env({'all_proxy': self.get_user_url(user, password)})
         return self._transport(self.server.get_url())
 

=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
--- a/bzrlib/transport/http/_urllib2_wrappers.py	2008-11-11 00:57:17 +0000
+++ b/bzrlib/transport/http/_urllib2_wrappers.py	2008-12-29 13:45:15 +0000
@@ -965,10 +965,6 @@
             raise KeyError('%s not found' % self.auth_required_header)
 
         auth = self.get_auth(request)
-        if auth.get('user', None) is None:
-            # Without a known user, we can't authenticate
-            return None
-
         auth['modified'] = False
         if self.auth_match(server_header, auth):
             # auth_match may have modified auth (by adding the
@@ -978,6 +974,10 @@
                 # We already tried that, give up
                 return None
 
+            if auth.get('user', None) is None:
+                # Without a known user, we can't authenticate
+                return None
+
             # Housekeeping
             request.connection.cleanup_pipe()
             response = self.parent.open(request)
@@ -1039,21 +1039,21 @@
         self._retry_count = None
 
     def get_user_password(self, auth):
-        """Ask user for a password if none is already available."""
+        """Ask user for a password if none is already available.
+
+        :param auth: authentication info gathered so far (from the initial url
+            and then during dialog with the server).
+        """
         auth_conf = config.AuthenticationConfig()
         user = auth['user']
         password = auth['password']
         realm = auth['realm']
 
         if user is None:
-            user = auth.get_user(auth['protocol'], auth['host'],
-                                 port=auth['port'], path=auth['path'],
-                                 realm=realm)
-            if user is None:
-                # Default to local user
-                user = getpass.getuser()
-
-        if password is None:
+            user = auth_conf.get_user(auth['protocol'], auth['host'],
+                                      port=auth['port'], path=auth['path'],
+                                      realm=realm)
+        if user is not None and password is None:
             password = auth_conf.get_password(
                 auth['protocol'], auth['host'], user, port=auth['port'],
                 path=auth['path'], realm=realm,




More information about the bazaar-commits mailing list