~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_wsgi.py

  • Committer: Robert Collins
  • Date: 2007-04-23 02:29:35 UTC
  • mfrom: (2441 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2442.
  • Revision ID: robertc@robertcollins.net-20070423022935-9hhongamvk6bfdso
Resolve conflicts with bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
    def test_construct(self):
72
72
        app = wsgi.SmartWSGIApp(FakeTransport())
73
73
        self.assertIsInstance(
74
 
            app.backing_transport, chroot.ChrootTransportDecorator)
 
74
            app.backing_transport, chroot.ChrootTransport)
75
75
 
76
76
    def test_http_get_rejected(self):
77
77
        # GET requests are rejected.
84
84
        
85
85
    def test_smart_wsgi_app_uses_given_relpath(self):
86
86
        # The SmartWSGIApp should use the "bzrlib.relpath" field from the
87
 
        # WSGI environ to construct the transport for this request, by cloning
88
 
        # its base transport with the given relpath.
 
87
        # WSGI environ to clone from its backing transport to get a specific
 
88
        # transport for this request.
89
89
        transport = FakeTransport()
90
90
        wsgi_app = wsgi.SmartWSGIApp(transport)
 
91
        wsgi_app.backing_transport = transport
91
92
        def make_request(transport, write_func):
92
93
            request = FakeRequest(transport, write_func)
93
94
            self.request = request
175
176
            path_var='a path_var')
176
177
        self.assertIsInstance(app, wsgi.RelpathSetter)
177
178
        self.assertIsInstance(app.app, wsgi.SmartWSGIApp)
178
 
        self.assertEndsWith(app.app.backing_transport.base, 'a%20root/')
 
179
        self.assertStartsWith(app.app.backing_transport.base, 'chroot-')
 
180
        backing_transport = app.app.backing_transport
 
181
        chroot_backing_transport = backing_transport.server.backing_transport
 
182
        self.assertEndsWith(chroot_backing_transport.base, 'a%20root/')
179
183
        self.assertEqual(app.prefix, 'a prefix')
180
184
        self.assertEqual(app.path_var, 'a path_var')
181
185
 
200
204
        self.assertEqual('200 OK', self.status)
201
205
        self.assertEqual('error\x01incomplete request\n', response)
202
206
 
203
 
    def test_chrooting(self):
204
 
        # Show that requests that try to access things outside of the base
205
 
        # really will get intercepted by the ChrootTransportDecorator.
206
 
        transport = memory.MemoryTransport()
207
 
        transport.mkdir('foo')
208
 
        transport.put_bytes('foo/bar', 'this is foo/bar')
209
 
        wsgi_app = wsgi.SmartWSGIApp(transport.clone('foo'))
210
 
 
211
 
        smart_request = StringIO('mkdir\x01/bad file\x01\n0\ndone\n')
212
 
        environ = self.build_environ({
213
 
            'REQUEST_METHOD': 'POST',
214
 
            'CONTENT_LENGTH': len(smart_request.getvalue()),
215
 
            'wsgi.input': smart_request,
216
 
            'bzrlib.relpath': '.',
217
 
        })
218
 
        iterable = wsgi_app(environ, self.start_response)
219
 
        response = self.read_response(iterable)
220
 
        self.assertEqual('200 OK', self.status)
221
 
        self.assertEqual(
222
 
            "error\x01Path '/bad file' is not a child of "
223
 
            "path 'memory:///foo/'\n",
224
 
            response)
225
 
 
226
207
 
227
208
class FakeRequest(object):
228
209