Rev 3521: Fix last failing tests under python2.6. in file:///net/bigmamac/Volumes/home/vila/src/bzr/experimental/more-ftp/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Mar 3 15:47:52 GMT 2009


At file:///net/bigmamac/Volumes/home/vila/src/bzr/experimental/more-ftp/

------------------------------------------------------------
revno: 3521
revision-id: v.ladeuil+lp at free.fr-20090303154749-61puv7w8t2pnz7zm
parent: v.ladeuil+lp at free.fr-20090302195435-goqqmr9lhwr5z03u
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: pyftpdlib
timestamp: Tue 2009-03-03 16:47:49 +0100
message:
  Fix last failing tests under python2.6.
  
  * bzrlib/tests/ftp_server/pyftpdlib_based.py:
  (FTPServer.get_url, FTPServer.setUp): Because medusa authorized
  connections without checking the password, we have tests that more
  or less relies on that behavior in direct or indirect ways. The
  simplest solution is to give write access to anonymous with
  pyftpdlib and test authentication in a separate test.
  
  * bzrlib/tests/test_ftp_transport.py:
  (TestFTPServerUI.setUp, TestFTPServerUI.get_url): Implementation
  compatible with medusa and pyftplib.
  (TestFTPServerUI.test_prompt_for_password,
  TestFTPServerUI.test_no_prompt_for_password_when_using_auth_config):
  Simplified.
  
  * bzrlib/tests/ftp_server/medusa_based.py:
  (FTPServer.add_user): Factored out from
  bzrlib.tests.test_ftp_transport.TestFTPServerUI._add_authorized_user
  since that's specific to our medusa based ftp server.
  
  * bzrlib/tests/test_transport_implementations.py:
  (TransportTests.test_connect_twice_is_same_content): Previous fix
  was incorrect, '.base' contained the needed server prefix, using
  self.get_transport instead of the basre get_transport provides the
  wanted feature.
-------------- next part --------------
=== modified file 'bzrlib/tests/ftp_server/medusa_based.py'
--- a/bzrlib/tests/ftp_server/medusa_based.py	2009-02-27 13:26:13 +0000
+++ b/bzrlib/tests/ftp_server/medusa_based.py	2009-03-03 15:47:49 +0000
@@ -279,6 +279,9 @@
             if e.args[0] != errno.EBADF:
                 raise
 
-
-
+    def add_user(self, user, password):
+        """Add a user with write access."""
+        authorizer = server = self._ftp_server.authorizer
+        authorizer.secured_user = user
+        authorizer.secured_password = password
 

=== modified file 'bzrlib/tests/ftp_server/pyftpdlib_based.py'
--- a/bzrlib/tests/ftp_server/pyftpdlib_based.py	2009-03-02 19:54:35 +0000
+++ b/bzrlib/tests/ftp_server/pyftpdlib_based.py	2009-03-03 15:47:49 +0000
@@ -149,7 +149,7 @@
 
     def get_url(self):
         """Calculate an ftp url to this server."""
-        return 'ftp://foo:bar@localhost:%d/' % (self._port)
+        return 'ftp://anonymous@localhost:%d/' % (self._port)
 
     def get_bogus_url(self):
         """Return a URL which cannot be connected to."""
@@ -169,7 +169,7 @@
 
         address = ('localhost', 0) # bind to a random port
         authorizer = AnonymousWithWriteAccessAuthorizer()
-        authorizer.add_user('foo', 'bar', self._root, perm='elradfmw')
+        authorizer.add_anonymous(self._root, perm='elradfmw')
         self._ftp_server = ftp_server(address, BZRConformingFTPHandler,
                                       authorizer)
         # This is hacky as hell, will not work if we need two servers working
@@ -209,3 +209,8 @@
         while self._ftpd_running:
             self._ftp_server.serve_forever(timeout=0.1, count=1)
         self._ftp_server.close_all(ignore_all=True)
+
+    def add_user(self, user, password):
+        """Add a user with write access."""
+        self._ftp_server.authorizer.add_user(user, password, self._root,
+                                             perm='elradfmw')

=== modified file 'bzrlib/tests/test_ftp_transport.py'
--- a/bzrlib/tests/test_ftp_transport.py	2009-02-27 13:26:13 +0000
+++ b/bzrlib/tests/test_ftp_transport.py	2009-03-03 15:47:49 +0000
@@ -69,26 +69,25 @@
 
 class TestFTPServerUI(TestCaseWithFTPServer):
 
-    def _add_authorized_user(self, user, 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 = user
-        authorizer.secured_password = password
+    def setUp(self):
+        super(TestFTPServerUI, self).setUp()
+        self.user = 'joe'
+        self.password = 'secret'
+        self.get_server().add_user(self.user, self.password)
+
+    def get_url(self, relpath=None):
+        """Overrides get_url to inject our user."""
+        base = super(TestFTPServerUI, self).get_url(relpath)
+        (scheme, user, password,
+         host, port, path) = transport.ConnectedTransport._split_url(base)
+        url = transport.ConnectedTransport._unsplit_url(
+            scheme, self.user, self.password, host, port, path)
+        return url
 
     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',
+        ui.ui_factory = tests.TestUIFactory(stdin=self.password+'\n',
                                             stdout=tests.StringIOWrapper())
-        # Ask the server to check the password
-        self._add_authorized_user(t._user, password)
         # Issue a request to the server to connect
         t.has('whatever/not/existing')
         # stdin should be empty (the provided password have been consumed)
@@ -96,20 +95,13 @@
 
     def test_no_prompt_for_password_when_using_auth_config(self):
         t = self.get_transport()
-        # 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='precious\n',
                                             stdout=tests.StringIOWrapper())
-        # Ask the server to check the password
-        self._add_authorized_user(t._user, password)
-
         # Create a config file with the right password
         conf = config.AuthenticationConfig()
         conf._get_config().update({'ftptest': {'scheme': 'ftp',
-                                               'user': t._user,
-                                               'password': password}})
+                                               'user': self.user,
+                                               'password': self.password}})
         conf._save()
         # Issue a request to the server to connect
         t.put_bytes('foo', 'test bytes\n')

=== modified file 'bzrlib/tests/test_transport_implementations.py'
--- a/bzrlib/tests/test_transport_implementations.py	2009-03-01 10:02:00 +0000
+++ b/bzrlib/tests/test_transport_implementations.py	2009-03-03 15:47:49 +0000
@@ -1515,7 +1515,7 @@
 
         # now opening at a relative url should give use a sane result:
         transport.mkdir('newdir')
-        transport5 = get_transport("newdir")
+        transport5 = self.get_transport('newdir')
         transport6 = transport5.clone('..')
         self.check_transport_contents('bar', transport6, 'foo')
 



More information about the bazaar-commits mailing list