Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ability to disable referral queries

  • Loading branch information...
commit b9c9f614dc4a0105f5a978f947d5a3d453b3ed2f 1 parent efbbf9c
@weppos authored
View
2  CHANGELOG.md
@@ -15,6 +15,8 @@
- NEW: Added full whois.nic.pw parser.
+- NEW: Ability to disable referral queries setting option :referral => false
+
- CHANGED: Dropped support for Ruby 1.8
- CHANGED: Renamed Whois::Record::Scanners::Ast to Renamed Whois::Record::Scanners::Nodable
View
2  lib/whois/client.rb
@@ -41,6 +41,8 @@ class Client
# to the specific local port.
# @option settings [String, nil] :host (nil)
# The server host to query. Leave it blank for intelligent detection.
+ # @option settings [Boolean, nil] :referral (nil)
+ # Set to +false+ to disable queries to referral WHOIS servers.
#
# @yield [self]
#
View
2  lib/whois/server/adapters/afilias.rb
@@ -29,7 +29,7 @@ def request(string)
response = query_the_socket(string, host)
buffer_append response, host
- if referral = extract_referral(response)
+ if options[:referral] != false && referral = extract_referral(response)
response = query_the_socket(string, referral)
buffer_append(response, referral)
end
View
2  lib/whois/server/adapters/verisign.rb
@@ -29,7 +29,7 @@ def request(string)
response = query_the_socket("=#{string}", host)
buffer_append response, host
- if referral = extract_referral(response)
+ if options[:referral] != false && referral = extract_referral(response)
response = query_the_socket(string, referral)
buffer_append(response, referral)
end
View
24 spec/whois/server/adapters/afilias_spec.rb
@@ -9,11 +9,11 @@
describe "#lookup" do
context "without referral" do
it "returns the WHOIS record" do
- response = "No match for DOMAIN.TEST."
+ response = "No match for example.test."
expected = response
- server.query_handler.expects(:call).with("domain.test", "whois.afilias-grs.info", 43).returns(response)
+ server.query_handler.expects(:call).with("example.test", "whois.afilias-grs.info", 43).returns(response)
- record = server.lookup("domain.test")
+ record = server.lookup("example.test")
record.to_s.should == expected
record.parts.should have(1).part
record.parts.should == [Whois::Record::Part.new(:body => response, :host => "whois.afilias-grs.info")]
@@ -23,16 +23,26 @@
context "with referral" do
it "follows all referrals" do
referral = File.read(fixture("referrals/afilias.bz.txt"))
- response = "Match for DOMAIN.TEST."
+ response = "Match for example.test."
expected = referral + "\n" + response
- server.query_handler.expects(:call).with("domain.test", "whois.afilias-grs.info", 43).returns(referral)
- server.query_handler.expects(:call).with("domain.test", "whois.belizenic.bz", 43).returns(response)
+ server.query_handler.expects(:call).with("example.test", "whois.afilias-grs.info", 43).returns(referral)
+ server.query_handler.expects(:call).with("example.test", "whois.belizenic.bz", 43).returns(response)
- record = server.lookup("domain.test")
+ record = server.lookup("example.test")
record.to_s.should == expected
record.parts.should have(2).parts
record.parts.should == [Whois::Record::Part.new(:body => referral, :host => "whois.afilias-grs.info"), Whois::Record::Part.new(:body => response, :host => "whois.belizenic.bz")]
end
+
+ it "ignores referral if options[:referral] is false" do
+ referral = File.read(fixture("referrals/afilias.bz.txt"))
+ server.options[:referral] = false
+ server.query_handler.expects(:call).with("example.test", "whois.afilias-grs.info", 43).returns(referral)
+ server.query_handler.expects(:call).with("example.test", "whois.belizenic.bz", 43).never
+
+ record = server.lookup("example.test")
+ record.parts.should have(1).part
+ end
end
end
View
44 spec/whois/server/adapters/verisign_spec.rb
@@ -9,11 +9,11 @@
describe "#lookup" do
context "without referral" do
it "returns the WHOIS record" do
- response = "No match for DOMAIN.TEST."
+ response = "No match for example.test."
expected = response
- server.query_handler.expects(:call).with("=domain.test", "whois.test", 43).returns(response)
+ server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(response)
- record = server.lookup("domain.test")
+ record = server.lookup("example.test")
record.to_s.should == expected
record.parts.should have(1).part
record.parts.should == [Whois::Record::Part.new(:body => response, :host => "whois.test")]
@@ -23,43 +23,53 @@
context "with referral" do
it "follows all referrals" do
referral = File.read(fixture("referrals/crsnic.com.txt"))
- response = "Match for DOMAIN.TEST."
+ response = "Match for example.test."
expected = referral + "\n" + response
- server.query_handler.expects(:call).with("=domain.test", "whois.test", 43).returns(referral)
- server.query_handler.expects(:call).with("domain.test", "whois.markmonitor.com", 43).returns(response)
+ server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(referral)
+ server.query_handler.expects(:call).with("example.test", "whois.markmonitor.com", 43).returns(response)
- record = server.lookup("domain.test")
+ record = server.lookup("example.test")
record.to_s.should == expected
record.parts.should have(2).parts
record.parts.should == [Whois::Record::Part.new(:body => referral, :host => "whois.test"), Whois::Record::Part.new(:body => response, :host => "whois.markmonitor.com")]
end
- it "extracts the closest referral when multiple referrals" do
+ it "extracts the closest referral if multiple referrals" do
referral = File.read(fixture("referrals/crsnic.com_referral_multiple.txt"))
- server.query_handler.expects(:call).with("=domain.test", "whois.test", 43).returns(referral)
- server.query_handler.expects(:call).with("domain.test", "whois.markmonitor.com", 43).returns("")
+ server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(referral)
+ server.query_handler.expects(:call).with("example.test", "whois.markmonitor.com", 43).returns("")
- record = server.lookup("domain.test")
+ record = server.lookup("example.test")
record.parts.should have(2).parts
end
- it "ignores referral when is not defined" do
+ it "ignores referral if is not defined" do
referral = File.read(fixture("referrals/crsnic.com_referral_not_defined.txt"))
- server.query_handler.expects(:call).with("=domain.test", "whois.test", 43).returns(referral)
+ server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(referral)
server.query_handler.expects(:call).never
- record = server.lookup("domain.test")
+ record = server.lookup("example.test")
+ record.parts.should have(1).part
+ end
+
+ it "ignores referral if options[:referral] is false" do
+ referral = File.read(fixture("referrals/crsnic.com_referral_not_defined.txt"))
+ # server.options[:referral] = false
+ server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(referral)
+ server.query_handler.expects(:call).never
+
+ record = server.lookup("example.test")
record.parts.should have(1).part
end
# (see #103)
# This is the case of vrsn-20100925-dnssecmonitor86.net
- it "gracefully ignores referral when is missing" do
+ it "ignores referral (gracefully) if missing" do
referral = File.read(fixture("referrals/crsnic.com_referral_missing.txt"))
- server.query_handler.expects(:call).with("=domain.test", "whois.test", 43).returns(referral)
+ server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(referral)
server.query_handler.expects(:call).never
- record = server.lookup("domain.test")
+ record = server.lookup("example.test")
record.parts.should have(1).part
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.