~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-05-16 22:16:28 UTC
  • mfrom: (3428.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20080516221628-r3muhnav5c87z2nm
(vila) Warn when ignoring ssh password in authentication.conf
        (#203186)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1412
1412
            'SMTP %(user)s@%(host)s:%(port)d password: ',
1413
1413
            'smtp', port=10025)
1414
1414
 
 
1415
    def test_ssh_password_emits_warning(self):
 
1416
        conf = config.AuthenticationConfig(_file=StringIO(
 
1417
                """
 
1418
[ssh with password]
 
1419
scheme=ssh
 
1420
host=bar.org
 
1421
user=jim
 
1422
password=jimpass
 
1423
"""))
 
1424
        entered_password = 'typed-by-hand'
 
1425
        stdout = tests.StringIOWrapper()
 
1426
        ui.ui_factory = tests.TestUIFactory(stdin=entered_password + '\n',
 
1427
                                            stdout=stdout)
 
1428
 
 
1429
        # Since the password defined in the authentication config is ignored,
 
1430
        # the user is prompted
 
1431
        self.assertEquals(entered_password,
 
1432
                          conf.get_password('ssh', 'bar.org', user='jim'))
 
1433
        self.assertContainsRe(
 
1434
            self._get_log(keep_log_file=True),
 
1435
            'password ignored in section \[ssh with password\]')
 
1436
 
 
1437
    def test_ssh_without_password_doesnt_emit_warning(self):
 
1438
        conf = config.AuthenticationConfig(_file=StringIO(
 
1439
                """
 
1440
[ssh with password]
 
1441
scheme=ssh
 
1442
host=bar.org
 
1443
user=jim
 
1444
"""))
 
1445
        entered_password = 'typed-by-hand'
 
1446
        stdout = tests.StringIOWrapper()
 
1447
        ui.ui_factory = tests.TestUIFactory(stdin=entered_password + '\n',
 
1448
                                            stdout=stdout)
 
1449
 
 
1450
        # Since the password defined in the authentication config is ignored,
 
1451
        # the user is prompted
 
1452
        self.assertEquals(entered_password,
 
1453
                          conf.get_password('ssh', 'bar.org', user='jim'))
 
1454
        # No warning shoud be emitted since there is no password. We are only
 
1455
        # providing "user".
 
1456
        self.assertNotContainsRe(
 
1457
            self._get_log(keep_log_file=True),
 
1458
            'password ignored in section \[ssh with password\]')
 
1459
 
1415
1460
 
1416
1461
# FIXME: Once we have a way to declare authentication to all test servers, we
1417
1462
# can implement generic tests.