~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_request.py

  • Committer: Andrew Bennetts
  • Date: 2009-03-18 05:33:25 UTC
  • mto: This revision was merged to the branch mainline in revision 4194.
  • Revision ID: andrew.bennetts@canonical.com-20090318053325-w5xdsr0fjwcpatj2
Add test_jail_hook.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
24
25
 
25
26
 
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)
177
177
        req.setup_jail()
178
178
        self.assertEqual([transport], request.jail_info.transports)
179
179
        req.teardown_jail()
180
180
        self.assertEqual(None, request.jail_info.transports)
181
181
 
 
182
 
 
183
class TestJailHook(TestCaseWithMemoryTransport):
 
184
 
 
185
    def tearDown(self):
 
186
        request.jail_info.transports = None
 
187
        TestCaseWithMemoryTransport.tearDown(self)
 
188
 
 
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')
 
194
        _pre_open_hook(t)
 
195
        # A transport in jail_info.transports is allowed
 
196
        request.jail_info.transports = [t]
 
197
        _pre_open_hook(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
 
203
        self.assertRaises(
 
204
            errors.BzrError, _pre_open_hook, get_transport('http://host/'))
 
205