Rev 2791: Fix #137044 by prompting for a password if *none* is provided for ftp. in file:///v/home/vila/src/bugs/137044/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Sep 5 08:27:53 BST 2007
At file:///v/home/vila/src/bugs/137044/
------------------------------------------------------------
revno: 2791
revision-id: 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:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/tests/test_ftp_transport.py test_aftp_transport.-20060823221619-98mwjzxtwtkt527k-1
bzrlib/transport/ftp.py ftp.py-20051116161804-58dc9506548c2a53
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2007-09-03 12:32:14 +0000
+++ b/NEWS 2007-09-05 07:27:49 +0000
@@ -119,6 +119,9 @@
* When two plugins conflict, the source of both the losing and now the
winning definition is shown. (Konstantin Mikhaylov, #5454)
+ * 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 07:27:49 +0000
@@ -14,11 +14,21 @@
# 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 sys
+
+from bzrlib import ui
+from bzrlib.tests import (
+ Feature,
+ TestCaseWithTransport,
+ TestUIFactory,
+ )
+from bzrlib.tests import (
+ StringIOWrapper,
+ )
import bzrlib.transport
-class _MedusaFeature(tests.Feature):
+class _MedusaFeature(Feature):
"""Some tests want an FTP Server, check if one is available.
Right now, the only way this is available is if 'medusa' is installed.
@@ -39,7 +49,7 @@
MedusaFeature = _MedusaFeature()
-class TestCaseWithFTPServer(tests.TestCaseWithTransport):
+class TestCaseWithFTPServer(TestCaseWithTransport):
_test_needs_features = [MedusaFeature]
@@ -50,7 +60,7 @@
-class TestCaseAFTP(tests.TestCaseWithTransport):
+class TestCaseAFTP(TestCaseWithTransport):
"""Test aftp transport."""
def test_aftp_degrade(self):
@@ -71,3 +81,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 = 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 = 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 07:27:49 +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)
+ # Only 'foo' user is allowed for the tests
+ 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