Example #1
0
def test_send_after_connect(mocker):
    mock_config(mocker)
    proxy, client_protocol, server_protocol, mock_make_proxied_connection = mock_protocol_proxy(mocker)

    proxy.connect("fakehost", 1337, False)

    proxy.client_connection_made(client_protocol)
    proxy.send_client_data("foobar")
    assert client_protocol.transport.pop_value() == 'foobar'

    proxy.server_connection_made(server_protocol)
    proxy.send_server_data("barfoo")
    assert server_protocol.transport.pop_value() == 'barfoo'
Example #2
0
def test_start_tls_after_connect(mocker):
    mock_config(mocker)
    proxy, client_protocol, server_protocol, mock_make_proxied_connection = mock_protocol_proxy(mocker)
    client_protocol.transport.startTLS = mock.MagicMock()
    server_protocol.transport.startTLS = mock.MagicMock()

    server_protocol.transport.startTLS.assert_not_called()
    client_protocol.transport.startTLS.assert_not_called()

    proxy.connect("fakehost", 1337, False)

    server_protocol.transport.startTLS.assert_not_called()
    client_protocol.transport.startTLS.assert_not_called()

    proxy.server_connection_made(server_protocol)
    proxy.start_server_tls()
    assert len(server_protocol.transport.startTLS.mock_calls) == 1

    proxy.client_connection_made(client_protocol)
    proxy.start_client_tls("fakehost")
    assert len(client_protocol.transport.startTLS.mock_calls) == 1