Rev 3778: Enable specifying default ssh username in authentication.conf in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Oct 15 22:44:48 BST 2008


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

------------------------------------------------------------
revno: 3778
revision-id: pqm at pqm.ubuntu.com-20081015214444-ztwoizx180edy73v
parent: pqm at pqm.ubuntu.com-20081014031836-0pn8u98igc7gvtv0
parent: aaron at aaronbentley.com-20081015191156-mrykcuir96zszuh7
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2008-10-15 22:44:44 +0100
message:
  Enable specifying default ssh username in authentication.conf
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
  bzrlib/tests/test_sftp_transport.py testsftp.py-20051027032739-247570325fec7e7e
  bzrlib/transport/ftp/__init__.py ftp.py-20051116161804-58dc9506548c2a53
  bzrlib/transport/remote.py     ssh.py-20060608202016-c25gvf1ob7ypbus6-1
  bzrlib/transport/sftp.py       sftp.py-20051019050329-ab48ce71b7e32dfe
  bzrlib/transport/ssh.py        ssh.py-20060824042150-0s9787kng6zv1nwq-1
    ------------------------------------------------------------
    revno: 3777.1.7
    revision-id: aaron at aaronbentley.com-20081015191156-mrykcuir96zszuh7
    parent: aaron at aaronbentley.com-20081015190711-so8c7mo9rfzs479e
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: ssh-authconfig
    timestamp: Wed 2008-10-15 15:11:56 -0400
    message:
      Restore AuthenticationConfig
    modified:
      bzrlib/transport/ssh.py        ssh.py-20060824042150-0s9787kng6zv1nwq-1
    ------------------------------------------------------------
    revno: 3777.1.6
    revision-id: aaron at aaronbentley.com-20081015190711-so8c7mo9rfzs479e
    parent: aaron at aaronbentley.com-20081015185954-6hm2y83u6fddrkeg
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: ssh-authconfig
    timestamp: Wed 2008-10-15 15:07:11 -0400
    message:
      Update NEWS
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3777.1.5
    revision-id: aaron at aaronbentley.com-20081015185954-6hm2y83u6fddrkeg
    parent: aaron at aaronbentley.com-20081015185907-lw5srt2ah0huccvt
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: ssh-authconfig
    timestamp: Wed 2008-10-15 14:59:54 -0400
    message:
      Remove AuthenticationConfig handling from Paramiko SSHVendor
    modified:
      bzrlib/transport/ssh.py        ssh.py-20060824042150-0s9787kng6zv1nwq-1
    ------------------------------------------------------------
    revno: 3777.1.4
    revision-id: aaron at aaronbentley.com-20081015185907-lw5srt2ah0huccvt
    parent: aaron at aaronbentley.com-20081015184528-mcdgasht0vz5bo8k
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: ssh-authconfig
    timestamp: Wed 2008-10-15 14:59:07 -0400
    message:
      bzr+ssh and sftp both use ssh scheme.
    modified:
      bzrlib/tests/test_sftp_transport.py testsftp.py-20051027032739-247570325fec7e7e
      bzrlib/transport/sftp.py       sftp.py-20051019050329-ab48ce71b7e32dfe
    ------------------------------------------------------------
    revno: 3777.1.3
    revision-id: aaron at aaronbentley.com-20081015184528-mcdgasht0vz5bo8k
    parent: aaron at aaronbentley.com-20081015172318-kg6h9v0daz8m66ns
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: ssh-authconfig
    timestamp: Wed 2008-10-15 14:45:28 -0400
    message:
      Use SSH default username from authentication.conf
    modified:
      bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
      bzrlib/transport/remote.py     ssh.py-20060608202016-c25gvf1ob7ypbus6-1
    ------------------------------------------------------------
    revno: 3777.1.2
    revision-id: aaron at aaronbentley.com-20081015172318-kg6h9v0daz8m66ns
    parent: aaron at aaronbentley.com-20081015155150-ewayhro15dhve4cs
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: ssh-authconfig
    timestamp: Wed 2008-10-15 13:23:18 -0400
    message:
      Make testing more thorough
    modified:
      bzrlib/tests/test_sftp_transport.py testsftp.py-20051027032739-247570325fec7e7e
    ------------------------------------------------------------
    revno: 3777.1.1
    revision-id: aaron at aaronbentley.com-20081015155150-ewayhro15dhve4cs
    parent: pqm at pqm.ubuntu.com-20081014031836-0pn8u98igc7gvtv0
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: ssh-authconfig
    timestamp: Wed 2008-10-15 11:51:50 -0400
    message:
      Use auth.conf for sftp
    modified:
      bzrlib/tests/test_sftp_transport.py testsftp.py-20051027032739-247570325fec7e7e
      bzrlib/transport/ftp/__init__.py ftp.py-20051116161804-58dc9506548c2a53
      bzrlib/transport/sftp.py       sftp.py-20051019050329-ab48ce71b7e32dfe
=== modified file 'NEWS'
--- a/NEWS	2008-10-14 02:45:17 +0000
+++ b/NEWS	2008-10-15 19:07:11 +0000
@@ -16,6 +16,9 @@
     * ``bzr dump-btree`` is a hidden command introduced to allow dumping
       the contents of a compressed btree file.  (John Arbash Meinel)
 
+    * default username for bzr+ssh and sftp can be configured in
+      authentication.conf. (Aaron Bentley)
+
   BUG FIXES:
 
   DOCUMENTATION:

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2008-09-17 04:33:24 +0000
+++ b/bzrlib/tests/test_remote.py	2008-10-15 18:45:28 +0000
@@ -27,6 +27,7 @@
 from cStringIO import StringIO
 
 from bzrlib import (
+    config,
     errors,
     graph,
     pack,
@@ -49,7 +50,11 @@
 from bzrlib.symbol_versioning import one_four
 from bzrlib.transport import get_transport, http
 from bzrlib.transport.memory import MemoryTransport
-from bzrlib.transport.remote import RemoteTransport, RemoteTCPTransport
+from bzrlib.transport.remote import (
+    RemoteTransport,
+    RemoteSSHTransport,
+    RemoteTCPTransport,
+)
 
 
 class BasicRemoteObjectTests(tests.TestCaseWithTransport):
@@ -1014,6 +1019,22 @@
             client._calls)
 
 
+class TestRemoteSSHTransportAuthentication(tests.TestCaseInTempDir):
+
+    def test_defaults_to_none(self):
+        t = RemoteSSHTransport('bzr+ssh://example.com')
+        self.assertIs(None, t._get_credentials()[0])
+
+    def test_uses_authentication_config(self):
+        conf = config.AuthenticationConfig()
+        conf._get_config().update(
+            {'bzr+sshtest': {'scheme': 'ssh', 'user': 'bar', 'host':
+            'example.com'}})
+        conf._save()
+        t = RemoteSSHTransport('bzr+ssh://example.com')
+        self.assertEqual('bar', t._get_credentials()[0])
+
+
 class TestRemoteRepository(tests.TestCase):
     """Base for testing RemoteRepository protocol usage.
     

=== modified file 'bzrlib/tests/test_sftp_transport.py'
--- a/bzrlib/tests/test_sftp_transport.py	2008-09-26 15:34:03 +0000
+++ b/bzrlib/tests/test_sftp_transport.py	2008-10-15 18:59:07 +0000
@@ -29,6 +29,7 @@
 
 from bzrlib import (
     bzrdir,
+    config,
     errors,
     tests,
     transport as _mod_transport,
@@ -483,3 +484,27 @@
         self.checkGetRequests([(0, 32768), (32768, 32768), (65536, 464)],
                               [(0, 40000), (40000, 100), (40100, 1900),
                                (42000, 24000)])
+
+
+class TestUsesAuthConfig(TestCaseWithSFTPServer):
+    """Test that AuthenticationConfig can supply default usernames."""
+
+    def get_transport_for_connection(self, set_config):
+        port = self.get_server()._listener.port
+        if set_config:
+            conf = config.AuthenticationConfig()
+            conf._get_config().update(
+                {'sftptest': {'scheme': 'ssh', 'port': port, 'user': 'bar'}})
+            conf._save()
+        t = get_transport('sftp://localhost:%d' % port)
+        # force a connection to be performed.
+        t.has('foo')
+        return t
+
+    def test_sftp_uses_config(self):
+        t = self.get_transport_for_connection(set_config=True)
+        self.assertEqual('bar', t._get_credentials()[0])
+
+    def test_sftp_is_none_if_no_config(self):
+        t = self.get_transport_for_connection(set_config=False)
+        self.assertIs(None, t._get_credentials()[0])

=== modified file 'bzrlib/transport/ftp/__init__.py'
--- a/bzrlib/transport/ftp/__init__.py	2008-08-28 15:01:41 +0000
+++ b/bzrlib/transport/ftp/__init__.py	2008-10-15 15:51:50 +0000
@@ -116,9 +116,10 @@
 
         :return: The created connection and its associated credentials.
 
-        The credentials are only the password as it may have been entered
-        interactively by the user and may be different from the one provided
-        in base url at transport creation time.
+        The input credentials are only the password as it may have been
+        entered interactively by the user and may be different from the one
+        provided in base url at transport creation time.  The returned
+        credentials are username, password.
         """
         if credentials is None:
             user, password = self._user, self._password

=== modified file 'bzrlib/transport/remote.py'
--- a/bzrlib/transport/remote.py	2008-09-25 16:03:22 +0000
+++ b/bzrlib/transport/remote.py	2008-10-15 18:45:28 +0000
@@ -512,15 +512,16 @@
     """
 
     def _build_medium(self):
-        # ssh will prompt the user for a password if needed and if none is
-        # provided but it will not give it back, so no credentials can be
-        # stored.
         location_config = config.LocationConfig(self.base)
         bzr_remote_path = location_config.get_bzr_remote_path()
+        user = self._user
+        if user is None:
+            auth = config.AuthenticationConfig()
+            user = auth.get_user('ssh', self._host, self._port)
         client_medium = medium.SmartSSHClientMedium(self._host, self._port,
-            self._user, self._password, self.base,
+            user, self._password, self.base,
             bzr_remote_path=bzr_remote_path)
-        return client_medium, None
+        return client_medium, (user, self._password)
 
 
 class RemoteHTTPTransport(RemoteTransport):

=== modified file 'bzrlib/transport/sftp.py'
--- a/bzrlib/transport/sftp.py	2008-09-10 17:33:01 +0000
+++ b/bzrlib/transport/sftp.py	2008-10-15 18:59:07 +0000
@@ -39,6 +39,7 @@
 import warnings
 
 from bzrlib import (
+    config,
     errors,
     urlutils,
     )
@@ -375,9 +376,13 @@
             password = credentials
 
         vendor = ssh._get_ssh_vendor()
+        user = self._user
+        if user is None:
+            auth = config.AuthenticationConfig()
+            user = auth.get_user('ssh', self._host, self._port)
         connection = vendor.connect_sftp(self._user, password,
                                          self._host, self._port)
-        return connection, password
+        return connection, (user, password)
 
     def _get_sftp(self):
         """Ensures that a connection is established"""

=== modified file 'bzrlib/transport/ssh.py'
--- a/bzrlib/transport/ssh.py	2008-04-24 07:22:53 +0000
+++ b/bzrlib/transport/ssh.py	2008-10-15 19:11:56 +0000
@@ -458,18 +458,10 @@
 
 
 def _paramiko_auth(username, password, host, port, paramiko_transport):
-    # paramiko requires a username, but it might be none if nothing was supplied
-    # use the local username, just in case.
-    # We don't override username, because if we aren't using paramiko,
-    # the username might be specified in ~/.ssh/config and we don't want to
-    # force it to something else
-    # Also, it would mess up the self.relpath() functionality
-    auth = config.AuthenticationConfig()
+    # paramiko requires a username, but it might be none if nothing was
+    # supplied.  If so, use the local username.
     if username is None:
-        username = auth.get_user('ssh', host, port=port)
-        if username is None:
-            # Default to local user
-            username = getpass.getuser()
+        username = getpass.getuser()
 
     if _use_ssh_agent:
         agent = paramiko.Agent()
@@ -496,6 +488,7 @@
             pass
 
     # give up and ask for a password
+    auth = config.AuthenticationConfig()
     password = auth.get_password('ssh', host, username, port=port)
     try:
         paramiko_transport.auth_password(username, password)




More information about the bazaar-commits mailing list