Rev 2805: Fix bug #137044: ftp password handling broken in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Sep 7 15:58:31 BST 2007


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

------------------------------------------------------------
revno: 2805
revision-id: pqm at pqm.ubuntu.com-20070907145828-hjh5941jv7y8d9z8
parent: pqm at pqm.ubuntu.com-20070906063814-iiwx3hccoukt499k
parent: v.ladeuil+lp at free.fr-20070907134117-hv955pzvsv3ofap9
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2007-09-07 15:58:28 +0100
message:
  Fix bug #137044: ftp password handling broken
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/test_ftp_transport.py test_aftp_transport.-20060823221619-98mwjzxtwtkt527k-1
  bzrlib/transport/ftp.py        ftp.py-20051116161804-58dc9506548c2a53
    ------------------------------------------------------------
    revno: 2804.1.1
    merged: v.ladeuil+lp at free.fr-20070907134117-hv955pzvsv3ofap9
    parent: pqm at pqm.ubuntu.com-20070906063814-iiwx3hccoukt499k
    parent: v.ladeuil+lp at free.fr-20070907133303-0c0ro056pn6owz10
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: bzr.integration
    timestamp: Fri 2007-09-07 15:41:17 +0200
    message:
      Fix bug #137044: ftp apssword handling broken
    ------------------------------------------------------------
    revno: 2790.1.4
    merged: v.ladeuil+lp at free.fr-20070907133303-0c0ro056pn6owz10
    parent: v.ladeuil+lp at free.fr-20070905133820-s1jndkddykxebo4g
    parent: pqm at pqm.ubuntu.com-20070906063814-iiwx3hccoukt499k
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 137044
    timestamp: Fri 2007-09-07 15:33:03 +0200
    message:
      Merge bzr.dev
    ------------------------------------------------------------
    revno: 2790.1.3
    merged: v.ladeuil+lp at free.fr-20070905133820-s1jndkddykxebo4g
    parent: v.ladeuil+lp at free.fr-20070905133538-3hlcjti8pktcamp0
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 137044
    timestamp: Wed 2007-09-05 15:38:20 +0200
    message:
      Cosmetic change.
    ------------------------------------------------------------
    revno: 2790.1.2
    merged: v.ladeuil+lp at free.fr-20070905133538-3hlcjti8pktcamp0
    parent: v.ladeuil+lp at free.fr-20070905072749-qiud9xt21loarqyy
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 137044
    timestamp: Wed 2007-09-05 15:35:38 +0200
    message:
      Review feedback.
    ------------------------------------------------------------
    revno: 2790.1.1
    merged: v.ladeuil+lp at free.fr-20070905072749-qiud9xt21loarqyy
    parent: pqm at pqm.ubuntu.com-20070903130729-qdcrag0a7vcpzfgm
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 137044
    timestamp: Wed 2007-09-05 09:27:49 +0200
    message:
      Fix #137044 by prompting for a password if *none* is provided for ftp.
      
      * bzrlib/transport/ftp.py:
      (FtpTransport._create_connection): The fix: the test was inverted.
      (_setup_medusa.test_authorizer.__init__): One user can be secured
      by verifying his password.
      (_setup_medusa.test_authorizer.authorize): Check the password if a
      secured user have been declared. Let the doors wide open
      otherwise (as before :-/).
      
      * bzrlib/tests/test_ftp_transport.py:
      (TestFTPServer.test_basic_exists): New class for UI related tests.
=== modified file 'NEWS'
--- a/NEWS	2007-09-06 02:41:54 +0000
+++ b/NEWS	2007-09-07 13:33:03 +0000
@@ -123,6 +123,9 @@
    * ``bzr --version`` takes care about encoding of stdout, especially
      when output is redirected. (Alexander Belchenko, #131100)
 
+    * Prompt for an ftp password if none is provided.
+      (Vincent Ladeuil, #137044)
+
   IMPROVEMENTS:
 
    * Add the option "--show-diff" to the commit command in order to display

=== modified file 'bzrlib/tests/test_ftp_transport.py'
--- a/bzrlib/tests/test_ftp_transport.py	2007-04-12 21:18:29 +0000
+++ b/bzrlib/tests/test_ftp_transport.py	2007-09-05 13:35:38 +0000
@@ -14,8 +14,13 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-from bzrlib import tests
-import bzrlib.transport
+import sys
+
+from bzrlib import (
+    tests,
+    transport,
+    ui,
+    )
 
 
 class _MedusaFeature(tests.Feature):
@@ -54,7 +59,7 @@
     """Test aftp transport."""
 
     def test_aftp_degrade(self):
-        t = bzrlib.transport.get_transport('aftp://host/path')
+        t = transport.get_transport('aftp://host/path')
         self.failUnless(t.is_active)
         parent = t.clone('..')
         self.failUnless(parent.is_active)
@@ -71,3 +76,42 @@
         t = self.get_transport()
         t.put_bytes('foo', 'test bytes\n')
         self.assertEqual('test bytes\n', t.get_bytes('foo'))
+
+
+class TestFTPServerUI(TestCaseWithFTPServer):
+
+    def setUp(self):
+        super(TestFTPServerUI, self).setUp()
+        self.old_factory = ui.ui_factory
+        # The following has the unfortunate side-effect of hiding any ouput
+        # during the tests (including pdb prompts). Feel free to comment them
+        # for debugging purposes but leave them in place, there are needed to
+        # run the tests without any console
+        self.old_stdout = sys.stdout
+        sys.stdout = tests.StringIOWrapper()
+        self.addCleanup(self.restoreUIFactory)
+
+    def restoreUIFactory(self):
+        ui.ui_factory = self.old_factory
+        sys.stdout = self.old_stdout
+
+    def test_prompt_for_password(self):
+        t = self.get_transport()
+        # Ensure that the test framework set the password
+        self.assertIsNot(t._password, None)
+        # Reset the password (get_url set the password to 'bar' so we
+        # reset it to None in the transport before the connection).
+        password = t._password
+        t._password = None
+        ui.ui_factory = tests.TestUIFactory(stdin=password+'\n')
+        # Ask the server to check the password
+        server = self.get_server()
+        # FIXME: There should be a better way to declare authorized users and
+        # passwords to the server
+        authorizer = server._ftp_server.authorizer
+        authorizer.secured_user = t._user
+        authorizer.secured_password = password
+        # Issue a request to the server to connect
+        t.has('whatever/not/existing')
+        # stdin should be empty (the provided password have been consumed)
+        self.assertEqual('', ui.ui_factory.stdin.readline())

=== modified file 'bzrlib/transport/ftp.py'
--- a/bzrlib/transport/ftp.py	2007-08-22 01:41:24 +0000
+++ b/bzrlib/transport/ftp.py	2007-09-05 13:38:20 +0000
@@ -130,7 +130,7 @@
             connection = ftplib.FTP()
             connection.connect(host=self._host, port=self._port)
             if self._user and self._user != 'anonymous' and \
-                    password is not None: # '' is a valid password
+                    password is None: # '' is a valid password
                 get_password = bzrlib.ui.ui_factory.get_password
                 password = get_password(prompt='FTP %(user)s@%(host)s password',
                                         user=self._user, host=self._host)
@@ -635,6 +635,9 @@
 
         def __init__(self, root):
             self.root = root
+            # If secured_user is set secured_password will be checked
+            self.secured_user = None
+            self.secured_password = None
 
         def authorize(self, channel, username, password):
             """Return (success, reply_string, filesystem)"""
@@ -647,7 +650,13 @@
             else:
                 channel.read_only = 0
 
-            return 1, 'OK.', medusa.filesys.os_filesystem(self.root)
+            # Check secured_user if set
+            if (self.secured_user is not None
+                and username == self.secured_user
+                and password != self.secured_password):
+                return 0, 'Password invalid.', None
+            else:
+                return 1, 'OK.', medusa.filesys.os_filesystem(self.root)
 
 
     class ftp_channel(medusa.ftp_server.ftp_channel):




More information about the bazaar-commits mailing list