~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_wsgi.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-03-21 04:49:05 UTC
  • mfrom: (2367.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070321044905-ded01a80ab49bdd9
Update NEWS to match bzr 0.15.

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.ChrootTransport)
 
74
            app.backing_transport, chroot.ChrootTransportDecorator)
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 clone from its backing transport to get a specific
88
 
        # transport for this request.
 
87
        # WSGI environ to construct the transport for this request, by cloning
 
88
        # its base transport with the given relpath.
89
89
        transport = FakeTransport()
90
90
        wsgi_app = wsgi.SmartWSGIApp(transport)
91
 
        wsgi_app.backing_transport = transport
92
91
        def make_request(transport, write_func):
93
92
            request = FakeRequest(transport, write_func)
94
93
            self.request = request
176
175
            path_var='a path_var')
177
176
        self.assertIsInstance(app, wsgi.RelpathSetter)
178
177
        self.assertIsInstance(app.app, wsgi.SmartWSGIApp)
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/')
 
178
        self.assertEndsWith(app.app.backing_transport.base, 'a%20root/')
183
179
        self.assertEqual(app.prefix, 'a prefix')
184
180
        self.assertEqual(app.path_var, 'a path_var')
185
181
 
204
200
        self.assertEqual('200 OK', self.status)
205
201
        self.assertEqual('error\x01incomplete request\n', response)
206
202
 
 
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
 
207
226
 
208
227
class FakeRequest(object):
209
228