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,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Whois::WebInterfaceError do
4
+
5
+ describe "#initialize" do
6
+ it "sets the URL" do
7
+ expect(described_class.new("http://example.com").url).to eq("http://example.com")
8
+ end
9
+
10
+ it "requires the URL argument" do
11
+ expect {
12
+ described_class.new
13
+ }.to raise_error(ArgumentError)
14
+ end
15
+ end
16
+
17
+ describe "#message" do
18
+ it "interpolates the URL" do
19
+ expect(described_class.new("http://example.com").message).to match(%r{http://example.com})
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Whois::Record::Part do
4
+
5
+ describe "#initialize" do
6
+ it "accepts an empty value" do
7
+ expect {
8
+ instance = described_class.new
9
+ expect(instance.body).to be_nil
10
+ }.to_not raise_error
11
+ end
12
+
13
+ it "accepts an empty hash" do
14
+ expect {
15
+ instance = described_class.new({})
16
+ expect(instance.body).to be_nil
17
+ }.to_not raise_error
18
+ end
19
+
20
+ it "initializes a new instance from given hash" do
21
+ instance = described_class.new(body: "This is a WHOIS record.", host: "whois.example.test")
22
+
23
+ expect(instance.body).to eq("This is a WHOIS record.")
24
+ expect(instance.host).to eq("whois.example.test")
25
+ end
26
+
27
+ it "initializes a new instance from given block" do
28
+ instance = described_class.new do |c|
29
+ c.body = "This is a WHOIS record."
30
+ c.host = "whois.example.test"
31
+ end
32
+
33
+ expect(instance.body).to eq("This is a WHOIS record.")
34
+ expect(instance.host).to eq("whois.example.test")
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,158 @@
1
+ require 'spec_helper'
2
+
3
+ describe Whois::Record do
4
+
5
+ subject { described_class.new(server, parts) }
6
+
7
+ let(:server) {
8
+ Whois::Server.factory(:tld, ".foo", "whois.example.test")
9
+ }
10
+ let(:parts) {[
11
+ Whois::Record::Part.new(body: "This is a record from foo.", host: "foo.example.test"),
12
+ Whois::Record::Part.new(body: "This is a record from bar.", host: "bar.example.test")
13
+ ]}
14
+ let(:content) {
15
+ parts.map(&:body).join("\n")
16
+ }
17
+
18
+
19
+ describe "#initialize" do
20
+ it "requires a server and parts" do
21
+ expect { described_class.new }.to raise_error(ArgumentError)
22
+ expect { described_class.new(server) }.to raise_error(ArgumentError)
23
+ expect { described_class.new(server, parts) }.to_not raise_error
24
+ end
25
+
26
+ it "sets server and parts from arguments" do
27
+ instance = described_class.new(server, parts)
28
+ expect(instance.server).to be(server)
29
+ expect(instance.parts).to be(parts)
30
+
31
+ instance = described_class.new(nil, nil)
32
+ expect(instance.server).to be_nil
33
+ expect(instance.parts).to be_nil
34
+ end
35
+ end
36
+
37
+
38
+ describe "#to_s" do
39
+ it "delegates to #content" do
40
+ expect(described_class.new(nil, [parts[0]]).to_s).to eq(parts[0].body)
41
+ expect(described_class.new(nil, parts).to_s).to eq(parts.map(&:body).join("\n"))
42
+ expect(described_class.new(nil, []).to_s).to eq("")
43
+ end
44
+ end
45
+
46
+ describe "#inspect" do
47
+ it "inspects the record content" do
48
+ expect(described_class.new(nil, [parts[0]]).inspect).to eq(parts[0].body.inspect)
49
+ end
50
+
51
+ it "joins multiple parts" do
52
+ expect(described_class.new(nil, parts).inspect).to eq(parts.map(&:body).join("\n").inspect)
53
+ end
54
+
55
+ it "joins empty parts" do
56
+ expect(described_class.new(nil, []).inspect).to eq("".inspect)
57
+ end
58
+ end
59
+
60
+ describe "#==" do
61
+ it "returns true when other is the same instance" do
62
+ one = two = described_class.new(server, parts)
63
+
64
+ expect(one == two).to be_truthy
65
+ expect(one.eql?(two)).to be_truthy
66
+ end
67
+
68
+ it "returns true when other has same class and has the same parts" do
69
+ one, two = described_class.new(server, parts), described_class.new(server, parts)
70
+
71
+ expect(one == two).to be_truthy
72
+ expect(one.eql?(two)).to be_truthy
73
+ end
74
+
75
+ it "returns true when other has descendant class and has the same parts" do
76
+ subklass = Class.new(described_class)
77
+ one, two = described_class.new(server, parts), subklass.new(server, parts)
78
+
79
+ expect(one == two).to be_truthy
80
+ expect(one.eql?(two)).to be_truthy
81
+ end
82
+
83
+ it "returns true when other has same class and has equal parts" do
84
+ one, two = described_class.new(server, parts), described_class.new(server, parts.dup)
85
+
86
+ expect(one == two).to be_truthy
87
+ expect(one.eql?(two)).to be_truthy
88
+ end
89
+
90
+ it "returns true when other has same class, different server and the same parts" do
91
+ one, two = described_class.new(server, parts), described_class.new(nil, parts)
92
+
93
+ expect(one == two).to be_truthy
94
+ expect(one.eql?(two)).to be_truthy
95
+ end
96
+
97
+ it "returns false when other has different class and has the same parts" do
98
+ one, two = described_class.new(server, parts), Struct.new(:server, :parts).new(server, parts)
99
+
100
+ expect(one == two).to be_falsey
101
+ expect(one.eql?(two)).to be_falsey
102
+ end
103
+
104
+ it "returns false when other has different parts" do
105
+ one, two = described_class.new(server, parts), described_class.new(server, [])
106
+
107
+ expect(one == two).to be_falsey
108
+ expect(one.eql?(two)).to be_falsey
109
+ end
110
+
111
+ it "returns false when other is string and has the same content" do
112
+ one, two = described_class.new(server, parts), described_class.new(server, parts).to_s
113
+
114
+ expect(one == two).to be_falsey
115
+ expect(one.eql?(two)).to be_falsey
116
+ end
117
+
118
+ it "returns false when other is string and has different content" do
119
+ one, two = described_class.new(server, parts), "different"
120
+
121
+ expect(one == two).to be_falsey
122
+ expect(one.eql?(two)).to be_falsey
123
+ end
124
+ end
125
+
126
+
127
+ describe "#match" do
128
+ it "delegates to content" do
129
+ expect(subject.match(/record/)).to be_a(MatchData)
130
+ expect(subject.match(/record/)[0]).to eq("record")
131
+
132
+ expect(subject.match(/nomatch/)).to be_nil
133
+ end
134
+ end
135
+
136
+ describe "#match?" do
137
+ it "calls match and checks for match" do
138
+ expect(subject.match?(/record/)).to eq(true)
139
+ expect(subject.match?(/nomatch/)).to eq(false)
140
+ end
141
+ end
142
+
143
+
144
+ describe "#content" do
145
+ it "returns the part body" do
146
+ expect(described_class.new(nil, [parts[0]]).content).to eq(parts[0].body)
147
+ end
148
+
149
+ it "joins multiple parts" do
150
+ expect(described_class.new(nil, parts).content).to eq(parts.map(&:body).join("\n"))
151
+ end
152
+
153
+ it "returns an empty string when no parts" do
154
+ expect(described_class.new(nil, []).content).to eq("")
155
+ end
156
+ end
157
+
158
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe Whois::Server::Adapters::Afilias do
4
+
5
+ let(:definition) { [:tld, ".test", "whois.afilias-grs.info", {}] }
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.afilias-grs.info", 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.afilias-grs.info")])
20
+ end
21
+ end
22
+
23
+ context "with referral" do
24
+ it "follows all referrals" do
25
+ referral = File.read(fixture("referrals/afilias.bz.txt"))
26
+ response = "Match for example.test."
27
+ expected = referral + "\n" + response
28
+ expect(server.query_handler).to receive(:call).with("example.test", "whois.afilias-grs.info", 43).and_return(referral)
29
+ expect(server.query_handler).to receive(:call).with("example.test", "whois.belizenic.bz", 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.afilias-grs.info"), Whois::Record::Part.new(body: response, host: "whois.belizenic.bz")])
35
+ end
36
+
37
+ it "ignores referral if options[:referral] is false" do
38
+ referral = File.read(fixture("referrals/afilias.bz.txt"))
39
+ server.options[:referral] = false
40
+ expect(server.query_handler).to receive(:call).with("example.test", "whois.afilias-grs.info", 43).and_return(referral)
41
+ expect(server.query_handler).to receive(:call).with("example.test", "whois.belizenic.bz", 43).never
42
+
43
+ record = server.lookup("example.test")
44
+ expect(record.parts.size).to eq(1)
45
+ end
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ describe Whois::Server::Adapters::Arin do
4
+
5
+ let(:definition) { [:ipv4, "0.0.0.0/1", "whois.arin.net"] }
6
+ let(:server) { described_class.new(*definition) }
7
+
8
+ describe "#lookup" do
9
+ context "without referral" do
10
+ it "returns the WHOIS record" do
11
+ response = "Whois Response"
12
+ expected = response
13
+ expect(server.query_handler).to receive(:call).with("n + 0.0.0.0", "whois.arin.net", 43).and_return(response)
14
+ record = server.lookup("0.0.0.0")
15
+ expect(record.to_s).to eq(expected)
16
+ expect(record.parts.size).to eq(1)
17
+ expect(record.parts).to eq([Whois::Record::Part.new(body: response, host: "whois.arin.net")])
18
+ end
19
+ end
20
+
21
+ context "with referral" do
22
+ it "follows whois:// referrals" do
23
+ referral = File.read(fixture("referrals/arin_referral_whois.txt"))
24
+ response = "Whois Response"
25
+ expected = referral + "\n" + response
26
+ expect(server.query_handler).to receive(:call).with("n + 0.0.0.0", "whois.arin.net", 43).and_return(referral)
27
+ expect(server.query_handler).to receive(:call).with("0.0.0.0", "whois.ripe.net", 43).and_return(response)
28
+
29
+ record = server.lookup("0.0.0.0")
30
+ expect(record.to_s).to eq(expected)
31
+ expect(record.parts.size).to eq(2)
32
+ expect(record.parts).to eq([Whois::Record::Part.new(body: referral, host: "whois.arin.net"),
33
+ Whois::Record::Part.new(body: response, host: "whois.ripe.net")])
34
+ end
35
+
36
+ it "follows rwhois:// referrals" do
37
+ referral = File.read(fixture("referrals/arin_referral_rwhois.txt"))
38
+ response = "Whois Response"
39
+ expected = referral + "\n" + response
40
+ expect(server.query_handler).to receive(:call).with("n + 0.0.0.0", "whois.arin.net", 43).and_return(referral)
41
+ expect(server.query_handler).to receive(:call).with("0.0.0.0", "rwhois.servernap.net", 4321).and_return(response)
42
+
43
+ record = server.lookup("0.0.0.0")
44
+ expect(record.to_s).to eq(expected)
45
+ expect(record.parts.size).to eq(2)
46
+ expect(record.parts).to eq([Whois::Record::Part.new(body: referral, host: "whois.arin.net"),
47
+ Whois::Record::Part.new(body: response, host: "rwhois.servernap.net")])
48
+ end
49
+
50
+ it "ignores referral if options[:referral] is false" do
51
+ referral = File.read(fixture("referrals/arin_referral_whois.txt"))
52
+ server.options[:referral] = false
53
+ expect(server.query_handler).to receive(:call).with("n + 0.0.0.0", "whois.arin.net", 43).and_return(referral)
54
+ expect(server.query_handler).to receive(:call).with("0.0.0.0", "whois.ripe.net", 43).never
55
+
56
+ record = server.lookup("0.0.0.0")
57
+ expect(record.parts.size).to eq(1)
58
+ end
59
+
60
+ it "ignores referral (gracefully) if missing" do
61
+ referral = File.read(fixture("referrals/arin_referral_missing.txt"))
62
+ expect(server.query_handler).to receive(:call).with("n + 0.0.0.0", "whois.arin.net", 43).and_return(referral)
63
+ expect(server.query_handler).to receive(:call).never
64
+
65
+ record = server.lookup("0.0.0.0")
66
+ expect(record.parts.size).to eq(1)
67
+ end
68
+
69
+ it "folows referrals without ports" do
70
+ referral = File.read(fixture("referrals/arin_referral_apnic.txt"))
71
+ response = "Whois Response"
72
+ expect(server.query_handler).to receive(:call).with("n + 0.0.0.0", "whois.arin.net", 43).and_return(referral)
73
+ expect(server.query_handler).to receive(:call).with("0.0.0.0", "whois.apnic.net", 43).and_return(response)
74
+
75
+ record = server.lookup("0.0.0.0")
76
+ expect(record.parts.size).to eq(2)
77
+ expect(record.parts).to eq([Whois::Record::Part.new(body: referral, host: "whois.arin.net"),
78
+ Whois::Record::Part.new(body: response, host: "whois.apnic.net")])
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'whois/server/adapters/arin'
3
+
4
+ describe Whois::Server::Adapters::Arpa do
5
+
6
+ let(:definition) { [:tld, ".in-addr.arpa", nil, {}] }
7
+
8
+ describe "#lookup" do
9
+ it "returns the WHOIS record" do
10
+ response = "Whois Response"
11
+ server = described_class.new(*definition)
12
+ expect(Whois::Server::Adapters::Arin.query_handler).to receive(:call).with("n + 229.128.in-addr.arpa", "whois.arin.net", 43).and_return(response)
13
+
14
+ record = server.lookup("229.128.in-addr.arpa")
15
+ expect(record.to_s).to eq(response)
16
+ expect(record.parts).to eq([Whois::Record::Part.new(body: response, host: "whois.arin.net")])
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,150 @@
1
+ require 'spec_helper'
2
+
3
+ describe Whois::Server::Adapters::Base do
4
+
5
+ let(:definition) { [:tld, ".test", "whois.test", { foo: "bar" }] }
6
+
7
+
8
+ describe "#initialize" do
9
+ it "requires type, allocation, and host parameters" do
10
+ expect { described_class.new(:tld) }.to raise_error(ArgumentError)
11
+ expect { described_class.new(:tld, ".test") }.to raise_error(ArgumentError)
12
+ expect { described_class.new(:tld, ".test", "whois.test") }.to_not raise_error
13
+ end
14
+
15
+ it "accepts an options parameter" do
16
+ expect { described_class.new(:tld, ".test", "whois.test", { foo: "bar" }) }.to_not raise_error
17
+ end
18
+
19
+ it "sets instance variables from arguments" do
20
+ instance = described_class.new(:tld, ".test", "whois.test", { foo: "bar" })
21
+ expect(instance.type).to eq(:tld)
22
+ expect(instance.allocation).to eq(".test")
23
+ expect(instance.host).to eq("whois.test")
24
+ expect(instance.options).to eq({ foo: "bar" })
25
+ end
26
+
27
+ it "defaults options to an empty hash" do
28
+ instance = described_class.new(:tld, ".test", "whois.test")
29
+ expect(instance.options).to eq({})
30
+ end
31
+ end
32
+
33
+ describe "#==" do
34
+ it "returns true when other is the same instance" do
35
+ one = two = described_class.new(*definition)
36
+
37
+ expect(one == two).to be_truthy
38
+ expect(one.eql?(two)).to be_truthy
39
+ end
40
+
41
+ it "returns true when other has same class and has the same attributes" do
42
+ one, two = described_class.new(*definition), described_class.new(*definition)
43
+
44
+ expect(one == two).to be_truthy
45
+ expect(one.eql?(two)).to be_truthy
46
+ end
47
+
48
+ it "returns true when other has descendant class and has the same attributes" do
49
+ subklass = Class.new(described_class)
50
+ one, two = described_class.new(*definition), subklass.new(*definition)
51
+
52
+ expect(one == two).to be_truthy
53
+ expect(one.eql?(two)).to be_truthy
54
+ end
55
+
56
+ it "returns false when other has different class and has the same attributes" do
57
+ one, two = described_class.new(*definition), Struct.new(:type, :allocation, :host, :options).new(*definition)
58
+
59
+ expect(one == two).to be_falsey
60
+ expect(one.eql?(two)).to be_falsey
61
+ end
62
+
63
+ it "returns false when other has different attributes" do
64
+ one, two = described_class.new(:tld, ".test", "whois.test"), described_class.new(:tld, ".cool", "whois.test")
65
+
66
+ expect(one == two).to be_falsey
67
+ expect(one.eql?(two)).to be_falsey
68
+ end
69
+
70
+ it "returns false when other has different options" do
71
+ one, two = described_class.new(:tld, ".test", "whois.test"), described_class.new(:tld, ".test", "whois.test", { foo: "bar" })
72
+
73
+ expect(one == two).to be_falsey
74
+ expect(one.eql?(two)).to be_falsey
75
+ end
76
+ end
77
+
78
+
79
+ describe "#configure" do
80
+ it "merges settings with current options" do
81
+ a = described_class.new(:tld, ".test", "whois.test", { :hello => "world" })
82
+ a.configure(foo: "bar")
83
+ expect(a.options).to eq({ :hello => "world", foo: "bar" })
84
+ end
85
+
86
+ it "gives higher priority to settings argument" do
87
+ a = described_class.new(:tld, ".test", "whois.test", { foo: "bar" })
88
+ expect(a.options).to eq({ foo: "bar" })
89
+ a.configure(:foo => "baz")
90
+ expect(a.options).to eq({ :foo => "baz" })
91
+ end
92
+
93
+ it "overrides @host if :host option exists" do
94
+ a = described_class.new(:tld, ".test", "whois.test", { :hello => "world" })
95
+ a.configure(foo: "bar", host: "whois.example.com")
96
+ expect(a.options).to eq({ :hello => "world", foo: "bar", host: "whois.example.com" })
97
+ expect(a.host).to eq("whois.example.com")
98
+ end
99
+ end
100
+
101
+
102
+ describe "#lookup" do
103
+ it "raises NotImplementedError" do
104
+ expect {
105
+ described_class.new(*definition).lookup("example.test")
106
+ }.to raise_error(NotImplementedError)
107
+ end
108
+ end
109
+
110
+ describe "#request" do
111
+ it "is an abstract method" do
112
+ expect {
113
+ described_class.new(*definition).request("example.test")
114
+ }.to raise_error(NotImplementedError)
115
+ end
116
+ end
117
+
118
+ describe "#query_the_socket" do
119
+ context "without :bind_host or :bind_port options" do
120
+ let(:server) { described_class.new(:tld, ".test", "whois.test", {}) }
121
+
122
+ it "does not bind the WHOIS query" do
123
+ expect(described_class.query_handler).to receive(:call).with("example.test", "whois.test", 43)
124
+
125
+ server.send(:query_the_socket, "example.test", "whois.test", 43)
126
+ end
127
+ end
128
+
129
+ context "with :bind_host and :bind_port options" do
130
+ let(:server) { described_class.new(:tld, ".test", "whois.test", { :bind_host => "192.168.1.1", :bind_port => 3000 }) }
131
+
132
+ it "binds the WHOIS query to given host and port" do
133
+ expect(described_class.query_handler).to receive(:call).with("example.test", "whois.test", 43, "192.168.1.1", 3000)
134
+
135
+ server.send(:query_the_socket, "example.test", "whois.test", 43)
136
+ end
137
+ end
138
+
139
+ context "with :bind_port and without :bind_host options" do
140
+ let(:server) { described_class.new(:tld, ".test", "whois.test", { :bind_port => 3000 }) }
141
+
142
+ it "binds the WHOIS query to given port and defaults host" do
143
+ expect(described_class.query_handler).to receive(:call).with("example.test", "whois.test", 43, described_class::DEFAULT_BIND_HOST, 3000)
144
+
145
+ server.send(:query_the_socket, "example.test", "whois.test", 43)
146
+ end
147
+ end
148
+ end
149
+
150
+ end