~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport.py

  • Committer: Andrew Bennetts
  • Date: 2007-10-08 02:22:17 UTC
  • mto: This revision was merged to the branch mainline in revision 2900.
  • Revision ID: andrew.bennetts@canonical.com-20071008022217-8gxkimbur9vzgbav
Fix bug 146715: bzr+ssh:// and sftp:// should not assume port-not-specified means port 22

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
 
import os
19
 
import sys
20
 
import stat
21
18
from cStringIO import StringIO
22
19
 
23
20
import bzrlib
26
23
    osutils,
27
24
    urlutils,
28
25
    )
29
 
from bzrlib.errors import (ConnectionError,
30
 
                           DependencyNotPresent,
 
26
from bzrlib.errors import (DependencyNotPresent,
31
27
                           FileExists,
32
28
                           InvalidURLJoin,
33
29
                           NoSuchFile,
34
30
                           PathNotChild,
35
 
                           TransportNotPossible,
36
 
                           ConnectionError,
37
 
                           DependencyNotPresent,
38
31
                           ReadError,
39
32
                           UnsupportedProtocol,
40
33
                           )
49
42
                              LateReadError,
50
43
                              register_lazy_transport,
51
44
                              register_transport_proto,
52
 
                              _clear_protocol_handlers,
53
45
                              Transport,
54
46
                              )
55
47
from bzrlib.transport.chroot import ChrootServer
625
617
    """Tests for connected to remote server transports"""
626
618
 
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)
634
626
 
635
 
        self.assertEquals(t.base, 'sftp://simple.example.com/home/source/')
 
627
        self.assertEquals(t.base, 'http://simple.example.com/home/source/')
636
628
 
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)
766
758
 
767
759
 
 
760
class SSHPortTestMixin(object):
 
761
    """Mixin class for testing SSH-based transports' use of ports in URLs.
 
762
    
 
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.
 
766
    """
 
767
 
 
768
    def make_url(self, netloc):
 
769
        """Make a url for the given netloc, using the scheme defined on the
 
770
        TestCase.
 
771
        """
 
772
        return '%s://%s/' % (self.scheme, netloc)
 
773
 
 
774
    def test_relpath_with_implicit_port(self):
 
775
        """SSH-based transports with the same URL are the same.
 
776
        
 
777
        Note than an unspecified port number is different to port 22 (because
 
778
        OpenSSH may be configured to use a non-standard port).
 
779
 
 
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
 
782
        both unspecified).
 
783
        """
 
784
        url_implicit_port = self.make_url('host.com')
 
785
        url_explicit_port = self.make_url('host.com:22')
 
786
 
 
787
        t_implicit_port = get_transport(url_implicit_port)
 
788
        self.assertEquals('', t_implicit_port.relpath(url_implicit_port))
 
789
        self.assertRaises(
 
790
            PathNotChild, t_implicit_port.relpath, url_explicit_port)
 
791
        
 
792
        t_explicit_port = get_transport(url_explicit_port)
 
793
        self.assertRaises(
 
794
            PathNotChild, t_explicit_port.relpath, url_implicit_port)
 
795
        self.assertEquals('', t_explicit_port.relpath(url_explicit_port))
 
796
 
 
797
    def test_construct_with_no_port(self):
 
798
        """If no port is specified, then the SSH-based transport's _port will
 
799
        be None.
 
800
        """
 
801
        t = get_transport(self.make_url('host.com'))
 
802
        self.assertEquals(None, t._port)
 
803
 
 
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)
 
808
 
 
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
 
812
        default port.
 
813
        """
 
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)
 
820
 
 
821
 
 
822
class SFTPTransportPortTest(TestCase, SSHPortTestMixin):
 
823
    """Tests for sftp:// transport (SFTPTransport)."""
 
824
 
 
825
    scheme = 'sftp'
 
826
 
 
827
 
 
828
class BzrSSHTransportPortTest(TestCase, SSHPortTestMixin):
 
829
    """Tests for bzr+ssh:// transport (RemoteSSHTransport)."""
 
830
 
 
831
    scheme = 'bzr+ssh'
 
832
 
 
833
 
768
834
class TestTransportTrace(TestCase):
769
835
 
770
836
    def test_get(self):