whois 4.0.8 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +11 -0
  3. data/.rspec +1 -0
  4. data/.simplecov +4 -0
  5. data/.travis.yml +27 -0
  6. data/CHANGELOG.md +9 -0
  7. data/Gemfile +5 -0
  8. data/LICENSE.txt +1 -1
  9. data/README.md +1 -1
  10. data/Rakefile +33 -0
  11. data/data/tld.json +21 -21
  12. data/lib/whois.rb +1 -1
  13. data/lib/whois/client.rb +1 -1
  14. data/lib/whois/errors.rb +1 -1
  15. data/lib/whois/record.rb +1 -1
  16. data/lib/whois/record/part.rb +1 -1
  17. data/lib/whois/server.rb +14 -2
  18. data/lib/whois/server/adapters/afilias.rb +1 -1
  19. data/lib/whois/server/adapters/arin.rb +1 -1
  20. data/lib/whois/server/adapters/arpa.rb +1 -1
  21. data/lib/whois/server/adapters/base.rb +1 -1
  22. data/lib/whois/server/adapters/formatted.rb +1 -1
  23. data/lib/whois/server/adapters/none.rb +1 -1
  24. data/lib/whois/server/adapters/not_implemented.rb +1 -1
  25. data/lib/whois/server/adapters/standard.rb +1 -1
  26. data/lib/whois/server/adapters/verisign.rb +1 -1
  27. data/lib/whois/server/adapters/web.rb +1 -1
  28. data/lib/whois/server/socket_handler.rb +1 -1
  29. data/lib/whois/version.rb +2 -2
  30. data/spec/fixtures/referrals/afilias.bz.txt +23 -0
  31. data/spec/fixtures/referrals/arin_referral_apnic.txt +78 -0
  32. data/spec/fixtures/referrals/arin_referral_missing.txt +52 -0
  33. data/spec/fixtures/referrals/arin_referral_ripe.txt +50 -0
  34. data/spec/fixtures/referrals/arin_referral_rwhois.txt +63 -0
  35. data/spec/fixtures/referrals/arin_referral_servernap.txt +63 -0
  36. data/spec/fixtures/referrals/arin_referral_whois.txt +56 -0
  37. data/spec/fixtures/referrals/crsnic.com.txt +60 -0
  38. data/spec/fixtures/referrals/crsnic.com_referral.txt +56 -0
  39. data/spec/fixtures/referrals/crsnic.com_referral_missing.txt +50 -0
  40. data/spec/integration/whois_spec.rb +73 -0
  41. data/spec/spec_helper.rb +24 -0
  42. data/spec/support/helpers/connectivity_helper.rb +15 -0
  43. data/spec/support/helpers/spec_helper.rb +31 -0
  44. data/spec/whois/client_spec.rb +144 -0
  45. data/spec/whois/errors_spec.rb +23 -0
  46. data/spec/whois/record/part_spec.rb +38 -0
  47. data/spec/whois/record_spec.rb +158 -0
  48. data/spec/whois/server/adapters/afilias_spec.rb +49 -0
  49. data/spec/whois/server/adapters/arin_spec.rb +84 -0
  50. data/spec/whois/server/adapters/arpa_spec.rb +20 -0
  51. data/spec/whois/server/adapters/base_spec.rb +150 -0
  52. data/spec/whois/server/adapters/formatted_spec.rb +53 -0
  53. data/spec/whois/server/adapters/none_spec.rb +23 -0
  54. data/spec/whois/server/adapters/not_implemented_spec.rb +24 -0
  55. data/spec/whois/server/adapters/standard_spec.rb +42 -0
  56. data/spec/whois/server/adapters/verisign_spec.rb +60 -0
  57. data/spec/whois/server/adapters/web_spec.rb +24 -0
  58. data/spec/whois/server/socket_handler_spec.rb +27 -0
  59. data/spec/whois/server_spec.rb +300 -0
  60. data/spec/whois/whois_spec.rb +15 -0
  61. data/tasks/spec.rake +199 -0
  62. data/utils/compare-whois.rb +30 -0
  63. data/utils/deftld.rb +231 -0
  64. data/utils/defutils.rb +26 -0
  65. data/utils/fixupd.rb +60 -0
  66. data/utils/matrix.rb +68 -0
  67. data/utils/mkwhois.rb +31 -0
  68. data/whois.gemspec +19 -32
  69. metadata +82 -5
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Whois::Server::Adapters::Formatted do
4
+
5
+ let(:definition) { [:tld, ".de", "whois.denic.de", { :format => "-T dn,ace -C US-ASCII %s" }] }
6
+
7
+
8
+ describe "#lookup" do
9
+ it "returns the WHOIS record" do
10
+ response = "Whois Response"
11
+ expected = response
12
+ server = described_class.new(*definition)
13
+ expect(server.query_handler).to receive(:call).with("-T dn,ace -C US-ASCII domain.de", "whois.denic.de", 43).and_return(response)
14
+
15
+ record = server.lookup("domain.de")
16
+ expect(record.to_s).to eq(expected)
17
+ expect(record.parts).to eq([Whois::Record::Part.new(body: response, host: "whois.denic.de")])
18
+ end
19
+
20
+ context "without format option" do
21
+ it "raises an error" do
22
+ server = described_class.new(*[:tld, ".de", "whois.denic.de", {}])
23
+ expect(server.query_handler).to receive(:call).never
24
+
25
+ expect {
26
+ server.lookup("domain.de")
27
+ }.to raise_error(Whois::ServerError)
28
+ end
29
+ end
30
+
31
+ context "with port option" do
32
+ it "sends the request to given port" do
33
+ response = "Whois Response"
34
+ server = described_class.new(:tld, ".de", "whois.denic.de", { :format => "-T dn,ace -C US-ASCII %s", :port => 20 })
35
+ expect(server.query_handler).to receive(:call).with("-T dn,ace -C US-ASCII domain.de", "whois.denic.de", 20).and_return(response)
36
+
37
+ server.lookup("domain.de")
38
+ end
39
+ end
40
+
41
+ context "with bind option" do
42
+ it "binds the request to given host and port" do
43
+ response = "Whois Response"
44
+ server = described_class.new(:tld, ".de", "whois.denic.de", { :format => "-T dn,ace -C US-ASCII %s" })
45
+ server.configure(:bind_host => "192.168.1.1", :bind_port => 3000)
46
+ expect(server.query_handler).to receive(:call).with("-T dn,ace -C US-ASCII domain.de", "whois.denic.de", 43, "192.168.1.1", 3000).and_return(response)
47
+
48
+ server.lookup("domain.de")
49
+ end
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Whois::Server::Adapters::None do
4
+
5
+ describe "#lookup" do
6
+ it "raises Whois::NoInterfaceError" do
7
+ expect {
8
+ described_class.new(:tld, ".test", nil).lookup("example.test")
9
+ }.to raise_error(Whois::NoInterfaceError)
10
+ end
11
+
12
+ it "customizes the error message according to the type" do
13
+ expect {
14
+ described_class.new(:tld, ".test", nil).lookup("example.test")
15
+ }.to raise_error(Whois::NoInterfaceError, /tld/)
16
+
17
+ expect {
18
+ described_class.new(:ipv4, "127.0.0.1", nil).lookup("127.0.0.1")
19
+ }.to raise_error(Whois::NoInterfaceError, /ipv4/)
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Whois::Server::Adapters::NotImplemented do
4
+
5
+ before(:each) do
6
+ @definition = [:ipv6, "2001:0000::/32", "teredo", { :adapter => Whois::Server::Adapters::NotImplemented }]
7
+ end
8
+
9
+
10
+ describe "#lookup" do
11
+ it "raises Whois::ServerNotImplemented" do
12
+ expect {
13
+ described_class.new(*@definition).lookup("example.test")
14
+ }.to raise_error(Whois::ServerNotImplemented)
15
+ end
16
+
17
+ it "customizes the error message according to the host" do
18
+ expect {
19
+ described_class.new(*@definition).lookup("example.test")
20
+ }.to raise_error(Whois::ServerNotImplemented, /teredo/)
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Whois::Server::Adapters::Standard do
4
+
5
+ let(:definition) { [:tld, ".test", "whois.test", {}] }
6
+
7
+
8
+ describe "#lookup" do
9
+ it "returns the WHOIS record" do
10
+ response = "Whois Response"
11
+ expected = response
12
+ server = described_class.new(*definition)
13
+ expect(server.query_handler).to receive(:call).with("domain.test", "whois.test", 43).and_return(response)
14
+
15
+ record = server.lookup("domain.test")
16
+ expect(record.to_s).to eq(expected)
17
+ expect(record.parts).to eq([Whois::Record::Part.new(body: response, host: "whois.test")])
18
+ end
19
+
20
+ context "with port option" do
21
+ it "sends the request to given port" do
22
+ response = "Whois Response"
23
+ server = described_class.new(:tld, ".test", "whois.test", { :port => 20 })
24
+ expect(server.query_handler).to receive(:call).with("domain.test", "whois.test", 20).and_return(response)
25
+
26
+ server.lookup("domain.test")
27
+ end
28
+ end
29
+
30
+ context "with bind option" do
31
+ it "binds the request to given host and port" do
32
+ response = "Whois Response"
33
+ server = described_class.new(:tld, ".test", "whois.test", { :port => 20 })
34
+ server.configure(:bind_host => "192.168.1.100", :bind_port => 3000)
35
+ expect(server.query_handler).to receive(:call).with("domain.test", "whois.test", 20, "192.168.1.100", 3000).and_return(response)
36
+
37
+ server.lookup("domain.test")
38
+ end
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe Whois::Server::Adapters::Verisign do
4
+
5
+ let(:definition) { [:tld, ".test", "whois.test", {}] }
6
+ let(:server) { described_class.new(*definition) }
7
+
8
+
9
+ describe "#lookup" do
10
+ context "without referral" do
11
+ it "returns the WHOIS record" do
12
+ response = "No match for example.test."
13
+ expected = response
14
+ expect(server.query_handler).to receive(:call).with("=example.test", "whois.test", 43).and_return(response)
15
+
16
+ record = server.lookup("example.test")
17
+ expect(record.to_s).to eq(expected)
18
+ expect(record.parts.size).to eq(1)
19
+ expect(record.parts).to eq([Whois::Record::Part.new(body: response, host: "whois.test")])
20
+ end
21
+ end
22
+
23
+ context "with referral" do
24
+ it "follows all referrals" do
25
+ referral = File.read(fixture("referrals/crsnic.com.txt"))
26
+ response = "Match for example.test."
27
+ expected = referral + "\n" + response
28
+ expect(server.query_handler).to receive(:call).with("=example.test", "whois.test", 43).and_return(referral)
29
+ expect(server.query_handler).to receive(:call).with("example.test", "whois.markmonitor.com", 43).and_return(response)
30
+
31
+ record = server.lookup("example.test")
32
+ expect(record.to_s).to eq(expected)
33
+ expect(record.parts.size).to eq(2)
34
+ expect(record.parts).to eq([Whois::Record::Part.new(body: referral, host: "whois.test"), Whois::Record::Part.new(body: response, host: "whois.markmonitor.com")])
35
+ end
36
+
37
+ it "ignores referral if options[:referral] is false" do
38
+ referral = File.read(fixture("referrals/crsnic.com.txt"))
39
+ server.options[:referral] = false
40
+ expect(server.query_handler).to receive(:call).with("=example.test", "whois.test", 43).and_return(referral)
41
+ expect(server.query_handler).to receive(:call).never
42
+
43
+ record = server.lookup("example.test")
44
+ expect(record.parts.size).to eq(1)
45
+ end
46
+
47
+ # (see #103)
48
+ # This is the case of vrsn-20100925-dnssecmonitor86.net
49
+ it "ignores referral (gracefully) if missing" do
50
+ referral = File.read(fixture("referrals/crsnic.com_referral_missing.txt"))
51
+ expect(server.query_handler).to receive(:call).with("=example.test", "whois.test", 43).and_return(referral)
52
+ expect(server.query_handler).to receive(:call).never
53
+
54
+ record = server.lookup("example.test")
55
+ expect(record.parts.size).to eq(1)
56
+ end
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Whois::Server::Adapters::Web do
4
+
5
+ before(:each) do
6
+ @definition = [:tld, ".test", nil, { :url => "http://whois.test" }]
7
+ end
8
+
9
+
10
+ describe "#lookup" do
11
+ it "raises Whois::WebInterfaceError" do
12
+ expect {
13
+ described_class.new(*@definition).lookup("example.test")
14
+ }.to raise_error(Whois::WebInterfaceError)
15
+ end
16
+
17
+ it "customizes the error message with the WHOIS web url" do
18
+ expect {
19
+ described_class.new(*@definition).lookup("example.test")
20
+ }.to raise_error(Whois::WebInterfaceError, /whois\.test/)
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'whois/server/socket_handler'
3
+
4
+ describe Whois::Server::SocketHandler do
5
+
6
+ describe "#call" do
7
+ [ Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ETIMEDOUT, Errno::EPIPE, SocketError ].each do |error|
8
+ it "re-raises #{error} as Whois::ConnectionError" do
9
+ expect(subject).to receive(:execute).and_raise(error)
10
+ expect {
11
+ subject.call("example.test", "whois.test", 43)
12
+ }.to raise_error(Whois::ConnectionError, "#{error}: #{error.new.message}")
13
+ end
14
+
15
+ it "executes a socket connection for given args" do
16
+ socket = double("Handler")
17
+ expect(socket).to receive(:write).with("example.test\r\n")
18
+ expect(socket).to receive(:read)
19
+ expect(socket).to receive(:close)
20
+
21
+ expect(TCPSocket).to receive(:new).with("whois.test", 43).and_return(socket)
22
+ subject.call("example.test", "whois.test", 43)
23
+ end
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,300 @@
1
+ require 'spec_helper'
2
+
3
+ describe Whois::Server do
4
+ describe ".load_json" do
5
+ it "loads a definition from a JSON file" do
6
+ expect(File).to receive(:read).with("tld.json").and_return(<<-JSON)
7
+ {
8
+ "ae.org": {
9
+ "host": "whois.centralnic.com"
10
+ },
11
+ "ar.com": {
12
+ "host": "whois.centralnic.com"
13
+ }
14
+ }
15
+ JSON
16
+ with_definitions do
17
+ described_class.load_json("tld.json")
18
+ expect(described_class.definitions(:tld)).to eq([
19
+ ["ae.org", "whois.centralnic.com", {}],
20
+ ["ar.com", "whois.centralnic.com", {}],
21
+ ])
22
+ end
23
+ end
24
+
25
+ it "convert option keys to Symbol" do
26
+ expect(File).to receive(:read).with("tld.json").and_return(<<-JSON)
27
+ {
28
+ "com": {
29
+ "host": "whois.crsnic.net",
30
+ "adapter": "verisign"
31
+ }
32
+ }
33
+ JSON
34
+ with_definitions do
35
+ described_class.load_json("tld.json")
36
+ expect(described_class.definitions(:tld)).to eq([
37
+ ["com", "whois.crsnic.net", adapter: "verisign"],
38
+ ])
39
+ end
40
+ end
41
+ end
42
+
43
+ describe ".definitions" do
44
+ it "returns the definitions array for given type" do
45
+ with_definitions do
46
+ Whois::Server.define(Whois::Server::TYPE_TLD, "foo", "whois.foo")
47
+ definition = described_class.definitions(Whois::Server::TYPE_TLD)
48
+ expect(definition).to be_a(Array)
49
+ expect(definition).to eq([["foo", "whois.foo", {}]])
50
+ end
51
+ end
52
+
53
+ it "raises ArgumentError when the type is invalid" do
54
+ with_definitions do
55
+ expect {
56
+ described_class.definitions(:foo)
57
+ }.to raise_error(ArgumentError)
58
+ end
59
+ end
60
+ end
61
+
62
+ describe ".define" do
63
+ it "adds a new definition with given arguments" do
64
+ with_definitions do
65
+ Whois::Server.define(Whois::Server::TYPE_TLD, "foo", "whois.foo")
66
+ expect(described_class.definitions(Whois::Server::TYPE_TLD)).to eq([["foo", "whois.foo", {}]])
67
+ end
68
+ end
69
+
70
+ it "accepts a hash of options" do
71
+ with_definitions do
72
+ Whois::Server.define(Whois::Server::TYPE_TLD, "foo", "whois.foo", foo: "bar")
73
+ expect(described_class.definitions(Whois::Server::TYPE_TLD)).to eq([["foo", "whois.foo", { :foo => "bar" }]])
74
+ end
75
+ end
76
+ end
77
+
78
+ describe ".factory" do
79
+ it "returns an adapter initialized with given arguments" do
80
+ server = Whois::Server.factory(:tld, "test", "whois.test")
81
+ expect(server.type).to eq(:tld)
82
+ expect(server.allocation).to eq("test")
83
+ expect(server.host).to eq("whois.test")
84
+ expect(server.options).to eq(Hash.new)
85
+ end
86
+
87
+ it "returns a standard adapter by default" do
88
+ server = Whois::Server.factory(:tld, "test", "whois.test")
89
+ expect(server).to be_a(Whois::Server::Adapters::Standard)
90
+ end
91
+
92
+ it "accepts an :adapter option as Class and returns an instance of given adapter" do
93
+ a = Class.new do
94
+ attr_reader :args
95
+ def initialize(*args)
96
+ @args = args
97
+ end
98
+ end
99
+ server = Whois::Server.factory(:tld, "test", "whois.test", :adapter => a)
100
+ expect(server).to be_a(a)
101
+ expect(server.args).to eq([:tld, "test", "whois.test", {}])
102
+ end
103
+
104
+ it "accepts an :adapter option as Symbol or String, load Class and returns an instance of given adapter" do
105
+ server = Whois::Server.factory(:tld, "test", "whois.test", :adapter => :none)
106
+ expect(server).to be_a(Whois::Server::Adapters::None)
107
+ server = Whois::Server.factory(:tld, "test", "whois.test", :adapter => "none")
108
+ expect(server).to be_a(Whois::Server::Adapters::None)
109
+ end
110
+
111
+ it "deletes the adapter option" do
112
+ server = Whois::Server.factory(:tld, "test", "whois.test", :adapter => Whois::Server::Adapters::None, :foo => "bar")
113
+ expect(server.options).to eq({ :foo => "bar" })
114
+ end
115
+ end
116
+
117
+ describe ".guess" do
118
+ it "recognizes tld" do
119
+ server = Whois::Server.guess(".com")
120
+ expect(server).to be_a(Whois::Server::Adapters::Base)
121
+ expect(server.type).to eq(Whois::Server::TYPE_TLD)
122
+ end
123
+
124
+ it "recognizes domain" do
125
+ server = Whois::Server.guess("example.com")
126
+ expect(server).to be_a(Whois::Server::Adapters::Base)
127
+ expect(server.type).to eq(Whois::Server::TYPE_TLD)
128
+ end
129
+
130
+ it "recognizes ipv4" do
131
+ server = Whois::Server.guess("127.0.0.1")
132
+ expect(server).to be_a(Whois::Server::Adapters::Base)
133
+ expect(server.type).to eq(Whois::Server::TYPE_IPV4)
134
+ end
135
+
136
+ it "recognizes ipv6" do
137
+ server = Whois::Server.guess("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
138
+ expect(server).to be_a(Whois::Server::Adapters::Base)
139
+ expect(server.type).to eq(Whois::Server::TYPE_IPV6)
140
+ end
141
+
142
+ it "recognizes ipv6 when zero groups" do
143
+ server = Whois::Server.guess("2002::1")
144
+ expect(server).to be_a(Whois::Server::Adapters::Base)
145
+ expect(server.type).to eq(Whois::Server::TYPE_IPV6)
146
+ end
147
+
148
+ it "recognizes asn16" do
149
+ server = Whois::Server.guess("AS23456")
150
+ expect(server).to be_a(Whois::Server::Adapters::Base)
151
+ expect(server.type).to eq(Whois::Server::TYPE_ASN16)
152
+ end
153
+
154
+ it "recognizes asn32" do
155
+ server = Whois::Server.guess("AS131072")
156
+ expect(server).to be_a(Whois::Server::Adapters::Base)
157
+ expect(server.type).to eq(Whois::Server::TYPE_ASN32)
158
+ end
159
+
160
+ it "recognizes email" do
161
+ expect {
162
+ Whois::Server.guess("email@example.org")
163
+ }.to raise_error(Whois::ServerNotSupported, /email/)
164
+ end
165
+
166
+ it "raises when unrecognized value" do
167
+ expect {
168
+ Whois::Server.guess("invalid")
169
+ }.to raise_error(Whois::ServerNotFound)
170
+ end
171
+
172
+
173
+ context "when the input is a tld" do
174
+ it "returns a IANA adapter" do
175
+ expect(Whois::Server.guess(".com")).to eq(Whois::Server.factory(:tld, ".", "whois.iana.org"))
176
+ end
177
+
178
+ it "returns a IANA adapter when the input is an idn" do
179
+ expect(Whois::Server.guess(".xn--fiqs8s")).to eq(Whois::Server.factory(:tld, ".", "whois.iana.org"))
180
+ end
181
+ end
182
+
183
+ context "when the input is a domain" do
184
+ it "lookups definitions and returns the adapter" do
185
+ with_definitions do
186
+ Whois::Server.define(:tld, "test", "whois.test")
187
+ expect(Whois::Server.guess("example.test")).to eq(Whois::Server.factory(:tld, "test", "whois.test"))
188
+ end
189
+ end
190
+
191
+ it "doesn't consider the dot as a regexp pattern" do
192
+ with_definitions do
193
+ Whois::Server.define(:tld, "no.com", "whois.no.com")
194
+ Whois::Server.define(:tld, "com", "whois.com")
195
+ expect(Whois::Server.guess("antoniocangiano.com")).to eq(Whois::Server.factory(:tld, "com", "whois.com"))
196
+ end
197
+ end
198
+
199
+ it "returns the closer definition" do
200
+ with_definitions do
201
+ Whois::Server.define(:tld, "com", com = "whois.com")
202
+ Whois::Server.define(:tld, "com.foo", comfoo = "whois.com.foo")
203
+ Whois::Server.define(:tld, "foo.com", foocom = "whois.foo.com")
204
+
205
+ expect(Whois::Server.guess("example.com").host).to eq(com)
206
+ expect(Whois::Server.guess("example.com.foo").host).to eq(comfoo)
207
+ expect(Whois::Server.guess("example.foo.com").host).to eq(foocom)
208
+ end
209
+ end
210
+ end
211
+
212
+ context "when the input is an asn16" do
213
+ it "lookups definitions and returns the adapter" do
214
+ with_definitions do
215
+ Whois::Server.define(:asn16, "0 65535", "whois.test")
216
+ expect(Whois::Server.guess("AS65535")).to eq(Whois::Server.factory(:asn16, "0 65535", "whois.test"))
217
+ end
218
+ end
219
+
220
+ it "raises if definition is not found" do
221
+ with_definitions do
222
+ Whois::Server.define(:asn16, "0 60000", "whois.test")
223
+ expect {
224
+ Whois::Server.guess("AS65535")
225
+ }.to raise_error(Whois::AllocationUnknown)
226
+ end
227
+ end
228
+ end
229
+
230
+ context "when the input is an asn32" do
231
+ it "lookups definitions and returns the adapter" do
232
+ with_definitions do
233
+ Whois::Server.define(:asn32, "65536 394239", "whois.test")
234
+ expect(Whois::Server.guess("AS65536")).to eq(Whois::Server.factory(:asn32, "65536 394239", "whois.test"))
235
+ end
236
+ end
237
+
238
+ it "raises if definition is not found" do
239
+ with_definitions do
240
+ Whois::Server.define(:asn32, "65536 131071", "whois.test")
241
+ expect {
242
+ Whois::Server.guess("AS200000")
243
+ }.to raise_error(Whois::AllocationUnknown)
244
+ end
245
+ end
246
+ end
247
+
248
+ context "when the input is a ipv4" do
249
+ it "lookups definitions and returns the adapter" do
250
+ with_definitions do
251
+ Whois::Server.define(:ipv4, "192.168.1.0/10", "whois.test")
252
+ expect(Whois::Server.find_for_ip("192.168.1.1")).to eq(Whois::Server.factory(:ipv4, "192.168.1.0/10", "whois.test"))
253
+ end
254
+ end
255
+
256
+ it "raises if definition is not found" do
257
+ with_definitions do
258
+ Whois::Server.define(:ipv4, "192.168.1.0/10", "whois.test")
259
+ expect {
260
+ Whois::Server.guess("192.192.0.1")
261
+ }.to raise_error(Whois::AllocationUnknown)
262
+ end
263
+ end
264
+ end
265
+
266
+ context "when the input is a ipv6" do
267
+ it "lookups definitions and returns the adapter" do
268
+ with_definitions do
269
+ Whois::Server.define(:ipv6, "2001:0200::/23", "whois.test")
270
+ expect(Whois::Server.guess("2001:0200::1")).to eq(Whois::Server.factory(:ipv6, "2001:0200::/23", "whois.test"))
271
+ end
272
+ end
273
+
274
+ it "raises if definition is not found" do
275
+ with_definitions do
276
+ Whois::Server.define(:ipv6, "::1", "whois.test")
277
+ expect {
278
+ Whois::Server.guess("2002:0300::1")
279
+ }.to raise_error(Whois::AllocationUnknown)
280
+ end
281
+ end
282
+
283
+ it "recognizes ipv4 compatibility mode" do
284
+ with_definitions do
285
+ Whois::Server.define(:ipv6, "::192.168.1.1", "whois.test")
286
+ expect(Whois::Server.guess("::192.168.1.1")).to eq(Whois::Server.factory(:ipv6, "::192.168.1.1", "whois.test"))
287
+ end
288
+ end
289
+
290
+ it "rescues IPAddr ArgumentError", issue: "weppos/whois#174" do
291
+ with_definitions do
292
+ expect {
293
+ Whois::Server.guess("f53")
294
+ }.to raise_error(Whois::AllocationUnknown)
295
+ end
296
+ end
297
+ end
298
+ end
299
+
300
+ end