~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_sftp_transport.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-10-15 21:44:44 UTC
  • mfrom: (3777.1.7 ssh-authconfig)
  • Revision ID: pqm@pqm.ubuntu.com-20081015214444-ztwoizx180edy73v
Enable specifying default ssh username in authentication.conf

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
from bzrlib import (
31
31
    bzrdir,
 
32
    config,
32
33
    errors,
33
34
    tests,
34
35
    transport as _mod_transport,
483
484
        self.checkGetRequests([(0, 32768), (32768, 32768), (65536, 464)],
484
485
                              [(0, 40000), (40000, 100), (40100, 1900),
485
486
                               (42000, 24000)])
 
487
 
 
488
 
 
489
class TestUsesAuthConfig(TestCaseWithSFTPServer):
 
490
    """Test that AuthenticationConfig can supply default usernames."""
 
491
 
 
492
    def get_transport_for_connection(self, set_config):
 
493
        port = self.get_server()._listener.port
 
494
        if set_config:
 
495
            conf = config.AuthenticationConfig()
 
496
            conf._get_config().update(
 
497
                {'sftptest': {'scheme': 'ssh', 'port': port, 'user': 'bar'}})
 
498
            conf._save()
 
499
        t = get_transport('sftp://localhost:%d' % port)
 
500
        # force a connection to be performed.
 
501
        t.has('foo')
 
502
        return t
 
503
 
 
504
    def test_sftp_uses_config(self):
 
505
        t = self.get_transport_for_connection(set_config=True)
 
506
        self.assertEqual('bar', t._get_credentials()[0])
 
507
 
 
508
    def test_sftp_is_none_if_no_config(self):
 
509
        t = self.get_transport_for_connection(set_config=False)
 
510
        self.assertIs(None, t._get_credentials()[0])