Rev 3912: Fix bug #300347 by allowing querying authentication.conf if no in lp:~vila/bzr/300347-http-user-by-auth-conf

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Dec 19 10:37:44 GMT 2008


At lp:~vila/bzr/300347-http-user-by-auth-conf

------------------------------------------------------------
revno: 3912
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.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2008-12-17 19:26:46 +0000
+++ b/NEWS	2008-12-19 10:37:42 +0000
@@ -46,6 +46,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)
 
@@ -76,10 +79,6 @@
     * Use the short status format when the short format is used for log.
       (Vincent Ladeuil, #87179)
 
-    * Don't require "username@" in HTTP(S) URLs that require
-      authentication.
-      (#256612)
-
   DOCUMENTATION:
 
     * Improved the formats help topic to explain why multiple formats

=== 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-19 10:37:42 +0000
@@ -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()
+        # 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')

=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
--- a/bzrlib/transport/http/_urllib2_wrappers.py	2008-12-17 19:26:46 +0000
+++ b/bzrlib/transport/http/_urllib2_wrappers.py	2008-12-19 10:37:42 +0000
@@ -46,7 +46,6 @@
 # actual code more or less do that, tests should be written to
 # ensure that.
 
-import getpass
 import httplib
 import socket
 import urllib
@@ -975,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)
@@ -1044,13 +1047,9 @@
 
         if user is None:
             user = auth_conf.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:
+                                      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