Exemplo n.º 1
0
def test_path_info_from_request_uri_fix():
    """Test the PathInfoFromRequestUriFix fixer"""
    app = fixers.PathInfoFromRequestUriFix(path_check_app)
    for key in 'REQUEST_URI', 'REQUEST_URL', 'UNENCODED_URL':
        env = dict(create_environ(), SCRIPT_NAME='/test', PATH_INFO='/?????')
        env[key] = '/test/foo%25bar?drop=this'
        response = Response.from_app(app, env)
        assert response.data == 'PATH_INFO: /foo%bar\nSCRIPT_NAME: /test'
def test_path_info_from_request_uri_fix():
    """Test the PathInfoFromRequestUriFix fixer"""
    app = fixers.PathInfoFromRequestUriFix(path_check_app)
    for key in 'REQUEST_URI', 'REQUEST_URL', 'UNENCODED_URL':
        env = dict(create_environ(), SCRIPT_NAME='/test', PATH_INFO='/?????')
        env[key] = '/test/foo%25bar?drop=this'
        response = Response.from_app(app, env)
        assert response.data == 'PATH_INFO: /foo%bar\nSCRIPT_NAME: /test'
Exemplo n.º 3
0
def test_lighttpd_cgi_root_fix():
    """Test the LighttpdCGIRootFix fixer"""
    app = fixers.LighttpdCGIRootFix(path_check_app)
    response = Response.from_app(app, dict(create_environ(),
        SCRIPT_NAME='/foo',
        PATH_INFO='/bar'
    ))
    assert response.data == 'PATH_INFO: /foo/bar\nSCRIPT_NAME: '
Exemplo n.º 4
0
def test_fix_headers_in_response():
    """Make sure fix_headers still works for backwards compatibility"""
    from werkzeug import Response
    class MyResponse(Response):
        def fix_headers(self, environ):
            Response.fix_headers(self, environ)
            self.headers['x-foo'] = "meh"
    myresp = MyResponse('Foo')
    resp = Response.from_app(myresp, create_environ(method='GET'))
    assert resp.headers['x-foo'] == 'meh'
    assert resp.data == 'Foo'
def test_header_rewriter_fix():
    """Test the HeaderRewriterFix fixer"""
    @Request.application
    def application(request):
        return Response("", headers=[('X-Foo', 'bar')])

    application = fixers.HeaderRewriterFix(application, ('X-Foo', ),
                                           (('X-Bar', '42'), ))
    response = Response.from_app(application, create_environ())
    assert response.headers['Content-Type'] == 'text/plain; charset=utf-8'
    assert 'X-Foo' not in response.headers
    assert response.headers['X-Bar'] == '42'
Exemplo n.º 6
0
def test_header_rewriter_fix():
    """Test the HeaderRewriterFix fixer"""
    @Request.application
    def application(request):
        return Response("", headers=[
            ('X-Foo', 'bar')
        ])
    application = fixers.HeaderRewriterFix(application, ('X-Foo',), (('X-Bar', '42'),))
    response = Response.from_app(application, create_environ())
    assert response.headers['Content-Type'] == 'text/plain; charset=utf-8'
    assert 'X-Foo' not in response.headers
    assert response.headers['X-Bar'] == '42'
Exemplo n.º 7
0
def test_proxy_fix():
    """Test the ProxyFix fixer"""
    @fixers.ProxyFix
    @Request.application
    def app(request):
        return Response('%s|%s' % (
            request.remote_addr,
            # do not use request.host as this fixes too :)
            request.environ['HTTP_HOST']
        ))
    response = Response.from_app(app, dict(create_environ(),
        HTTP_X_FORWARDED_HOST='example.com',
        HTTP_X_FORWARDED_FOR='1.2.3.4, 5.6.7.8',
        REMOTE_ADDR='127.0.0.1',
        HTTP_HOST='fake'
    ))
    assert response.data == '1.2.3.4|example.com'
def test_proxy_fix():
    """Test the ProxyFix fixer"""
    @fixers.ProxyFix
    @Request.application
    def app(request):
        return Response('%s|%s' % (
            request.remote_addr,
            # do not use request.host as this fixes too :)
            request.environ['HTTP_HOST']))

    response = Response.from_app(
        app,
        dict(create_environ(),
             HTTP_X_FORWARDED_HOST='example.com',
             HTTP_X_FORWARDED_FOR='1.2.3.4, 5.6.7.8',
             REMOTE_ADDR='127.0.0.1',
             HTTP_HOST='fake'))
    assert response.data == '1.2.3.4|example.com'
Exemplo n.º 9
0
def test_fix_headers_in_response():
    """Make sure fix_headers still works for backwards compatibility"""
    # ignore some warnings werkzeug emits for backwards compat
    for msg in ['called into deprecated fix_headers',
                'fix_headers changed behavior']:
        warnings.filterwarnings('ignore', message=msg,
                                category=DeprecationWarning)

    from werkzeug import Response
    class MyResponse(Response):
        def fix_headers(self, environ):
            Response.fix_headers(self, environ)
            self.headers['x-foo'] = "meh"
    myresp = MyResponse('Foo')
    resp = Response.from_app(myresp, create_environ(method='GET'))
    assert resp.headers['x-foo'] == 'meh'
    assert resp.data == 'Foo'

    warnings.resetwarnings()
Exemplo n.º 10
0
def test_fix_headers_in_response():
    """Make sure fix_headers still works for backwards compatibility"""
    # ignore some warnings werkzeug emits for backwards compat
    for msg in [
            'called into deprecated fix_headers',
            'fix_headers changed behavior'
    ]:
        warnings.filterwarnings('ignore',
                                message=msg,
                                category=DeprecationWarning)

    from werkzeug import Response

    class MyResponse(Response):
        def fix_headers(self, environ):
            Response.fix_headers(self, environ)
            self.headers['x-foo'] = "meh"

    myresp = MyResponse('Foo')
    resp = Response.from_app(myresp, create_environ(method='GET'))
    assert resp.headers['x-foo'] == 'meh'
    assert resp.data == 'Foo'

    warnings.resetwarnings()
def test_lighttpd_cgi_root_fix():
    """Test the LighttpdCGIRootFix fixer"""
    app = fixers.LighttpdCGIRootFix(path_check_app)
    response = Response.from_app(
        app, dict(create_environ(), SCRIPT_NAME='/foo', PATH_INFO='/bar'))
    assert response.data == 'PATH_INFO: /foo/bar\nSCRIPT_NAME: '
Exemplo n.º 12
0
 def __call__(self, request, **kwargs):
     self.request = request
     response = Response.from_app(self.app, self.request.environ)
     return response
Exemplo n.º 13
0
 def __call__(self, request, **kwargs):
   self.request = request
   response = Response.from_app(self.app, self.request.environ)
   return response