~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-12-05 18:15:54 UTC
  • mfrom: (3881.1.1 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20081205181554-ofrdnafloc43bxkh
(jam) Merge the summary message for bzr-1.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
"""Tests for finding and reading the bzr config file[s]."""
19
19
# import system imports here
150
150
        self._transport = self.control_files = \
151
151
            FakeControlFilesAndTransport(user_id=user_id)
152
152
 
153
 
    def _get_config(self):
154
 
        return config.TransportConfig(self._transport, 'branch.conf')
155
 
 
156
153
    def lock_write(self):
157
154
        pass
158
155
 
428
425
        locations = config.locations_config_filename()
429
426
        config.ensure_config_dir_exists()
430
427
        local_url = urlutils.local_path_to_url('branch')
431
 
        open(locations, 'wb').write('[%s]\nnickname = foobar'
 
428
        open(locations, 'wb').write('[%s]\nnickname = foobar' 
432
429
                                    % (local_url,))
433
430
        self.assertEqual('foobar', branch.nick)
434
431
 
439
436
 
440
437
        locations = config.locations_config_filename()
441
438
        config.ensure_config_dir_exists()
442
 
        open(locations, 'wb').write('[%s/branch]\nnickname = barry'
 
439
        open(locations, 'wb').write('[%s/branch]\nnickname = barry' 
443
440
                                    % (osutils.getcwd().encode('utf8'),))
444
441
        self.assertEqual('barry', branch.nick)
445
442
 
1266
1263
"""))
1267
1264
        self.assertRaises(ValueError, conf.get_credentials, 'ftp', 'foo.net')
1268
1265
 
1269
 
    def test_unknown_password_encoding(self):
1270
 
        conf = config.AuthenticationConfig(_file=StringIO(
1271
 
                """[broken]
1272
 
scheme=ftp
1273
 
user=joe
1274
 
password_encoding=unknown
1275
 
"""))
1276
 
        self.assertRaises(ValueError, conf.get_password,
1277
 
                          'ftp', 'foo.net', 'joe')
1278
 
 
1279
1266
    def test_credentials_for_scheme_host(self):
1280
1267
        conf = config.AuthenticationConfig(_file=StringIO(
1281
1268
                """# Identity on foo.net
1430
1417
    def test_set_credentials(self):
1431
1418
        conf = config.AuthenticationConfig()
1432
1419
        conf.set_credentials('name', 'host', 'user', 'scheme', 'password',
1433
 
        99, path='/foo', verify_certificates=False, realm='realm')
 
1420
        99, path='/foo', verify_certificates=False)
1434
1421
        credentials = conf.get_credentials(host='host', scheme='scheme',
1435
 
                                           port=99, path='/foo',
1436
 
                                           realm='realm')
 
1422
                                           port=99, path='/foo')
1437
1423
        CREDENTIALS = {'name': 'name', 'user': 'user', 'password': 'password',
1438
 
                       'verify_certificates': False, 'scheme': 'scheme', 
1439
 
                       'host': 'host', 'port': 99, 'path': '/foo', 
1440
 
                       'realm': 'realm'}
 
1424
                       'verify_certificates': False,}
1441
1425
        self.assertEqual(CREDENTIALS, credentials)
1442
1426
        credentials_from_disk = config.AuthenticationConfig().get_credentials(
1443
 
            host='host', scheme='scheme', port=99, path='/foo', realm='realm')
 
1427
            host='host', scheme='scheme', port=99, path='/foo')
1444
1428
        self.assertEqual(CREDENTIALS, credentials_from_disk)
1445
1429
 
1446
1430
    def test_reset_credentials_different_name(self):
1450
1434
        self.assertIs(None, conf._get_config().get('name'))
1451
1435
        credentials = conf.get_credentials(host='host', scheme='scheme')
1452
1436
        CREDENTIALS = {'name': 'name2', 'user': 'user2', 'password':
1453
 
                       'password', 'verify_certificates': True, 
1454
 
                       'scheme': 'scheme', 'host': 'host', 'port': None, 
1455
 
                       'path': None, 'realm': None}
 
1437
                       'password', 'verify_certificates': True}
1456
1438
        self.assertEqual(CREDENTIALS, credentials)
1457
1439
 
1458
1440
 
1544
1526
            'password ignored in section \[ssh with password\]')
1545
1527
 
1546
1528
 
1547
 
class TestCredentialStoreRegistry(tests.TestCase):
1548
 
 
1549
 
    def _get_cs_registry(self):
1550
 
        return config.credential_store_registry
1551
 
 
1552
 
    def test_default_credential_store(self):
1553
 
        r = self._get_cs_registry()
1554
 
        default = r.get_credential_store(None)
1555
 
        self.assertIsInstance(default, config.PlainTextCredentialStore)
1556
 
 
1557
 
    def test_unknown_credential_store(self):
1558
 
        r = self._get_cs_registry()
1559
 
        # It's hard to imagine someone creating a credential store named
1560
 
        # 'unknown' so we use that as an never registered key.
1561
 
        self.assertRaises(KeyError, r.get_credential_store, 'unknown')
1562
 
 
1563
 
 
1564
 
class TestPlainTextCredentialStore(tests.TestCase):
1565
 
 
1566
 
    def test_decode_password(self):
1567
 
        r = config.credential_store_registry
1568
 
        plain_text = r.get_credential_store()
1569
 
        decoded = plain_text.decode_password(dict(password='secret'))
1570
 
        self.assertEquals('secret', decoded)
1571
 
 
1572
 
 
1573
1529
# FIXME: Once we have a way to declare authentication to all test servers, we
1574
1530
# can implement generic tests.
1575
1531
# test_user_password_in_url