Пример #1
0
def test_mangle_request_single(httprequest):
    orig_req = httprequest.copy() # in case it gets mangled
    macro = mock_int_macro(modified_req=('GET /modified HTTP/1.1\r\n\r\n'))
    expected_req = Request('GET /modified HTTP/1.1\r\n\r\n')
    (new_req, mangled) = yield macros.mangle_request(orig_req, {'testmacro': macro})
    assert new_req == expected_req
    assert httprequest == orig_req
    assert httprequest.unmangled is None
    assert new_req.unmangled == orig_req
    assert mangled
Пример #2
0
def test_mangle_request_multiple(httprequest):
    orig_req = httprequest.copy() # in case it gets mangled
    macro = mock_int_macro(modified_req=('GET /cloud HTTP/1.1\r\n\r\n'))
    macro2 = CloudToButtMacro()
    intmacros = OrderedDict()
    intmacros['testmacro'] = macro
    intmacros['testmacro2'] = macro2
    (new_req, mangled) = yield macros.mangle_request(orig_req, intmacros)

    expected_req = Request('GET /butt HTTP/1.1\r\n\r\n')
    assert new_req == expected_req
    assert httprequest == orig_req
    assert httprequest.unmangled is None
    assert new_req.unmangled == orig_req
    assert mangled
Пример #3
0
def test_proxy_server_no_streaming_with_int_macros(mocker):
    mfactory = mock.MagicMock()
    mfactory_class = mocker.patch('pappyproxy.proxy.ProxyClientFactory')
    mfactory_class.return_value = mfactory

    mocker.patch('pappyproxy.proxy.ProxyServer._make_remote_connection')

    mfactory.prepare_request.return_value = mock_deferred(None)
    full_req = ('POST /fooo HTTP/1.1\r\n'
                'Test-Header: foo\r\n'
                'Content-Length: 4\r\n'
                '\r\n'
                'ABCD')

    int_macros = [{'mockmacro': mock_int_macro(modified_req='GET / HTTP/1.1\r\n\r\n')}]
    server_protocol = gen_server_protocol(int_macros=int_macros)
    server_protocol.dataReceived(full_req)
    f_args, f_kwargs = mfactory_class.call_args
    assert f_kwargs['stream_response'] == False
Пример #4
0
def test_proxy_server_no_streaming_with_int_macros(mocker):
    mfactory = mock.MagicMock()
    mfactory_class = mocker.patch('pappyproxy.proxy.ProxyClientFactory')
    mfactory_class.return_value = mfactory

    mocker.patch('pappyproxy.proxy.ProxyServer._make_remote_connection')

    mfactory.prepare_request.return_value = mock_deferred(None)
    full_req = ('POST /fooo HTTP/1.1\r\n'
                'Test-Header: foo\r\n'
                'Content-Length: 4\r\n'
                '\r\n'
                'ABCD')

    int_macros = [{
        'mockmacro':
        mock_int_macro(modified_req='GET / HTTP/1.1\r\n\r\n')
    }]
    server_protocol = gen_server_protocol(int_macros=int_macros)
    server_protocol.dataReceived(full_req)
    f_args, f_kwargs = mfactory_class.call_args
    assert f_kwargs['stream_response'] == False