def test_mpc_socks_ssl(mocker): mock_config(mocker) tcp_endpoint_instance = mock.MagicMock() socks_endpoint_instance = mock.MagicMock() wrapper_instance = mock.MagicMock() tcp_endpoint = mocker.patch('twisted.internet.endpoints.TCP4ClientEndpoint', return_value=tcp_endpoint_instance) socks_endpoint = mocker.patch('txsocksx.client.SOCKS5ClientEndpoint', return_value=socks_endpoint_instance) wrapper_endpoint = mocker.patch('txsocksx.tls.TLSWrapClientEndpoint', return_value=wrapper_instance) target_host = 'fakehost' target_port = 1337 socks_host = 'fakesockshost' socks_port = 1447 socks_config = {'host':socks_host, 'port':socks_port} make_proxied_connection('fakefactory', target_host, target_port, True, socks_config=socks_config) tcp_ep_calls = tcp_endpoint.mock_calls[0] assert tcp_ep_calls[1][1] == socks_host assert tcp_ep_calls[1][2] == socks_port socks_ep_calls = socks_endpoint.mock_calls[0] assert socks_ep_calls[1][0] == target_host assert socks_ep_calls[1][1] == target_port assert socks_ep_calls[1][2] is tcp_endpoint_instance assert socks_ep_calls[2]['methods'] == {'anonymous': ()} wrapper_calls = wrapper_endpoint.mock_calls[0] assert isinstance(wrapper_calls[1][0], ssl.ClientContextFactory) assert wrapper_calls[1][1] is socks_endpoint_instance connectcall = wrapper_instance.connect assert len(connectcall.mock_calls) == 1
def test_mpc_socks(mocker): mock_config(mocker) tcp_endpoint_instance = mock.MagicMock() socks_endpoint_instance = mock.MagicMock() tcp_endpoint = mocker.patch( 'twisted.internet.endpoints.TCP4ClientEndpoint', return_value=tcp_endpoint_instance) socks_endpoint = mocker.patch('txsocksx.client.SOCKS5ClientEndpoint', return_value=socks_endpoint_instance) target_host = 'fakehost' target_port = 1337 socks_host = 'fakesockshost' socks_port = 1447 socks_config = {'host': socks_host, 'port': socks_port} make_proxied_connection('fakefactory', target_host, target_port, False, socks_config=socks_config) tcp_ep_calls = tcp_endpoint.mock_calls[0] assert tcp_ep_calls[1][1] == socks_host assert tcp_ep_calls[1][2] == socks_port socks_ep_calls = socks_endpoint.mock_calls[0] assert socks_ep_calls[1][0] == target_host assert socks_ep_calls[1][1] == target_port assert socks_ep_calls[1][2] is tcp_endpoint_instance assert socks_ep_calls[2]['methods'] == {'anonymous': ()} connectcall = socks_endpoint_instance.connect assert len(connectcall.mock_calls) == 1
def test_mpc_socks_creds(mocker): mock_config(mocker) tcp_endpoint_instance = mock.MagicMock() socks_endpoint_instance = mock.MagicMock() tcp_endpoint = mocker.patch('twisted.internet.endpoints.TCP4ClientEndpoint', return_value=tcp_endpoint_instance) socks_endpoint = mocker.patch('txsocksx.client.SOCKS5ClientEndpoint', return_value=socks_endpoint_instance) target_host = 'fakehost' target_port = 1337 socks_host = 'fakesockshost' socks_port = 1447 socks_user = '******' socks_password = '******' socks_config = {'host':socks_host, 'port':socks_port, 'username':socks_user, 'password':socks_password} make_proxied_connection('fakefactory', target_host, target_port, False, socks_config=socks_config) tcp_ep_calls = tcp_endpoint.mock_calls[0] assert tcp_ep_calls[1][1] == socks_host assert tcp_ep_calls[1][2] == socks_port socks_ep_calls = socks_endpoint.mock_calls[0] assert socks_ep_calls[1][0] == target_host assert socks_ep_calls[1][1] == target_port assert socks_ep_calls[1][2] is tcp_endpoint_instance assert socks_ep_calls[2]['methods'] == {'login': (socks_user, socks_password), 'anonymous': ()} connectcall = socks_endpoint_instance.connect assert len(connectcall.mock_calls) == 1
def test_mpc_socks_ssl_creds(mocker): mock_config(mocker) tcp_endpoint_instance = mock.MagicMock() socks_endpoint_instance = mock.MagicMock() wrapper_instance = mock.MagicMock() tcp_endpoint = mocker.patch( 'twisted.internet.endpoints.TCP4ClientEndpoint', return_value=tcp_endpoint_instance) socks_endpoint = mocker.patch('txsocksx.client.SOCKS5ClientEndpoint', return_value=socks_endpoint_instance) wrapper_endpoint = mocker.patch('txsocksx.tls.TLSWrapClientEndpoint', return_value=wrapper_instance) target_host = 'fakehost' target_port = 1337 socks_host = 'fakesockshost' socks_port = 1447 socks_user = '******' socks_password = '******' socks_config = { 'host': socks_host, 'port': socks_port, 'username': socks_user, 'password': socks_password } make_proxied_connection('fakefactory', target_host, target_port, True, socks_config=socks_config) tcp_ep_calls = tcp_endpoint.mock_calls[0] assert tcp_ep_calls[1][1] == socks_host assert tcp_ep_calls[1][2] == socks_port socks_ep_calls = socks_endpoint.mock_calls[0] assert socks_ep_calls[1][0] == target_host assert socks_ep_calls[1][1] == target_port assert socks_ep_calls[1][2] is tcp_endpoint_instance assert socks_ep_calls[2]['methods'] == { 'login': (socks_user, socks_password), 'anonymous': () } wrapper_calls = wrapper_endpoint.mock_calls[0] assert isinstance(wrapper_calls[1][0], ssl.ClientContextFactory) assert wrapper_calls[1][1] is socks_endpoint_instance connectcall = wrapper_instance.connect assert len(connectcall.mock_calls) == 1
def test_mpc_simple(mocker): mock_config(mocker) endpoint_instance = mock.MagicMock() endpoint = mocker.patch('twisted.internet.endpoints.TCP4ClientEndpoint', return_value=endpoint_instance) make_proxied_connection('fakefactory', 'fakehost', 1337, False) endpointcalls = endpoint.mock_calls[0] assert endpointcalls[1][1] == 'fakehost' assert endpointcalls[1][2] == 1337 connectcall = endpoint_instance.connect assert len(connectcall.mock_calls) == 1
def test_mpc_ssl(mocker): mock_config(mocker) endpoint_instance = mock.MagicMock() endpoint = mocker.patch('twisted.internet.endpoints.SSL4ClientEndpoint', return_value=endpoint_instance) make_proxied_connection('fakefactory', 'fakehost', 1337, True) endpointcalls = endpoint.mock_calls[0] assert endpointcalls[1][1] == 'fakehost' assert endpointcalls[1][2] == 1337 assert isinstance(endpointcalls[1][3], ssl.ClientContextFactory) connectcall = endpoint_instance.connect assert len(connectcall.mock_calls) == 1