21
21
from bzrlib import errors
22
22
from bzrlib.smart import request
23
23
from bzrlib.tests import TestCase, TestCaseWithMemoryTransport
24
from bzrlib.transport import get_transport
26
27
class NoBodyRequest(request.SmartServerRequest):
172
173
def test_jail(self):
173
174
transport = self.get_transport('blah')
174
175
req = request.SmartServerRequest(transport)
175
tls = threading.local()
176
176
self.assertEqual(None, request.jail_info.transports)
178
178
self.assertEqual([transport], request.jail_info.transports)
179
179
req.teardown_jail()
180
180
self.assertEqual(None, request.jail_info.transports)
183
class TestJailHook(TestCaseWithMemoryTransport):
186
request.jail_info.transports = None
187
TestCaseWithMemoryTransport.tearDown(self)
189
def test_jail_hook(self):
190
request.jail_info.transports = None
191
_pre_open_hook = request._pre_open_hook
192
# Any transport is fine if jail_info.transports is None
193
t = self.get_transport('foo')
195
# A transport in jail_info.transports is allowed
196
request.jail_info.transports = [t]
198
# A child of a transport in jail_info is allowed
199
_pre_open_hook(t.clone('child'))
200
# A parent is not allowed
201
self.assertRaises(errors.BzrError, _pre_open_hook, t.clone('..'))
202
# A completely unrelated transport is not allowed
204
errors.BzrError, _pre_open_hook, get_transport('http://host/'))