def make_socks4(loop, *, addr=None, auth=None, rr=True, dst=None, r=b'', ap_factory=None, whiter=None): addr = addr or aiosocks.Socks4Addr('localhost', 1080) auth = auth or aiosocks.Socks4Auth('user') dst = dst or ('python.org', 80) proto = aiosocks.Socks4Protocol(proxy=addr, proxy_auth=auth, dst=dst, remote_resolve=rr, loop=loop, app_protocol_factory=ap_factory, waiter=whiter) proto._stream_writer = mock.Mock() proto.read_response = mock.Mock(side_effect=coro(mock.Mock( return_value=r))) proto._get_dst_addr = mock.Mock( side_effect=coro(mock.Mock(return_value=(socket.AF_INET, '127.0.0.1')))) return proto
def test_socks4_ctor(loop): addr = aiosocks.Socks4Addr('localhost', 1080) auth = aiosocks.Socks4Auth('user') dst = ('python.org', 80) with pytest.raises(ValueError): aiosocks.Socks4Protocol(None, None, dst, loop=loop, waiter=None, app_protocol_factory=None) with pytest.raises(ValueError): aiosocks.Socks4Protocol(None, auth, dst, loop=loop, waiter=None, app_protocol_factory=None) with pytest.raises(ValueError): aiosocks.Socks4Protocol(aiosocks.Socks5Addr('host'), auth, dst, loop=loop, waiter=None, app_protocol_factory=None) with pytest.raises(ValueError): aiosocks.Socks4Protocol(addr, aiosocks.Socks5Auth('l', 'p'), dst, loop=loop, waiter=None, app_protocol_factory=None) aiosocks.Socks4Protocol(addr, None, dst, loop=loop, waiter=None, app_protocol_factory=None) aiosocks.Socks4Protocol(addr, auth, dst, loop=loop, waiter=None, app_protocol_factory=None)