625
617
"""Tests for connected to remote server transports"""
627
619
def test_parse_url(self):
628
t = ConnectedTransport('sftp://simple.example.com/home/source')
620
t = ConnectedTransport('http://simple.example.com/home/source')
629
621
self.assertEquals(t._host, 'simple.example.com')
630
self.assertEquals(t._port, 22)
622
self.assertEquals(t._port, 80)
631
623
self.assertEquals(t._path, '/home/source/')
632
624
self.failUnless(t._user is None)
633
625
self.failUnless(t._password is None)
635
self.assertEquals(t.base, 'sftp://simple.example.com/home/source/')
627
self.assertEquals(t.base, 'http://simple.example.com/home/source/')
637
629
def test_parse_quoted_url(self):
638
630
t = ConnectedTransport('http://ro%62ey:h%40t@ex%41mple.com:2222/path')
765
757
self.assertEquals('bzr://host.com:666/', t.base)
760
class SSHPortTestMixin(object):
761
"""Mixin class for testing SSH-based transports' use of ports in URLs.
763
Unlike other connected transports, SSH-based transports (sftp, bzr+ssh)
764
don't have a default port, because the user may have OpenSSH configured to
765
use a non-standard port.
768
def make_url(self, netloc):
769
"""Make a url for the given netloc, using the scheme defined on the
772
return '%s://%s/' % (self.scheme, netloc)
774
def test_relpath_with_implicit_port(self):
775
"""SSH-based transports with the same URL are the same.
777
Note than an unspecified port number is different to port 22 (because
778
OpenSSH may be configured to use a non-standard port).
780
So t.relpath(url) should always be '' if t.base is the same as url, but
781
raise PathNotChild if the ports in t and url are not both specified (or
784
url_implicit_port = self.make_url('host.com')
785
url_explicit_port = self.make_url('host.com:22')
787
t_implicit_port = get_transport(url_implicit_port)
788
self.assertEquals('', t_implicit_port.relpath(url_implicit_port))
790
PathNotChild, t_implicit_port.relpath, url_explicit_port)
792
t_explicit_port = get_transport(url_explicit_port)
794
PathNotChild, t_explicit_port.relpath, url_implicit_port)
795
self.assertEquals('', t_explicit_port.relpath(url_explicit_port))
797
def test_construct_with_no_port(self):
798
"""If no port is specified, then the SSH-based transport's _port will
801
t = get_transport(self.make_url('host.com'))
802
self.assertEquals(None, t._port)
804
def test_url_with_no_port(self):
805
"""If no port was specified, none is shown in the base URL."""
806
t = get_transport(self.make_url('host.com'))
807
self.assertEquals(self.make_url('host.com'), t.base)
809
def test_url_includes_port(self):
810
"""An SSH-based transport's base will show the port if one was
811
specified, even if that port is 22, because we do not assume 22 is the
814
# 22 is the "standard" port for SFTP.
815
t = get_transport(self.make_url('host.com:22'))
816
self.assertEquals(self.make_url('host.com:22'), t.base)
817
# 666 is not a standard port.
818
t = get_transport(self.make_url('host.com:666'))
819
self.assertEquals(self.make_url('host.com:666'), t.base)
822
class SFTPTransportPortTest(TestCase, SSHPortTestMixin):
823
"""Tests for sftp:// transport (SFTPTransport)."""
828
class BzrSSHTransportPortTest(TestCase, SSHPortTestMixin):
829
"""Tests for bzr+ssh:// transport (RemoteSSHTransport)."""
768
834
class TestTransportTrace(TestCase):
770
836
def test_get(self):