Rev 2914: More tests. in http://code.launchpad.net/%7Ev-ladeuil/bzr/auth.ring

Vincent Ladeuil v.ladeuil+lp at free.fr
Sun Oct 21 11:49:39 BST 2007


At http://code.launchpad.net/%7Ev-ladeuil/bzr/auth.ring

------------------------------------------------------------
revno: 2914
revision-id: v.ladeuil+lp at free.fr-20071021104922-lc4hyrz0g06sj5u9
parent: v.ladeuil+lp at free.fr-20071021085941-w5ji5t385d8b5o26
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: auth.ring
timestamp: Sun 2007-10-21 12:49:22 +0200
message:
  More tests.
  
  * bzrlib/tests/test_config.py:
  (TestAuthenticationConfig): Add tests for default prompts.
  
  * bzrlib/config.py:
  (AuthenticationConfig.get_password): Oops, remove debug statement.
modified:
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
  bzrlib/tests/test_ftp_transport.py test_aftp_transport.-20060823221619-98mwjzxtwtkt527k-1
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2007-10-20 16:49:14 +0000
+++ b/bzrlib/config.py	2007-10-21 10:49:22 +0000
@@ -1082,7 +1082,6 @@
             password = credentials['password']
         else:
             # Prompt user only if we could't find a password
-            print 'couco'
             if prompt is None:
                 prompt = ('%s' % scheme.upper()
                           + ' %(user)s@%(host)s%(realm)s password')

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2007-10-17 15:36:20 +0000
+++ b/bzrlib/tests/test_config.py	2007-10-21 10:49:22 +0000
@@ -30,6 +30,7 @@
     errors,
     osutils,
     mail_client,
+    ui,
     urlutils,
     tests,
     trace,
@@ -1118,7 +1119,7 @@
 
 
 class TestAuthenticationConfigFile(tests.TestCase):
-    """Test the authentication.conf file matching."""
+    """Test the authentication.conf file matching"""
 
     # XXX: test definitions without users.
 
@@ -1287,7 +1288,62 @@
         self.assertEquals(True, credentials.get('verify_certificates'))
 
 
-# FIXME: Once we had a way to declare authentication to all test servers, we
+class TestAuthenticationConfig(tests.TestCase):
+    """Test AuthenticationConfig behaviour"""
+
+    def _check_default_prompt(self, expected_prompt_format, scheme,
+                              host=None, port=None, realm=None, path=None):
+        if host is None:
+            host = 'bar.org'
+        user, password = 'jim', 'precious'
+        expected_prompt = expected_prompt_format % {
+            'scheme': scheme, 'host': host, 'port': port,
+            'user': user, 'realm': realm}
+
+        stdout = tests.StringIOWrapper()
+        ui.ui_factory = tests.TestUIFactory(stdin=password + '\n',
+                                            stdout=stdout)
+        # We use an empty conf so that the user is always prompted
+        conf = config.AuthenticationConfig()
+        self.assertEquals(password,
+                          conf.get_password(scheme, host, user, port=port,
+                                            realm=realm, path=path))
+        self.assertEquals(stdout.getvalue(), expected_prompt)
+
+    def test_default_prompts(self):
+        self._check_default_prompt('FTP %(user)s@%(host)s password: ', 'ftp')
+        self._check_default_prompt('FTP %(user)s@%(host)s:%(port)d password: ',
+                                   'ftp', port=10020)
+
+        self._check_default_prompt('SSH %(user)s@%(host)s:%(port)d password: ',
+                                   'ssh', port=12345)
+        # SMTP port handling is a bit special (it's handled if embedded in the
+        # host too)
+        # FIXME: should we forbid that or extend it to other schemes ?
+        self._check_default_prompt('SMTP %(user)s@%(host)s password: ',
+                                   'smtp')
+        self._check_default_prompt('SMTP %(user)s@%(host)s password: ',
+                                   'smtp', host='bar.org:10025')
+        self._check_default_prompt(
+            'SMTP %(user)s@%(host)s:%(port)d password: ',
+            'smtp', port=10025)
+
+        self._check_default_prompt('HTTP %(user)s@%(host)s password: ',
+                                   'http')
+        self._check_default_prompt(
+            "HTTP %(user)s@%(host)s, Realm: '%(realm)s' password: ",
+            'http', realm='bzr')
+        self._check_default_prompt(
+            "HTTP %(user)s@%(host)s:%(port)d, Realm: '%(realm)s' password: ",
+            'http', realm='bzr', port=10080)
+
+        # FIXME: the following pass but the real implementation
+        # (_urllib2_wrappers) do not use the default prompt and displays HTTP
+        # instead of HTTPS
+        self._check_default_prompt('HTTPS %(user)s@%(host)s password: ',
+                                   'https')
+
+# FIXME: Once we have a way to declare authentication to all test servers, we
 # can implement generic tests.
 class TestAuthenticationRing(tests.TestCaseWithTransport):
     pass

=== modified file 'bzrlib/tests/test_ftp_transport.py'
--- a/bzrlib/tests/test_ftp_transport.py	2007-10-20 16:49:14 +0000
+++ b/bzrlib/tests/test_ftp_transport.py	2007-10-21 10:49:22 +0000
@@ -122,7 +122,8 @@
 
         # Create a config file with the right password
         conf = config.AuthenticationConfig()
-        conf._get_config().update({'ftptest': {'scheme': 'ftp', 'user': t._user,
+        conf._get_config().update({'ftptest': {'scheme': 'ftp',
+                                               'user': t._user,
                                                'password': password}})
         conf._save()
         # Issue a request to the server to connect



More information about the bazaar-commits mailing list