def test_proxy_chain(): proxy = ProxyChain([ Proxy.from_url(SOCKS5_IPV4_URL), Proxy.from_url(SOCKS4_URL), Proxy.from_url(HTTP_PROXY_URL), ]) # noinspection PyTypeChecker status_code = make_request(proxy=proxy, url=TEST_URL) assert status_code == 200
def test_socks5_proxy_ipv4(url, rdns, resolve_host): proxy = Proxy.from_url(SOCKS5_IPV4_URL, rdns=rdns) status_code = make_request( proxy=proxy, url=url, resolve_host=resolve_host ) assert status_code == 200
def test_socks5_proxy_with_invalid_proxy_port(unused_tcp_port): proxy = Proxy.create( proxy_type=ProxyType.SOCKS5, host=SOCKS5_IPV4_HOST, port=unused_tcp_port, username=LOGIN, password=PASSWORD, ) with pytest.raises(ProxyConnectionError): make_request(proxy=proxy, url=TEST_URL)
def test_socks5_proxy_with_connect_timeout(): proxy = Proxy.create( proxy_type=ProxyType.SOCKS5, host=SOCKS5_IPV4_HOST, port=SOCKS5_IPV4_PORT, username=LOGIN, password=PASSWORD, ) with pytest.raises(ProxyTimeoutError): make_request(proxy=proxy, url=TEST_URL, timeout=0.0001)
def test_socks5_proxy_with_invalid_credentials(): proxy = Proxy.create( proxy_type=ProxyType.SOCKS5, host=SOCKS5_IPV4_HOST, port=SOCKS5_IPV4_PORT, username=LOGIN, password=PASSWORD + 'aaa', ) with pytest.raises(ProxyError): make_request(proxy=proxy, url=TEST_URL)
def test_http_proxy_with_invalid_credentials(): proxy = Proxy.create( proxy_type=ProxyType.HTTP, host=PROXY_HOST_IPV4, port=HTTP_PROXY_PORT, username=LOGIN, password=PASSWORD + 'aaa', ) with pytest.raises(ProxyError): make_request(proxy=proxy, url=TEST_URL_IPV4)
def tunneling(self): """ This is the main function that parses the proxy and creates a tunnel. """ self.socket_connection = Proxy.from_url( url=self.tunnel_proxy, client=clients.Clients[self.client.upper()].value, proxy=self.proxy) self.sock = self.socket_connection.connect( dest_host=self.server_name, dest_port=self.server_port, timeout=self.timeout, )
def _start_proxied_socket(url, options, proxy): if not HAVE_PYTHON_SOCKS: raise WebSocketException( "Python Socks is needed for SOCKS proxying but is not available") hostname, port, resource, is_secure = parse_url(url) if proxy.proxy_protocol == "socks5": rdns = False proxy_type = ProxyType.SOCKS5 if proxy.proxy_protocol == "socks4": rdns = False proxy_type = ProxyType.SOCKS4 # socks5h and socks4a send DNS through proxy if proxy.proxy_protocol == "socks5h": rdns = True proxy_type = ProxyType.SOCKS5 if proxy.proxy_protocol == "socks4a": rdns = True proxy_type = ProxyType.SOCKS4 ws_proxy = Proxy.create(proxy_type=proxy_type, host=proxy.proxy_host, port=int(proxy.proxy_port), username=proxy.auth[0] if proxy.auth else None, password=proxy.auth[1] if proxy.auth else None, rdns=rdns) sock = ws_proxy.connect(hostname, port, timeout=proxy.proxy_timeout) if is_secure and HAVE_SSL: sock = _ssl_socket(sock, options.sslopt, hostname) elif is_secure: raise WebSocketException("SSL not available.") return sock, (hostname, port, resource)
def test_socks5_proxy_ipv4_with_auth_none(rdns): proxy = Proxy.from_url(SOCKS5_IPV4_URL_WO_AUTH, rdns=rdns) status_code = make_request(proxy=proxy, url=TEST_URL) assert status_code == 200
def test_http_proxy(): proxy = Proxy.from_url(HTTP_PROXY_URL) status_code = make_request(proxy=proxy, url=TEST_URL) assert status_code == 200
def test_socks4_proxy(rdns, resolve_host): proxy = Proxy.from_url(SOCKS4_URL, rdns=rdns) status_code = make_request(proxy=proxy, url=TEST_URL, resolve_host=resolve_host) assert status_code == 200
def test_socks5_proxy_ipv6(): proxy = Proxy.from_url(SOCKS5_IPV6_URL) status_code = make_request(proxy=proxy, url=TEST_URL) assert status_code == 200
def test_socks5_proxy_hostname_ipv4(): proxy = Proxy.from_url(SOCKS5_IPV4_HOSTNAME_URL) status_code = make_request(proxy=proxy, url=TEST_URL_IPV4, ) assert status_code == 200
def test_socks5_proxy_hostname_ipv6(rdns): proxy = Proxy.from_url(SOCKS5_IPV4_URL, rdns=rdns) status_code = make_request(proxy=proxy, url=TEST_URL_IPv6) assert status_code == 200
def test_answer(): os.mkdir("potatopath") proxy = Proxy.from_url('socks5://user:[email protected]:1080') assert inc(3) == 4