Rev 3422: Fix bug #203186 by ignoring passwords for ssh and warning user. in http://bazaar.launchpad.net/%7Evila/bzr/203186-warn-pass-for-ssh-auth

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu May 15 23:21:19 BST 2008


At http://bazaar.launchpad.net/%7Evila/bzr/203186-warn-pass-for-ssh-auth

------------------------------------------------------------
revno: 3422
revision-id: v.ladeuil+lp at free.fr-20080515222045-0ewqm6gk6f8s58zv
parent: v.ladeuil+lp at free.fr-20080512142928-b0x3ktxdriztye6h
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 203186-warn-pass-for-ssh-auth
timestamp: Fri 2008-05-16 00:20:45 +0200
message:
  Fix bug #203186 by ignoring passwords for ssh and warning user.
  
  * bzrlib/tests/test_config.py:
  (TestAuthenticationConfig.test_ssh_password_emits_warning): Check
  that password is ignored and a warning issued.
  
  * bzrlib/config.py:
  (AuthenticationConfig.get_password): Ignore passwords for ssh
  schemes and warn user.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2008-05-12 10:16:36 +0000
+++ b/NEWS	2008-05-15 22:20:45 +0000
@@ -18,6 +18,11 @@
 
   BUGFIXES:
 
+    * Issue a warning and ignore passwords declared in authentication.conf when
+      used for an ssh scheme (sftp or bzr+ssh).
+      (Vincent Ladeuil, #203186)
+
+
   DOCUMENTATION:
 
   TESTING:

=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2008-05-09 19:09:52 +0000
+++ b/bzrlib/config.py	2008-05-15 22:20:45 +0000
@@ -1090,12 +1090,17 @@
         credentials = self.get_credentials(scheme, host, port, user, path)
         if credentials is not None:
             password = credentials['password']
+            if scheme is 'ssh':
+                trace.warning('password ignored in section [%s],'
+                              ' use an ssh agent instead'
+                              % credentials['name'])
+                password = None
         else:
             password = None
         # Prompt user only if we could't find a password
         if password is None:
             if prompt is None:
-                # Create a default prompt suitable for most of the cases
+                # Create a default prompt suitable for most cases
                 prompt = '%s' % scheme.upper() + ' %(user)s@%(host)s password'
             # Special handling for optional fields in the prompt
             if port is not None:

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2008-05-09 19:09:52 +0000
+++ b/bzrlib/tests/test_config.py	2008-05-15 22:20:45 +0000
@@ -1412,6 +1412,28 @@
             'SMTP %(user)s@%(host)s:%(port)d password: ',
             'smtp', port=10025)
 
+    def test_ssh_password_emits_warning(self):
+        conf = config.AuthenticationConfig(_file=StringIO(
+                """
+[ssh with password]
+scheme=ssh
+host=bar.org
+user=jim
+password=jimpass
+"""))
+        entered_password = 'typed-by-hand'
+        stdout = tests.StringIOWrapper()
+        ui.ui_factory = tests.TestUIFactory(stdin=entered_password + '\n',
+                                            stdout=stdout)
+
+        # Since the password defined in the authentication config is ignored,
+        # the user is prompted
+        self.assertEquals(entered_password,
+                          conf.get_password('ssh', 'bar.org', user='jim'))
+        self.assertContainsRe(
+            self._get_log(keep_log_file=True),
+            'password ignored in section \[ssh with password\]')
+
 
 # FIXME: Once we have a way to declare authentication to all test servers, we
 # can implement generic tests.



More information about the bazaar-commits mailing list