Ejemplo n.º 1
0
    def test_abspath(self):
        # The abspath is always relative to the chroot_url.
        server = ChrootServer(get_transport('memory:///foo/bar/'))
        server.setUp()
        transport = get_transport(server.get_url())
        self.assertEqual(server.get_url(), transport.abspath('/'))

        subdir_transport = transport.clone('subdir')
        self.assertEqual(server.get_url(), subdir_transport.abspath('/'))
        server.tearDown()
Ejemplo n.º 2
0
    def test_abspath(self):
        # The abspath is always relative to the chroot_url.
        server = ChrootServer(get_transport('memory:///foo/bar/'))
        server.setUp()
        transport = get_transport(server.get_url())
        self.assertEqual(server.get_url(), transport.abspath('/'))

        subdir_transport = transport.clone('subdir')
        self.assertEqual(server.get_url(), subdir_transport.abspath('/'))
        server.tearDown()
Ejemplo n.º 3
0
 def _initialize_bazaar_server(self, directory, server_port):
     from bzrlib import urlutils
     from bzrlib.transport import get_transport
     from bzrlib.transport.chroot import ChrootServer
     url = urlutils.local_path_to_url(directory)
     url = 'readonly+' + url
     print url
     chroot_server = ChrootServer(get_transport(url))
     chroot_server.setUp()
     t = get_transport(chroot_server.get_url())
     print chroot_server.get_url()
     self._bazaar_server = SmartTCPServer(
         t, 'localhost', server_port)
     self._bazaar_server.start_background_thread()
Ejemplo n.º 4
0
 def test_clone(self):
     server = ChrootServer(get_transport('memory:///foo/bar/'))
     server.setUp()
     transport = get_transport(server.get_url())
     # relpath from root and root path are the same
     relpath_cloned = transport.clone('foo')
     abspath_cloned = transport.clone('/foo')
     self.assertEqual(server, relpath_cloned.server)
     self.assertEqual(server, abspath_cloned.server)
     server.tearDown()
Ejemplo n.º 5
0
 def test_clone(self):
     server = ChrootServer(get_transport('memory:///foo/bar/'))
     server.setUp()
     transport = get_transport(server.get_url())
     # relpath from root and root path are the same
     relpath_cloned = transport.clone('foo')
     abspath_cloned = transport.clone('/foo')
     self.assertEqual(server, relpath_cloned.server)
     self.assertEqual(server, abspath_cloned.server)
     server.tearDown()
Ejemplo n.º 6
0
class SmartTCPServer_for_testing(SmartTCPServer):
    """Server suitable for use by transport tests.
    
    This server is backed by the process's cwd.
    """

    def __init__(self, thread_name_suffix=''):
        SmartTCPServer.__init__(self, None)
        self.client_path_extra = None
        self.thread_name_suffix = thread_name_suffix
        
    def get_backing_transport(self, backing_transport_server):
        """Get a backing transport from a server we are decorating."""
        return transport.get_transport(backing_transport_server.get_url())

    def setUp(self, backing_transport_server=None,
              client_path_extra='/extra/'):
        """Set up server for testing.
        
        :param backing_transport_server: backing server to use.  If not
            specified, a LocalURLServer at the current working directory will
            be used.
        :param client_path_extra: a path segment starting with '/' to append to
            the root URL for this server.  For instance, a value of '/foo/bar/'
            will mean the root of the backing transport will be published at a
            URL like `bzr://127.0.0.1:nnnn/foo/bar/`, rather than
            `bzr://127.0.0.1:nnnn/`.  Default value is `extra`, so that tests
            by default will fail unless they do the necessary path translation.
        """
        if not client_path_extra.startswith('/'):
            raise ValueError(client_path_extra)
        from bzrlib.transport.chroot import ChrootServer
        if backing_transport_server is None:
            from bzrlib.transport.local import LocalURLServer
            backing_transport_server = LocalURLServer()
        self.chroot_server = ChrootServer(
            self.get_backing_transport(backing_transport_server))
        self.chroot_server.setUp()
        self.backing_transport = transport.get_transport(
            self.chroot_server.get_url())
        self.root_client_path = self.client_path_extra = client_path_extra
        self.start_background_thread(self.thread_name_suffix)

    def tearDown(self):
        self.stop_background_thread()
        self.chroot_server.tearDown()

    def get_url(self):
        url = super(SmartTCPServer_for_testing, self).get_url()
        return url[:-1] + self.client_path_extra

    def get_bogus_url(self):
        """Return a URL which will fail to connect"""
        return 'bzr://127.0.0.1:1/'
Ejemplo n.º 7
0
    def test_switch_branches(self):
        # switch_branches moves a branch to the new location and places a
        # branch (with no revisions) stacked on the new branch in the old
        # location.

        chroot_server = ChrootServer(self.get_transport())
        chroot_server.start_server()
        self.addCleanup(chroot_server.stop_server)
        scheme = chroot_server.get_url().rstrip('/:')

        old_branch = FakeBranch(1)
        self.get_transport(old_branch.unique_name).create_prefix()
        tree = self.make_branch_and_tree(old_branch.unique_name)
        # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
        # required to generate the revision-id.
        with override_environ(BZR_EMAIL='*****@*****.**'):
            tree.commit(message='.')

        new_branch = FakeBranch(2)

        switch_branches('.', scheme, old_branch, new_branch)

        # Post conditions:
        # 1. unstacked branch in new_branch's location
        # 2. stacked branch with no revisions in repo at old_branch
        # 3. last_revision() the same for two branches

        old_location_bzrdir = BzrDir.open(
            str(URI(scheme=scheme, host='',
                    path='/' + old_branch.unique_name)))
        new_location_bzrdir = BzrDir.open(
            str(URI(scheme=scheme, host='',
                    path='/' + new_branch.unique_name)))

        old_location_branch = old_location_bzrdir.open_branch()
        new_location_branch = new_location_bzrdir.open_branch()

        # 1. unstacked branch in new_branch's location
        self.assertRaises(NotStacked, new_location_branch.get_stacked_on_url)

        # 2. stacked branch with no revisions in repo at old_branch
        self.assertEqual('/' + new_branch.unique_name,
                         old_location_branch.get_stacked_on_url())
        self.assertEqual(
            [],
            old_location_bzrdir.open_repository().all_revision_ids())

        # 3. last_revision() the same for two branches
        self.assertEqual(old_location_branch.last_revision(),
                         new_location_branch.last_revision())
Ejemplo n.º 8
0
    def test_urljoin_preserves_chroot(self):
        """Using urlutils.join(url, '..') on a chroot URL should not produce a
        URL that escapes the intended chroot.

        This is so that it is not possible to escape a chroot by doing::
            url = chroot_transport.base
            parent_url = urlutils.join(url, '..')
            new_transport = get_transport(parent_url)
        """
        server = ChrootServer(get_transport('memory:///path/'))
        server.setUp()
        transport = get_transport(server.get_url())
        self.assertRaises(InvalidURLJoin, urlutils.join, transport.base, '..')
        server.tearDown()
Ejemplo n.º 9
0
    def test_urljoin_preserves_chroot(self):
        """Using urlutils.join(url, '..') on a chroot URL should not produce a
        URL that escapes the intended chroot.

        This is so that it is not possible to escape a chroot by doing::
            url = chroot_transport.base
            parent_url = urlutils.join(url, '..')
            new_transport = get_transport(parent_url)
        """
        server = ChrootServer(get_transport('memory:///path/'))
        server.setUp()
        transport = get_transport(server.get_url())
        self.assertRaises(
            InvalidURLJoin, urlutils.join, transport.base, '..')
        server.tearDown()
Ejemplo n.º 10
0
    def test_chroot_url_preserves_chroot(self):
        """Calling get_transport on a chroot transport's base should produce a
        transport with exactly the same behaviour as the original chroot
        transport.

        This is so that it is not possible to escape a chroot by doing::
            url = chroot_transport.base
            parent_url = urlutils.join(url, '..')
            new_transport = get_transport(parent_url)
        """
        server = ChrootServer(get_transport('memory:///path/subpath'))
        server.setUp()
        transport = get_transport(server.get_url())
        new_transport = get_transport(transport.base)
        self.assertEqual(transport.server, new_transport.server)
        self.assertEqual(transport.base, new_transport.base)
        server.tearDown()
Ejemplo n.º 11
0
    def test_chroot_url_preserves_chroot(self):
        """Calling get_transport on a chroot transport's base should produce a
        transport with exactly the same behaviour as the original chroot
        transport.

        This is so that it is not possible to escape a chroot by doing::
            url = chroot_transport.base
            parent_url = urlutils.join(url, '..')
            new_transport = get_transport(parent_url)
        """
        server = ChrootServer(get_transport('memory:///path/subpath'))
        server.setUp()
        transport = get_transport(server.get_url())
        new_transport = get_transport(transport.base)
        self.assertEqual(transport.server, new_transport.server)
        self.assertEqual(transport.base, new_transport.base)
        server.tearDown()
Ejemplo n.º 12
0
    def test_switch_branches(self):
        # switch_branches moves a branch to the new location and places a
        # branch (with no revisions) stacked on the new branch in the old
        # location.

        chroot_server = ChrootServer(self.get_transport())
        chroot_server.start_server()
        self.addCleanup(chroot_server.stop_server)
        scheme = chroot_server.get_url().rstrip("/:")

        old_branch = FakeBranch(1)
        self.get_transport(old_branch.unique_name).create_prefix()
        tree = self.make_branch_and_tree(old_branch.unique_name)
        # XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
        # required to generate the revision-id.
        with override_environ(BZR_EMAIL="*****@*****.**"):
            tree.commit(message=".")

        new_branch = FakeBranch(2)

        switch_branches(".", scheme, old_branch, new_branch)

        # Post conditions:
        # 1. unstacked branch in new_branch's location
        # 2. stacked branch with no revisions in repo at old_branch
        # 3. last_revision() the same for two branches

        old_location_bzrdir = BzrDir.open(str(URI(scheme=scheme, host="", path="/" + old_branch.unique_name)))
        new_location_bzrdir = BzrDir.open(str(URI(scheme=scheme, host="", path="/" + new_branch.unique_name)))

        old_location_branch = old_location_bzrdir.open_branch()
        new_location_branch = new_location_bzrdir.open_branch()

        # 1. unstacked branch in new_branch's location
        self.assertRaises(NotStacked, new_location_branch.get_stacked_on_url)

        # 2. stacked branch with no revisions in repo at old_branch
        self.assertEqual("/" + new_branch.unique_name, old_location_branch.get_stacked_on_url())
        self.assertEqual([], old_location_bzrdir.open_repository().all_revision_ids())

        # 3. last_revision() the same for two branches
        self.assertEqual(old_location_branch.last_revision(), new_location_branch.last_revision())
Ejemplo n.º 13
0
 def test_get_url(self):
     backing_transport = MemoryTransport()
     server = ChrootServer(backing_transport)
     server.setUp()
     self.assertEqual('chroot-%d:///' % id(server), server.get_url())
     server.tearDown()
Ejemplo n.º 14
0
 def test_get_url(self):
     backing_transport = MemoryTransport()
     server = ChrootServer(backing_transport)
     server.setUp()
     self.assertEqual('chroot-%d:///' % id(server), server.get_url())
     server.tearDown()