Skip to content

Commit

Permalink
TCPSocket::ignores by Patrick Sinclair + test
Browse files Browse the repository at this point in the history
tests: use local socksify
  • Loading branch information
astro committed Apr 17, 2008
1 parent c690ad8 commit 659908c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/socksify.rb
Expand Up @@ -102,15 +102,22 @@ def self.socks_port
def self.socks_port=(port)
@@socks_port = port
end
def self.ignores
@@ignores ||= []
end
def self.ignores=(ignores)
@@ignores = ignores
end

alias :initialize_tcp :initialize

# See http://tools.ietf.org/html/rfc1928
def initialize(host=nil, port=0, local_host="0.0.0.0", local_port=0)
socks_server = self.class.socks_server
socks_port = self.class.socks_port
ignores = self.class.ignores

if socks_server and socks_port
if socks_server and socks_port and not ignores.include?(host)
Socksify::debug_notice "Connecting to SOCKS server #{socks_server}:#{socks_port}"
initialize_tcp socks_server, socks_port

Expand Down
18 changes: 17 additions & 1 deletion test/tc_socksify.rb
@@ -1,10 +1,13 @@
#!/usr/bin/ruby

require 'test/unit'
require 'socksify'
require 'net/http'
require 'uri'

$:.unshift "#{File::dirname($0)}/../lib/"
require 'socksify'


class SocksifyTest < Test::Unit::TestCase
def setup
Socksify::debug = true
Expand Down Expand Up @@ -36,6 +39,19 @@ def test_whatismyip
end
end

def test_ignores
disable_socks

ip_direct = whatismyip

enable_socks
TCPSocket.ignores << 'www.whatismyip.org'

ip_socks_ignored = whatismyip

assert(ip_direct == ip_socks_ignored)
end

def whatismyip
url = URI::parse('http://www.whatismyip.org/')
Net::HTTP.start(url.host, url.port) do |http|
Expand Down

0 comments on commit 659908c

Please sign in to comment.