예제 #1
0
 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)
예제 #2
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()
예제 #3
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()
예제 #4
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())
예제 #5
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()
예제 #6
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()
예제 #7
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()
예제 #8
0
 def test_tearDown(self):
     backing_transport = MemoryTransport()
     server = ChrootServer(backing_transport)
     server.setUp()
     server.tearDown()
     self.assertFalse(server.scheme in _get_protocol_handlers().keys())
예제 #9
0
 def test_construct(self):
     backing_transport = MemoryTransport()
     server = ChrootServer(backing_transport)
     self.assertEqual(backing_transport, server.backing_transport)