Example #1
0
    def start_server(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)
        self.root_client_path = self.client_path_extra = client_path_extra
        from breezy.transport.chroot import ChrootServer
        if backing_transport_server is None:
            backing_transport_server = LocalURLServer()
        self.chroot_server = ChrootServer(
            self.get_backing_transport(backing_transport_server))
        self.chroot_server.start_server()
        self.backing_transport = transport.get_transport_from_url(
            self.chroot_server.get_url())
        super(SmartTCPServer_for_testing, self).start_server()
Example #2
0
    def test_format_initialize_find_open(self):
        # loopback test to check the current format initializes to itself.
        if not self.branch_format.is_supported():
            # unsupported formats are not loopback testable
            # because the default open will not open them and
            # they may not be initializable.
            return
        # supported formats must be able to init and open
        t = self.get_transport()
        readonly_t = transport.get_transport_from_url(self.get_readonly_url())
        made_branch = self.make_branch('.')
        self.assertIsInstance(made_branch, _mod_branch.Branch)

        # find it via bzrdir opening:
        opened_control = controldir.ControlDir.open(readonly_t.base)
        direct_opened_branch = opened_control.open_branch()
        self.assertEqual(direct_opened_branch.__class__, made_branch.__class__)
        self.assertEqual(opened_control, direct_opened_branch.controldir)
        self.assertIsInstance(direct_opened_branch._format,
                              self.branch_format.__class__)

        # find it via Branch.open
        opened_branch = _mod_branch.Branch.open(readonly_t.base)
        self.assertIsInstance(opened_branch, made_branch.__class__)
        self.assertEqual(made_branch._format.__class__,
                         opened_branch._format.__class__)
        # if it has a unique id string, can we probe for it ?
        try:
            self.branch_format.get_format_string()
        except NotImplementedError:
            return
        self.assertEqual(self.branch_format,
                         opened_control.find_branch_format())
Example #3
0
 def start_server(self, backing_server=None):
     """Setup the Chroot on backing_server."""
     if backing_server is not None:
         self.backing_transport = transport.get_transport_from_url(
             backing_server.get_url())
     else:
         self.backing_transport = transport.get_transport_from_path('.')
     super(TestingChrootServer, self).start_server()
Example #4
0
    def test_abspath_root_sibling_server(self):
        server = stub_sftp.SFTPSiblingAbsoluteServer()
        server.start_server()
        self.addCleanup(server.stop_server)

        transport = _mod_transport.get_transport_from_url(server.get_url())
        self.assertFalse(transport.abspath('/').endswith('/~/'))
        self.assertTrue(transport.abspath('/').endswith('/'))
        del transport
Example #5
0
 def start_server(self, backing_server=None):
     """Setup the Chroot on backing_server."""
     if backing_server is not None:
         self.backing_transport = transport.get_transport_from_url(
             backing_server.get_url())
     else:
         self.backing_transport = transport.get_transport_from_path('.')
     self.backing_transport.clone('added-by-filter').ensure_base()
     self.filter_func = lambda x: 'added-by-filter/' + x
     super(TestingPathFilteringServer, self).start_server()
Example #6
0
    def test_different_format_not_equal(self):
        """Different format repositories are comparable and not the same.

        Comparing different format repository objects should give a negative
        result, rather than trigger an exception (which could happen with a
        naive __eq__ implementation, e.g. due to missing attributes).
        """
        repo = self.make_repository('repo')
        other_repo = self.make_repository('other', format='default')
        if repo._format == other_repo._format:
            # We're testing the default format!  So we have to use a non-default
            # format for other_repo.
            transport.get_transport_from_url(
                self.get_vfs_only_url()).delete_tree('other')
            other_repo = self.make_repository('other', format='knit')
        # Make sure the other_repo is not a RemoteRepository.
        other_bzrdir = controldir.ControlDir.open(
            self.get_vfs_only_url('other'))
        other_repo = other_bzrdir.open_repository()
        self.assertDifferentRepo(repo, other_repo)
Example #7
0
 def test_bad_connection_ssh(self):
     """None => auto-detect vendor"""
     f = open(os.devnull, "wb")
     self.addCleanup(f.close)
     self.set_vendor(None, f)
     t = _mod_transport.get_transport_from_url(self.bogus_url)
     try:
         self.assertRaises(errors.ConnectionError, t.get, 'foobar')
     except NameError as e:
         if "global name 'SSHException'" in str(e):
             self.knownFailure('Known NameError bug in paramiko 1.6.1')
         raise
Example #8
0
 def test_create_anonymous_lightweight_checkout(self):
     """A lightweight checkout from a readonly branch should succeed."""
     tree_a = self.make_branch_and_tree('a')
     rev_id = tree_a.commit('put some content in the branch')
     # open the branch via a readonly transport
     url = self.get_readonly_url(urlutils.basename(tree_a.branch.base))
     t = transport.get_transport_from_url(url)
     if not tree_a.branch.controldir._format.supports_transport(t):
         raise tests.TestNotApplicable("format does not support transport")
     source_branch = _mod_branch.Branch.open(url)
     # sanity check that the test will be valid
     self.assertRaises((errors.LockError, errors.TransportNotPossible),
                       source_branch.lock_write)
     checkout = source_branch.create_checkout('c', lightweight=True)
     self.assertEqual(rev_id, checkout.last_revision())
Example #9
0
 def get_transport_for_connection(self, set_config):
     port = self.get_server().port
     if set_config:
         conf = config.AuthenticationConfig()
         conf._get_config().update(
             {'sftptest': {
                 'scheme': 'ssh',
                 'port': port,
                 'user': '******'
             }})
         conf._save()
     t = _mod_transport.get_transport_from_url('sftp://localhost:%d' % port)
     # force a connection to be performed.
     t.has('foo')
     return t
Example #10
0
 def test_jail_hook(self):
     request.jail_info.transports = None
     _pre_open_hook = request._pre_open_hook
     # Any transport is fine if jail_info.transports is None
     t = self.get_transport('foo')
     _pre_open_hook(t)
     # A transport in jail_info.transports is allowed
     request.jail_info.transports = [t]
     _pre_open_hook(t)
     # A child of a transport in jail_info is allowed
     _pre_open_hook(t.clone('child'))
     # A parent is not allowed
     self.assertRaises(errors.JailBreak, _pre_open_hook, t.clone('..'))
     # A completely unrelated transport is not allowed
     self.assertRaises(errors.JailBreak, _pre_open_hook,
                       transport.get_transport_from_url('http://host/'))
Example #11
0
async def bzr_backend(request):
    vcs_manager = request.app.vcs_manager
    package = request.match_info["package"]
    branch_name = request.match_info.get("branch")
    repo = await _bzr_open_repo(vcs_manager, request.app.db, package)
    if branch_name:
        try:
            get_suite_config(request.app.config, branch_name)
        except KeyError:
            raise web.HTTPNotFound(text='no such suite: %s' % branch_name)
        transport = repo.user_transport.clone(branch_name)
    else:
        transport = repo.user_transport
    transport.ensure_base()
    if await is_worker(request.app.db, request):
        backing_transport = transport
    else:
        backing_transport = get_transport_from_url("readonly+" +
                                                   transport.base)
    out_buffer = BytesIO()
    request_data_bytes = await request.read()

    protocol_factory, unused_bytes = medium._get_protocol_factory_for_bytes(
        request_data_bytes)

    smart_protocol_request = protocol_factory(transport, out_buffer.write, ".",
                                              backing_transport)
    smart_protocol_request.accept_bytes(unused_bytes)
    if smart_protocol_request.next_read_size() != 0:
        # The request appears to be incomplete, or perhaps it's just a
        # newer version we don't understand.  Regardless, all we can do
        # is return an error response in the format of our version of the
        # protocol.
        response_data = b"error\x01incomplete request\n"
    else:
        response_data = out_buffer.getvalue()

    response = web.StreamResponse(status=200)
    response.content_type = "application/octet-stream"

    await response.prepare(request)

    await response.write(response_data)

    await response.write_eof()

    return response
Example #12
0
 def test_open_containing(self):
     self.assertRaises(errors.NotBranchError,
                       _mod_branch.Branch.open_containing,
                       self.get_readonly_url(''))
     self.assertRaises(errors.NotBranchError,
                       _mod_branch.Branch.open_containing,
                       self.get_readonly_url('g/p/q'))
     branch = self.make_branch('.')
     if not branch.controldir._format.supports_transport(
             transport.get_transport_from_url(self.get_readonly_url('.'))):
         raise tests.TestNotApplicable("format does not support transport")
     branch, relpath = _mod_branch.Branch.open_containing(
         self.get_readonly_url(''))
     self.assertEqual('', relpath)
     branch, relpath = _mod_branch.Branch.open_containing(
         self.get_readonly_url('g/p/q'))
     self.assertEqual('g/p/q', relpath)
Example #13
0
 def test_bad_connection_paramiko(self):
     """Test that a real connection attempt raises the right error"""
     from breezy.transport import ssh
     self.set_vendor(ssh.ParamikoVendor())
     t = _mod_transport.get_transport_from_url(self.bogus_url)
     self.assertRaises(errors.ConnectionError, t.get, 'foobar')
Example #14
0
 def get_backing_transport(self, backing_transport_server):
     """Get a backing transport from a server we are decorating."""
     url = 'readonly+' + backing_transport_server.get_url()
     return transport.get_transport_from_url(url)
Example #15
0
 def get_backing_transport(self, backing_transport_server):
     """Get a backing transport from a server we are decorating."""
     return transport.get_transport_from_url(
         backing_transport_server.get_url())