~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Vincent Ladeuil
  • Date: 2008-10-05 21:32:00 UTC
  • mto: (3926.1.1 bzr.integration)
  • mto: This revision was merged to the branch mainline in revision 3928.
  • Revision ID: v.ladeuil+lp@free.fr-20081005213200-tbgbnnhq6rjabnlz
Add credential stores plugging.

* tests/test_config.py:
(TestAuthenticationConfigFile.test_unknown_password_encoding):
Test that the user get a meaningful error on typos or installation
problems.
(TestCredentialStoreRegistry): Basic tests for the registry.
(TestPlainTextCredentialStore): Test plain text credential store.

* config.py:
(AuthenticationConfig.decode_password): Go through the credential
store registry to decode the password.
(CredentialStoreRegistry): New registry for credential stores.
(CredentialStore): Abstract base class for credential stores.
(PlainTextCredentialStore): Default, plain text, credential store,
using authentication.conf file itself as storage(i.e actual
behavior).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1263
1263
"""))
1264
1264
        self.assertRaises(ValueError, conf.get_credentials, 'ftp', 'foo.net')
1265
1265
 
 
1266
    def test_unknown_password_encoding(self):
 
1267
        conf = config.AuthenticationConfig(_file=StringIO(
 
1268
                """[broken]
 
1269
scheme=ftp
 
1270
user=joe
 
1271
password_encoding=unknown
 
1272
"""))
 
1273
        self.assertRaises(ValueError, conf.get_password,
 
1274
                          'ftp', 'foo.net', 'joe')
 
1275
 
1266
1276
    def test_credentials_for_scheme_host(self):
1267
1277
        conf = config.AuthenticationConfig(_file=StringIO(
1268
1278
                """# Identity on foo.net
1500
1510
            'password ignored in section \[ssh with password\]')
1501
1511
 
1502
1512
 
 
1513
class TestCredentialStoreRegistry(tests.TestCase):
 
1514
 
 
1515
    def _get_cs_registry(self):
 
1516
        return config.credential_store_registry
 
1517
 
 
1518
    def test_default_credential_store(self):
 
1519
        r = self._get_cs_registry()
 
1520
        default = r.get_credential_store(None)
 
1521
        self.assertIsInstance(default, config.PlainTextCredentialStore)
 
1522
 
 
1523
    def test_unknown_credential_store(self):
 
1524
        r = self._get_cs_registry()
 
1525
        # It's hard to imagine someone creating a credential store named
 
1526
        # 'unknown' so we use that as an never registered key.
 
1527
        self.assertRaises(KeyError, r.get_credential_store, 'unknown')
 
1528
 
 
1529
 
 
1530
class TestPlainTextCredentialStore(tests.TestCase):
 
1531
 
 
1532
    def test_decode_password(self):
 
1533
        r = config.credential_store_registry
 
1534
        plain_text = r.get_credential_store()
 
1535
        decoded = plain_text.decode_password(dict(password='secret'))
 
1536
        self.assertEquals('secret', decoded)
 
1537
 
 
1538
 
1503
1539
# FIXME: Once we have a way to declare authentication to all test servers, we
1504
1540
# can implement generic tests.
1505
1541
# test_user_password_in_url