Exemplo n.º 1
0
    def test_relpath_setter(self):
        # wsgi.RelpathSetter is WSGI "middleware" to set the 'bzrlib.relpath'
        # variable.
        calls = []

        def fake_app(environ, start_response):
            calls.append(environ['bzrlib.relpath'])

        wrapped_app = wsgi.RelpathSetter(fake_app,
                                         prefix='/abc/',
                                         path_var='FOO')
        wrapped_app({'FOO': '/abc/xyz/.bzr/smart'}, None)
        self.assertEqual(['xyz'], calls)
Exemplo n.º 2
0
    def test_relpath_setter_bad_path_prefix(self):
        # wsgi.RelpathSetter will reject paths with that don't match the prefix
        # with a 404.  This is probably a sign of misconfiguration; a server
        # shouldn't ever be invoking our WSGI application with bad paths.
        def fake_app(environ, start_response):
            self.fail('The app should never be called when the path is wrong')

        wrapped_app = wsgi.RelpathSetter(fake_app,
                                         prefix='/abc/',
                                         path_var='FOO')
        iterable = wrapped_app({'FOO': 'AAA/abc/xyz/.bzr/smart'},
                               self.start_response)
        self.read_response(iterable)
        self.assertTrue(self.status.startswith('404'))
Exemplo n.º 3
0
    def test_relpath_setter_bad_path_suffix(self):
        # Similar to test_relpath_setter_bad_path_prefix: wsgi.RelpathSetter
        # will reject paths with that don't match the suffix '.bzr/smart' with a
        # 404 as well.  Again, this shouldn't be seen by our WSGI application if
        # the server is configured correctly.
        def fake_app(environ, start_response):
            self.fail('The app should never be called when the path is wrong')

        wrapped_app = wsgi.RelpathSetter(fake_app,
                                         prefix='/abc/',
                                         path_var='FOO')
        iterable = wrapped_app({'FOO': '/abc/xyz/.bzr/AAA'},
                               self.start_response)
        self.read_response(iterable)
        self.assertTrue(self.status.startswith('404'))