Skip to content

Commit

Permalink
Fixed incompatibility with Ruby 1.8.7 resolv-replace and :bind_host (…
Browse files Browse the repository at this point in the history
…references #40).

When bind_host is not passed, the following error is raised: 

    ArgumentError: cannot interpret as DNS name: nil
    
    /usr/local/lib/ruby/1.8/resolv.rb:1060:in `create'
    /usr/local/lib/ruby/1.8/resolv.rb:906:in `generate_candidates'
    /usr/local/lib/ruby/1.8/resolv.rb:931:in `resolv'
    /usr/local/lib/ruby/1.8/resolv.rb:481:in `each_resource'
    /usr/local/lib/ruby/1.8/resolv.rb:386:in `each_address'
    /usr/local/lib/ruby/1.8/resolv.rb:115:in `each_address'
    /usr/local/lib/ruby/1.8/resolv.rb:114:in `each'
    /usr/local/lib/ruby/1.8/resolv.rb:114:in `each_address'
    /usr/local/lib/ruby/1.8/resolv.rb:92:in `getaddress'
    /usr/local/lib/ruby/1.8/resolv.rb:43:in `getaddress'
    /usr/local/lib/ruby/1.8/resolv-replace.rb:8:in `getaddress'
    /usr/local/lib/ruby/1.8/resolv-replace.rb:18:in `initialize'
  • Loading branch information
weppos committed Jan 24, 2011
1 parent 7a04f94 commit ffbbaff
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 18 deletions.
7 changes: 6 additions & 1 deletion lib/whois/server/adapters/base.rb
Expand Up @@ -28,6 +28,10 @@ class Base
# Default WHOIS request port.
DEFAULT_WHOIS_PORT = 43

# Default bind hostname.
DEFAULT_BIND_HOST = "0.0.0.0"


# @return [Symbol] The type of WHOIS server
attr_reader :type
# @return [String] The allocation this server is responsible for.
Expand Down Expand Up @@ -150,7 +154,7 @@ def query_the_socket(query, host, port = nil)
query,
host,
port || options[:port] || DEFAULT_WHOIS_PORT,
options[:bind_host],
options[:bind_host] || DEFAULT_BIND_HOST,
options[:bind_port]
)
end
Expand All @@ -162,6 +166,7 @@ def query_the_socket(query, host, port = nil)
#
# @api internal
def ask_the_socket(query, host, port, local_host, local_port)
args = [host, port, local_host, local_port].compact
client = TCPSocket.open(host, port, local_host, local_port)
client.write("#{query}\r\n") # I could use put(foo) and forget the \n
client.read # but write/read is more symmetric than puts/read
Expand Down
2 changes: 1 addition & 1 deletion spec/integration_spec.rb
Expand Up @@ -6,7 +6,7 @@
it "works" do
with_definitions do
Whois::Server.define(:tld, ".it", "whois.nic.it")
Whois::Server::Adapters::Standard.any_instance.expects(:ask_the_socket).with("example.it", "whois.nic.it", 43, nil, nil).returns(<<-EOS)
Whois::Server::Adapters::Standard.any_instance.expects(:ask_the_socket).with("example.it", "whois.nic.it", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns(<<-EOS)
Domain: example.it
Status: AVAILABLE
EOS
Expand Down
6 changes: 3 additions & 3 deletions spec/whois/server/adapters/afilias_spec.rb
Expand Up @@ -13,7 +13,7 @@
it "returns the WHOIS record" do
response = "No match for DOMAIN.TEST."
expected = response
@server.expects(:ask_the_socket).with("domain.test", "whois.afilias-grs.info", 43, nil, nil).returns(response)
@server.expects(:ask_the_socket).with("domain.test", "whois.afilias-grs.info", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns(response)

record = @server.query("domain.test")
record.to_s.should == expected
Expand All @@ -27,8 +27,8 @@
referral = File.read(fixture("referrals/afilias.bz.txt"))
response = "Match for DOMAIN.TEST."
expected = referral + "\n" + response
@server.expects(:ask_the_socket).with("domain.test", "whois.afilias-grs.info", 43, nil, nil).returns(referral)
@server.expects(:ask_the_socket).with("domain.test", "whois.belizenic.bz", 43, nil, nil).returns(response)
@server.expects(:ask_the_socket).with("domain.test", "whois.afilias-grs.info", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns(referral)
@server.expects(:ask_the_socket).with("domain.test", "whois.belizenic.bz", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns(response)

record = @server.query("domain.test")
record.to_s.should == expected
Expand Down
4 changes: 2 additions & 2 deletions spec/whois/server/adapters/formatted_spec.rb
Expand Up @@ -12,7 +12,7 @@
response = "Whois Response"
expected = response
server = klass.new(*@definition)
server.expects(:ask_the_socket).with("-T dn,ace -C US-ASCII domain.de", "whois.denic.de", 43, nil, nil).returns(response)
server.expects(:ask_the_socket).with("-T dn,ace -C US-ASCII domain.de", "whois.denic.de", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns(response)

record = server.query("domain.de")
record.to_s.should == expected
Expand All @@ -33,7 +33,7 @@
it "sends the request to given port" do
response = "Whois Response"
server = klass.new(:tld, ".de", "whois.denic.de", { :format => "-T dn,ace -C US-ASCII %s", :port => 20 })
server.expects(:ask_the_socket).with("-T dn,ace -C US-ASCII domain.de", "whois.denic.de", 20, nil, nil).returns(response)
server.expects(:ask_the_socket).with("-T dn,ace -C US-ASCII domain.de", "whois.denic.de", 20, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns(response)

server.query("domain.de")
end
Expand Down
6 changes: 3 additions & 3 deletions spec/whois/server/adapters/pir_spec.rb
Expand Up @@ -13,7 +13,7 @@
it "returns the WHOIS record" do
response = "No match for DOMAIN.TEST."
expected = response
@server.expects(:ask_the_socket).with("FULL domain.test", "whois.publicinterestregistry.net", 43, nil, nil).returns(response)
@server.expects(:ask_the_socket).with("FULL domain.test", "whois.publicinterestregistry.net", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns(response)

record = @server.query("domain.test")
record.to_s.should == expected
Expand All @@ -27,8 +27,8 @@
referral = File.read(fixture("referrals/pir.org.txt"))
response = "Match for DOMAIN.TEST."
expected = referral + "\n" + response
@server.expects(:ask_the_socket).with("FULL domain.test", "whois.publicinterestregistry.net", 43, nil, nil).returns(referral)
@server.expects(:ask_the_socket).with("domain.test", "whois.iana.org", 43, nil, nil).returns(response)
@server.expects(:ask_the_socket).with("FULL domain.test", "whois.publicinterestregistry.net", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns(referral)
@server.expects(:ask_the_socket).with("domain.test", "whois.iana.org", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns(response)

record = @server.query("domain.test")
record.to_s.should == expected
Expand Down
4 changes: 2 additions & 2 deletions spec/whois/server/adapters/standard_spec.rb
Expand Up @@ -12,7 +12,7 @@
response = "Whois Response"
expected = response
server = klass.new(*@definition)
server.expects(:ask_the_socket).with("domain.test", "whois.test", 43, nil, nil).returns(response)
server.expects(:ask_the_socket).with("domain.test", "whois.test", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns(response)

record = server.query("domain.test")
record.to_s.should == expected
Expand All @@ -23,7 +23,7 @@
it "sends the request to given port" do
response = "Whois Response"
server = klass.new(:tld, ".test", "whois.test", { :port => 20 })
server.expects(:ask_the_socket).with("domain.test", "whois.test", 20, nil, nil).returns(response)
server.expects(:ask_the_socket).with("domain.test", "whois.test", 20, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns(response)

server.query("domain.test")
end
Expand Down
12 changes: 6 additions & 6 deletions spec/whois/server/adapters/verisign_spec.rb
Expand Up @@ -13,7 +13,7 @@
it "returns the WHOIS record" do
response = "No match for DOMAIN.TEST."
expected = response
@server.expects(:ask_the_socket).with("=domain.test", "whois.test", 43, nil, nil).returns(response)
@server.expects(:ask_the_socket).with("=domain.test", "whois.test", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns(response)

record = @server.query("domain.test")
record.to_s.should == expected
Expand All @@ -27,8 +27,8 @@
referral = File.read(fixture("referrals/crsnic.com.txt"))
response = "Match for DOMAIN.TEST."
expected = referral + "\n" + response
@server.expects(:ask_the_socket).with("=domain.test", "whois.test", 43, nil, nil).returns(referral)
@server.expects(:ask_the_socket).with("domain.test", "whois.markmonitor.com", 43, nil, nil).returns(response)
@server.expects(:ask_the_socket).with("=domain.test", "whois.test", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns(referral)
@server.expects(:ask_the_socket).with("domain.test", "whois.markmonitor.com", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns(response)

record = @server.query("domain.test")
record.to_s.should == expected
Expand All @@ -38,7 +38,7 @@

it "ignore referral when is not defined" do
referral = File.read(fixture("referrals/crsnic.com_referral_not_defined.txt"))
@server.expects(:ask_the_socket).with("=domain.test", "whois.test", 43, nil, nil).returns(referral)
@server.expects(:ask_the_socket).with("=domain.test", "whois.test", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns(referral)
@server.expects(:ask_the_socket).never

record = @server.query("domain.test")
Expand All @@ -47,8 +47,8 @@

it "extracts the closest referral when multiple referrals" do
referral = File.read(fixture("referrals/crsnic.com_referral_multiple.txt"))
@server.expects(:ask_the_socket).with("=domain.test", "whois.test", 43, nil, nil).returns(referral)
@server.expects(:ask_the_socket).with("domain.test", "whois.markmonitor.com", 43, nil, nil).returns("")
@server.expects(:ask_the_socket).with("=domain.test", "whois.test", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns(referral)
@server.expects(:ask_the_socket).with("domain.test", "whois.markmonitor.com", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, nil).returns("")

record = @server.query("domain.test")
record.parts.should have(2).parts
Expand Down

0 comments on commit ffbbaff

Please sign in to comment.