Rev 4550: (andrew) Restore the use ChrootServer for the served directory in in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Mon Jul 20 05:49:26 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4550 [merge]
revision-id: pqm at pqm.ubuntu.com-20090720044925-bs0d4n5q66wvrgrd
parent: pqm at pqm.ubuntu.com-20090720033224-n4zz83x1s2fuyyb5
parent: andrew.bennetts at canonical.com-20090720034826-tti9jk552wes25mg
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2009-07-20 05:49:25 +0100
message:
(andrew) Restore the use ChrootServer for the served directory in
'bzr serve'.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/smart/server.py server.py-20061110062051-chzu10y32vx8gvur-1
bzrlib/tests/blackbox/test_serve.py test_serve.py-20060913064329-8t2pvmsikl4s3xhl-1
=== modified file 'NEWS'
--- a/NEWS 2009-07-19 06:46:05 +0000
+++ b/NEWS 2009-07-20 04:49:25 +0000
@@ -33,6 +33,9 @@
* ``bzr mv`` no longer takes out branch locks, which allows it to work
when the branch is readonly. (Robert Collins, #216541)
+* ``bzr serve`` once again applies a ``ChrootServer`` to the given
+ directory before serving it. (Andrew Bennetts, #400535)
+
* Fixed spurious "Source branch does not support stacking" warning when
pushing. (Andrew Bennetts, #388908)
=== modified file 'bzrlib/smart/server.py'
--- a/bzrlib/smart/server.py 2009-06-10 03:56:49 +0000
+++ b/bzrlib/smart/server.py 2009-07-20 03:45:52 +0000
@@ -111,6 +111,8 @@
pass
for hook in SmartTCPServer.hooks['server_started']:
hook(backing_urls, self.get_url())
+ for hook in SmartTCPServer.hooks['server_started_ex']:
+ hook(backing_urls, self)
self._started.set()
try:
try:
@@ -214,6 +216,10 @@
"where backing_url is a list of URLs giving the "
"server-specific directory locations, and public_url is the "
"public URL for the directory being served.", (0, 16), None))
+ self.create_hook(HookPoint('server_started_ex',
+ "Called by the bzr server when it starts serving a directory. "
+ "server_started is called with (backing_urls, server_obj).",
+ (1, 17), None))
self.create_hook(HookPoint('server_stopped',
"Called by the bzr server when it stops serving a directory. "
"server_stopped is called with the same parameters as the "
@@ -313,7 +319,7 @@
from bzrlib.transport.chroot import ChrootServer
chroot_server = ChrootServer(transport)
chroot_server.setUp()
- t = get_transport(chroot_server.get_url())
+ transport = get_transport(chroot_server.get_url())
if inet:
smart_server = medium.SmartServerPipeStreamMedium(
sys.stdin, sys.stdout, transport)
@@ -322,8 +328,7 @@
host = medium.BZR_DEFAULT_INTERFACE
if port is None:
port = medium.BZR_DEFAULT_PORT
- smart_server = SmartTCPServer(
- transport, host=host, port=port)
+ smart_server = SmartTCPServer(transport, host=host, port=port)
trace.note('listening on port: %s' % smart_server.port)
# For the duration of this server, no UI output is permitted. note
# that this may cause problems with blackbox tests. This should be
=== modified file 'bzrlib/tests/blackbox/test_serve.py'
--- a/bzrlib/tests/blackbox/test_serve.py 2009-06-10 03:56:49 +0000
+++ b/bzrlib/tests/blackbox/test_serve.py 2009-07-20 03:45:52 +0000
@@ -21,18 +21,22 @@
import signal
import subprocess
import sys
+import thread
import threading
from bzrlib import (
errors,
osutils,
revision as _mod_revision,
+ transport,
)
from bzrlib.branch import Branch
from bzrlib.bzrdir import BzrDir
from bzrlib.errors import ParamikoNotPresent
-from bzrlib.smart import medium
+from bzrlib.smart import client, medium
+from bzrlib.smart.server import SmartTCPServer
from bzrlib.tests import TestCaseWithTransport, TestSkipped
+from bzrlib.trace import mutter
from bzrlib.transport import get_transport, remote
@@ -239,3 +243,77 @@
% bzr_remote_path],
self.command_executed)
+
+class TestCmdServeChrooting(TestCaseWithTransport):
+
+ def test_serve_tcp(self):
+ """'bzr serve' wraps the given --directory in a ChrootServer.
+
+ So requests that search up through the parent directories (like
+ find_repositoryV3) will give "not found" responses, rather than
+ InvalidURLJoin or jail break errors.
+ """
+ t = self.get_transport()
+ t.mkdir('server-root')
+ self.run_bzr_serve_then_func(
+ ['--port', '0', '--directory', t.local_abspath('server-root'),
+ '--allow-writes'],
+ self.when_server_started)
+ # The when_server_started method issued a find_repositoryV3 that should
+ # fail with 'norepository' because there are no repositories inside the
+ # --directory.
+ self.assertEqual(('norepository',), self.client_resp)
+
+ def run_bzr_serve_then_func(self, serve_args, func, *func_args,
+ **func_kwargs):
+ """Run 'bzr serve', and run the given func in a thread once the server
+ has started.
+
+ When 'func' terminates, the server will be terminated too.
+ """
+ # install hook
+ def on_server_start(backing_urls, tcp_server):
+ t = threading.Thread(
+ target=on_server_start_thread, args=(tcp_server,))
+ t.start()
+ def on_server_start_thread(tcp_server):
+ try:
+ # Run func
+ self.tcp_server = tcp_server
+ try:
+ func(*func_args, **func_kwargs)
+ except Exception, e:
+ # Log errors to make some test failures a little less
+ # mysterious.
+ mutter('func broke: %r', e)
+ finally:
+ # Then stop the server
+ mutter('interrupting...')
+ thread.interrupt_main()
+ SmartTCPServer.hooks.install_named_hook(
+ 'server_started_ex', on_server_start,
+ 'run_bzr_serve_then_func hook')
+ # start a TCP server
+ try:
+ self.run_bzr(['serve'] + list(serve_args))
+ except KeyboardInterrupt:
+ pass
+
+ def when_server_started(self):
+ # Connect to the TCP server and issue some requests and see what comes
+ # back.
+ client_medium = medium.SmartTCPClientMedium(
+ '127.0.0.1', self.tcp_server.port,
+ 'bzr://localhost:%d/' % (self.tcp_server.port,))
+ smart_client = client._SmartClient(client_medium)
+ resp = smart_client.call('mkdir', 'foo', '')
+ resp = smart_client.call('BzrDirFormat.initialize', 'foo/')
+ try:
+ resp = smart_client.call('BzrDir.find_repositoryV3', 'foo/')
+ except errors.ErrorFromSmartServer, e:
+ resp = e.error_tuple
+ self.client_resp = resp
+ client_medium.disconnect()
+
+
+
More information about the bazaar-commits
mailing list