From c1179c8e680c2f3601e3249bb5a6b38a1d2c82f2 Mon Sep 17 00:00:00 2001 From: liz johnson Date: Thu, 8 Aug 2024 18:30:54 -0500 Subject: [PATCH] handle socks connection --- lib/socksify/tcpsocket.rb | 6 +++--- test/test_tcpsocket.rb | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/socksify/tcpsocket.rb b/lib/socksify/tcpsocket.rb index 8ff20cf..a2160e1 100644 --- a/lib/socksify/tcpsocket.rb +++ b/lib/socksify/tcpsocket.rb @@ -17,7 +17,7 @@ def initialize(host = nil, port = nil, local_host = nil, local_port = nil, **kwa socks_ignores = set_socks_ignores(socks_peer) host = socks_peer.peer_host if socks_peer if socks_server && socks_port && !socks_ignores.include?(host) - make_socks_connection(host, port, socks_server, socks_port) + make_socks_connection(host, port, socks_server, socks_port, **kwargs) else make_direct_connection(host, port, local_host, local_port, **kwargs) end @@ -57,9 +57,9 @@ def set_socks_ignores(socks_peer = nil) socks_peer ? [] : self.class.socks_ignores end - def make_socks_connection(host, port, socks_server, socks_port) + def make_socks_connection(host, port, socks_server, socks_port, **kwargs) Socksify.debug_notice "Connecting to SOCKS server #{socks_server}:#{socks_port}" - initialize_tcp socks_server, socks_port + initialize_tcp socks_server, socks_port, **kwargs socks_authenticate unless @socks_version =~ /^4/ socks_connect(host, port) if host end diff --git a/test/test_tcpsocket.rb b/test/test_tcpsocket.rb index 2ce740c..66c5b15 100644 --- a/test/test_tcpsocket.rb +++ b/test/test_tcpsocket.rb @@ -7,13 +7,26 @@ class TCPSocketTest < Minitest::Test if RUBY_VERSION.to_f >= 3.0 def test_tcp_socket_direct_connection_with_connection_timeout + disable_socks + socket = TCPSocket.new('127.0.0.1', 9050, connect_timeout: 0.1) assert !socket.closed? end + + def test_tcp_socket_socks_connection_with_connection_timeout + enable_socks + + # leave off the host because we don't need to worry about connecting to socks + socket = TCPSocket.new(connect_timeout: 0.1) + + assert !socket.closed? + end end - def test_tcp_socket_direct_connection_with_connection_timeout + def test_tcp_socket_direct_connection_with_connection_timeout_no_kwargs + disable_socks + socket = TCPSocket.new('127.0.0.1', 9050) assert !socket.closed?