~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 04:49:31 UTC
  • mto: This revision was merged to the branch mainline in revision 4194.
  • Revision ID: andrew.bennetts@canonical.com-20090318044931-uqq32ujozbz0csuv
Add setup_jail and teardown_jail to SmartServerRequest.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for smart server request infrastructure (bzrlib.smart.request)."""
18
18
 
 
19
import threading
 
20
 
19
21
from bzrlib import errors
20
22
from bzrlib.smart import request
21
 
from bzrlib.tests import TestCase
 
23
from bzrlib.tests import TestCase, TestCaseWithMemoryTransport
22
24
 
23
25
 
24
26
class NoBodyRequest(request.SmartServerRequest):
61
63
        raise errors.NoSuchFile('xyzzy')
62
64
 
63
65
 
 
66
class CheckJailRequest(request.SmartServerRequest):
 
67
 
 
68
    def __init__(self, *args):
 
69
        request.SmartServerRequest.__init__(self, *args)
 
70
        self.jail_transports_log = []
 
71
 
 
72
    def do(self):
 
73
        self.jail_transports_log.append(request.jail_info.transports)
 
74
 
 
75
    def do_chunk(self, bytes):
 
76
        self.jail_transports_log.append(request.jail_info.transports)
 
77
 
 
78
    def do_end(self):
 
79
        self.jail_transports_log.append(request.jail_info.transports)
 
80
 
 
81
 
64
82
class TestSmartRequest(TestCase):
65
83
 
66
84
    def test_request_class_without_do_body(self):
76
94
        handler.end_received()
77
95
        # Request done, no exception was raised.
78
96
 
 
97
    def test_only_request_code_is_jailed(self):
 
98
        transport = 'dummy transport'
 
99
        handler = request.SmartServerRequestHandler(
 
100
            transport, {'foo': CheckJailRequest}, '/')
 
101
        handler.args_received(('foo',))
 
102
        self.assertEqual(None, request.jail_info.transports)
 
103
        handler.accept_body('bytes')
 
104
        self.assertEqual(None, request.jail_info.transports)
 
105
        handler.end_received()
 
106
        self.assertEqual(None, request.jail_info.transports)
 
107
        self.assertEqual(
 
108
            [[transport]] * 3, handler._command.jail_transports_log)
 
109
 
 
110
 
79
111
 
80
112
class TestSmartRequestHandlerErrorTranslation(TestCase):
81
113
    """Tests that SmartServerRequestHandler will translate exceptions raised by
134
166
            ('TokenMismatch', 'some-token', 'actual-token'),
135
167
            errors.TokenMismatch('some-token', 'actual-token'))
136
168
 
 
169
 
 
170
class TestRequestJail(TestCaseWithMemoryTransport):
 
171
    
 
172
    def test_jail(self):
 
173
        transport = self.get_transport('blah')
 
174
        req = request.SmartServerRequest(transport)
 
175
        tls = threading.local()
 
176
        self.assertEqual(None, request.jail_info.transports)
 
177
        req.setup_jail()
 
178
        self.assertEqual([transport], request.jail_info.transports)
 
179
        req.teardown_jail()
 
180
        self.assertEqual(None, request.jail_info.transports)
 
181