whois 5.0.1 → 5.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +26 -0
- data/.rubocop_opinionated.yml +157 -0
- data/.rubocop_todo.yml +242 -0
- data/.simplecov +2 -0
- data/.tool-versions +1 -0
- data/CHANGELOG.md +68 -53
- data/Gemfile +5 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/Rakefile +12 -17
- data/bin/console +1 -0
- data/bin/whoisrb +3 -2
- data/data/ipv4.json +1 -3
- data/data/tld.json +2 -90
- data/lib/whois.rb +12 -10
- data/lib/whois/client.rb +4 -2
- data/lib/whois/errors.rb +4 -2
- data/lib/whois/record.rb +3 -1
- data/lib/whois/record/part.rb +4 -3
- data/lib/whois/server.rb +26 -21
- data/lib/whois/server/adapters/afilias.rb +4 -1
- data/lib/whois/server/adapters/arin.rb +5 -2
- data/lib/whois/server/adapters/arpa.rb +22 -19
- data/lib/whois/server/adapters/base.rb +4 -4
- data/lib/whois/server/adapters/formatted.rb +4 -2
- data/lib/whois/server/adapters/none.rb +3 -1
- data/lib/whois/server/adapters/not_implemented.rb +3 -1
- data/lib/whois/server/adapters/standard.rb +4 -2
- data/lib/whois/server/adapters/verisign.rb +4 -1
- data/lib/whois/server/adapters/web.rb +3 -1
- data/lib/whois/server/socket_handler.rb +8 -6
- data/lib/whois/version.rb +4 -2
- data/spec/integration/whois_spec.rb +6 -6
- data/spec/spec_helper.rb +4 -2
- data/spec/support/helpers/connectivity_helper.rb +2 -0
- data/spec/support/helpers/spec_helper.rb +2 -0
- data/spec/whois/client_spec.rb +6 -7
- data/spec/whois/record/part_spec.rb +4 -4
- data/spec/whois/record_spec.rb +9 -7
- data/spec/whois/server/adapters/afilias_spec.rb +3 -3
- data/spec/whois/server/adapters/arin_spec.rb +7 -8
- data/spec/whois/server/adapters/arpa_spec.rb +2 -2
- data/spec/whois/server/adapters/base_spec.rb +13 -13
- data/spec/whois/server/adapters/formatted_spec.rb +7 -7
- data/spec/whois/server/adapters/none_spec.rb +2 -2
- data/spec/whois/server/adapters/not_implemented_spec.rb +3 -3
- data/spec/whois/server/adapters/standard_spec.rb +5 -5
- data/spec/whois/server/adapters/verisign_spec.rb +3 -3
- data/spec/whois/server/adapters/web_spec.rb +3 -3
- data/spec/whois/server/socket_handler_spec.rb +7 -5
- data/spec/whois/server_spec.rb +31 -29
- data/spec/whois/{errors_spec.rb → web_interface_error_spec.rb} +4 -4
- data/spec/whois/whois_spec.rb +3 -3
- metadata +11 -8
- data/tasks/spec.rake +0 -199
data/spec/whois/record_spec.rb
CHANGED
@@ -1,16 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Whois::Record do
|
4
|
-
|
5
6
|
subject { described_class.new(server, parts) }
|
6
7
|
|
7
8
|
let(:server) {
|
8
9
|
Whois::Server.factory(:tld, ".foo", "whois.example.test")
|
9
10
|
}
|
10
|
-
let(:parts) {
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
let(:parts) {
|
12
|
+
[
|
13
|
+
Whois::Record::Part.new(body: "This is a record from foo.", host: "foo.example.test"),
|
14
|
+
Whois::Record::Part.new(body: "This is a record from bar.", host: "bar.example.test"),
|
15
|
+
]
|
16
|
+
}
|
14
17
|
let(:content) {
|
15
18
|
parts.map(&:body).join("\n")
|
16
19
|
}
|
@@ -20,7 +23,7 @@ describe Whois::Record do
|
|
20
23
|
it "requires a server and parts" do
|
21
24
|
expect { described_class.new }.to raise_error(ArgumentError)
|
22
25
|
expect { described_class.new(server) }.to raise_error(ArgumentError)
|
23
|
-
expect { described_class.new(server, parts) }.
|
26
|
+
expect { described_class.new(server, parts) }.not_to raise_error
|
24
27
|
end
|
25
28
|
|
26
29
|
it "sets server and parts from arguments" do
|
@@ -154,5 +157,4 @@ describe Whois::Record do
|
|
154
157
|
expect(described_class.new(nil, []).content).to eq("")
|
155
158
|
end
|
156
159
|
end
|
157
|
-
|
158
160
|
end
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Whois::Server::Adapters::Afilias do
|
4
|
-
|
5
6
|
let(:definition) { [:tld, ".test", "whois.afilias-grs.info", {}] }
|
6
7
|
let(:server) { described_class.new(*definition) }
|
7
8
|
|
@@ -24,7 +25,7 @@ describe Whois::Server::Adapters::Afilias do
|
|
24
25
|
it "follows all referrals" do
|
25
26
|
referral = File.read(fixture("referrals/afilias.bz.txt"))
|
26
27
|
response = "Match for example.test."
|
27
|
-
expected = referral
|
28
|
+
expected = "#{referral}\n#{response}"
|
28
29
|
expect(server.query_handler).to receive(:call).with("example.test", "whois.afilias-grs.info", 43).and_return(referral)
|
29
30
|
expect(server.query_handler).to receive(:call).with("example.test", "whois.belizenic.bz", 43).and_return(response)
|
30
31
|
|
@@ -45,5 +46,4 @@ describe Whois::Server::Adapters::Afilias do
|
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
48
|
-
|
49
49
|
end
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Whois::Server::Adapters::Arin do
|
4
|
-
|
5
6
|
let(:definition) { [:ipv4, "0.0.0.0/1", "whois.arin.net"] }
|
6
7
|
let(:server) { described_class.new(*definition) }
|
7
8
|
|
@@ -22,7 +23,7 @@ describe Whois::Server::Adapters::Arin do
|
|
22
23
|
it "follows whois:// referrals" do
|
23
24
|
referral = File.read(fixture("referrals/arin_referral_whois.txt"))
|
24
25
|
response = "Whois Response"
|
25
|
-
expected = referral
|
26
|
+
expected = "#{referral}\n#{response}"
|
26
27
|
expect(server.query_handler).to receive(:call).with("n + 0.0.0.0", "whois.arin.net", 43).and_return(referral)
|
27
28
|
expect(server.query_handler).to receive(:call).with("0.0.0.0", "whois.ripe.net", 43).and_return(response)
|
28
29
|
|
@@ -30,13 +31,13 @@ describe Whois::Server::Adapters::Arin do
|
|
30
31
|
expect(record.to_s).to eq(expected)
|
31
32
|
expect(record.parts.size).to eq(2)
|
32
33
|
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
|
+
Whois::Record::Part.new(body: response, host: "whois.ripe.net"),])
|
34
35
|
end
|
35
36
|
|
36
37
|
it "follows rwhois:// referrals" do
|
37
38
|
referral = File.read(fixture("referrals/arin_referral_rwhois.txt"))
|
38
39
|
response = "Whois Response"
|
39
|
-
expected = referral
|
40
|
+
expected = "#{referral}\n#{response}"
|
40
41
|
expect(server.query_handler).to receive(:call).with("n + 0.0.0.0", "whois.arin.net", 43).and_return(referral)
|
41
42
|
expect(server.query_handler).to receive(:call).with("0.0.0.0", "rwhois.servernap.net", 4321).and_return(response)
|
42
43
|
|
@@ -44,7 +45,7 @@ describe Whois::Server::Adapters::Arin do
|
|
44
45
|
expect(record.to_s).to eq(expected)
|
45
46
|
expect(record.parts.size).to eq(2)
|
46
47
|
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
|
+
Whois::Record::Part.new(body: response, host: "rwhois.servernap.net"),])
|
48
49
|
end
|
49
50
|
|
50
51
|
it "ignores referral if options[:referral] is false" do
|
@@ -75,10 +76,8 @@ describe Whois::Server::Adapters::Arin do
|
|
75
76
|
record = server.lookup("0.0.0.0")
|
76
77
|
expect(record.parts.size).to eq(2)
|
77
78
|
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
|
+
Whois::Record::Part.new(body: response, host: "whois.apnic.net"),])
|
79
80
|
end
|
80
81
|
end
|
81
|
-
|
82
82
|
end
|
83
|
-
|
84
83
|
end
|
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'whois/server/adapters/arin'
|
3
5
|
|
4
6
|
describe Whois::Server::Adapters::Arpa do
|
5
|
-
|
6
7
|
let(:definition) { [:tld, ".in-addr.arpa", nil, {}] }
|
7
8
|
|
8
9
|
describe "#lookup" do
|
@@ -16,5 +17,4 @@ describe Whois::Server::Adapters::Arpa do
|
|
16
17
|
expect(record.parts).to eq([Whois::Record::Part.new(body: response, host: "whois.arin.net")])
|
17
18
|
end
|
18
19
|
end
|
19
|
-
|
20
20
|
end
|
@@ -1,19 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Whois::Server::Adapters::Base do
|
4
|
-
|
5
|
-
let(:definition) { [:tld, ".test", "whois.test", { foo: "bar" }] }
|
6
|
+
let(:definition) { [:tld, ".test", "whois.test", { foo: "bar" }] }
|
6
7
|
|
7
8
|
|
8
9
|
describe "#initialize" do
|
9
10
|
it "requires type, allocation, and host parameters" do
|
10
11
|
expect { described_class.new(:tld) }.to raise_error(ArgumentError)
|
11
12
|
expect { described_class.new(:tld, ".test") }.to raise_error(ArgumentError)
|
12
|
-
expect { described_class.new(:tld, ".test", "whois.test") }.
|
13
|
+
expect { described_class.new(:tld, ".test", "whois.test") }.not_to raise_error
|
13
14
|
end
|
14
15
|
|
15
16
|
it "accepts an options parameter" do
|
16
|
-
expect { described_class.new(:tld, ".test", "whois.test", { foo: "bar" }) }.
|
17
|
+
expect { described_class.new(:tld, ".test", "whois.test", { foo: "bar" }) }.not_to raise_error
|
17
18
|
end
|
18
19
|
|
19
20
|
it "sets instance variables from arguments" do
|
@@ -78,22 +79,22 @@ describe Whois::Server::Adapters::Base do
|
|
78
79
|
|
79
80
|
describe "#configure" do
|
80
81
|
it "merges settings with current options" do
|
81
|
-
a = described_class.new(:tld, ".test", "whois.test", { :
|
82
|
+
a = described_class.new(:tld, ".test", "whois.test", { hello: "world" })
|
82
83
|
a.configure(foo: "bar")
|
83
|
-
expect(a.options).to eq({ :
|
84
|
+
expect(a.options).to eq({ hello: "world", foo: "bar" })
|
84
85
|
end
|
85
86
|
|
86
87
|
it "gives higher priority to settings argument" do
|
87
88
|
a = described_class.new(:tld, ".test", "whois.test", { foo: "bar" })
|
88
89
|
expect(a.options).to eq({ foo: "bar" })
|
89
|
-
a.configure(:
|
90
|
-
expect(a.options).to eq({ :
|
90
|
+
a.configure(foo: "baz")
|
91
|
+
expect(a.options).to eq({ foo: "baz" })
|
91
92
|
end
|
92
93
|
|
93
94
|
it "overrides @host if :host option exists" do
|
94
|
-
a = described_class.new(:tld, ".test", "whois.test", { :
|
95
|
+
a = described_class.new(:tld, ".test", "whois.test", { hello: "world" })
|
95
96
|
a.configure(foo: "bar", host: "whois.example.com")
|
96
|
-
expect(a.options).to eq({ :
|
97
|
+
expect(a.options).to eq({ hello: "world", foo: "bar", host: "whois.example.com" })
|
97
98
|
expect(a.host).to eq("whois.example.com")
|
98
99
|
end
|
99
100
|
end
|
@@ -127,7 +128,7 @@ describe Whois::Server::Adapters::Base do
|
|
127
128
|
end
|
128
129
|
|
129
130
|
context "with :bind_host and :bind_port options" do
|
130
|
-
let(:server) { described_class.new(:tld, ".test", "whois.test", { :
|
131
|
+
let(:server) { described_class.new(:tld, ".test", "whois.test", { bind_host: "192.168.1.1", bind_port: 3000 }) }
|
131
132
|
|
132
133
|
it "binds the WHOIS query to given host and port" do
|
133
134
|
expect(described_class.query_handler).to receive(:call).with("example.test", "whois.test", 43, "192.168.1.1", 3000)
|
@@ -137,7 +138,7 @@ describe Whois::Server::Adapters::Base do
|
|
137
138
|
end
|
138
139
|
|
139
140
|
context "with :bind_port and without :bind_host options" do
|
140
|
-
let(:server) { described_class.new(:tld, ".test", "whois.test", { :
|
141
|
+
let(:server) { described_class.new(:tld, ".test", "whois.test", { bind_port: 3000 }) }
|
141
142
|
|
142
143
|
it "binds the WHOIS query to given port and defaults host" do
|
143
144
|
expect(described_class.query_handler).to receive(:call).with("example.test", "whois.test", 43, described_class::DEFAULT_BIND_HOST, 3000)
|
@@ -146,5 +147,4 @@ describe Whois::Server::Adapters::Base do
|
|
146
147
|
end
|
147
148
|
end
|
148
149
|
end
|
149
|
-
|
150
150
|
end
|
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Whois::Server::Adapters::Formatted do
|
4
|
-
|
5
|
-
let(:definition) { [:tld, ".de", "whois.denic.de", { :format => "-T dn,ace -C US-ASCII %s" }] }
|
6
|
+
let(:definition) { [:tld, ".de", "whois.denic.de", { format: "-T dn,ace -C US-ASCII %s" }] }
|
6
7
|
|
7
8
|
|
8
9
|
describe "#lookup" do
|
@@ -19,7 +20,7 @@ describe Whois::Server::Adapters::Formatted do
|
|
19
20
|
|
20
21
|
context "without format option" do
|
21
22
|
it "raises an error" do
|
22
|
-
server = described_class.new(
|
23
|
+
server = described_class.new(:tld, ".de", "whois.denic.de", {})
|
23
24
|
expect(server.query_handler).to receive(:call).never
|
24
25
|
|
25
26
|
expect {
|
@@ -31,7 +32,7 @@ describe Whois::Server::Adapters::Formatted do
|
|
31
32
|
context "with port option" do
|
32
33
|
it "sends the request to given port" do
|
33
34
|
response = "Whois Response"
|
34
|
-
server = described_class.new(:tld, ".de", "whois.denic.de", { :
|
35
|
+
server = described_class.new(:tld, ".de", "whois.denic.de", { format: "-T dn,ace -C US-ASCII %s", port: 20 })
|
35
36
|
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
|
|
37
38
|
server.lookup("domain.de")
|
@@ -41,13 +42,12 @@ describe Whois::Server::Adapters::Formatted do
|
|
41
42
|
context "with bind option" do
|
42
43
|
it "binds the request to given host and port" do
|
43
44
|
response = "Whois Response"
|
44
|
-
server = described_class.new(:tld, ".de", "whois.denic.de", { :
|
45
|
-
server.configure(:
|
45
|
+
server = described_class.new(:tld, ".de", "whois.denic.de", { format: "-T dn,ace -C US-ASCII %s" })
|
46
|
+
server.configure(bind_host: "192.168.1.1", bind_port: 3000)
|
46
47
|
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
|
|
48
49
|
server.lookup("domain.de")
|
49
50
|
end
|
50
51
|
end
|
51
52
|
end
|
52
|
-
|
53
53
|
end
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Whois::Server::Adapters::None do
|
4
|
-
|
5
6
|
describe "#lookup" do
|
6
7
|
it "raises Whois::NoInterfaceError" do
|
7
8
|
expect {
|
@@ -19,5 +20,4 @@ describe Whois::Server::Adapters::None do
|
|
19
20
|
}.to raise_error(Whois::NoInterfaceError, /ipv4/)
|
20
21
|
end
|
21
22
|
end
|
22
|
-
|
23
23
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Whois::Server::Adapters::NotImplemented do
|
4
|
-
|
5
6
|
before(:each) do
|
6
|
-
@definition = [:ipv6, "2001:0000::/32", "teredo", { :
|
7
|
+
@definition = [:ipv6, "2001:0000::/32", "teredo", { adapter: Whois::Server::Adapters::NotImplemented }]
|
7
8
|
end
|
8
9
|
|
9
10
|
|
@@ -20,5 +21,4 @@ describe Whois::Server::Adapters::NotImplemented do
|
|
20
21
|
}.to raise_error(Whois::ServerNotImplemented, /teredo/)
|
21
22
|
end
|
22
23
|
end
|
23
|
-
|
24
24
|
end
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Whois::Server::Adapters::Standard do
|
4
|
-
|
5
6
|
let(:definition) { [:tld, ".test", "whois.test", {}] }
|
6
7
|
|
7
8
|
|
@@ -20,7 +21,7 @@ describe Whois::Server::Adapters::Standard do
|
|
20
21
|
context "with port option" do
|
21
22
|
it "sends the request to given port" do
|
22
23
|
response = "Whois Response"
|
23
|
-
server = described_class.new(:tld, ".test", "whois.test", { :
|
24
|
+
server = described_class.new(:tld, ".test", "whois.test", { port: 20 })
|
24
25
|
expect(server.query_handler).to receive(:call).with("domain.test", "whois.test", 20).and_return(response)
|
25
26
|
|
26
27
|
server.lookup("domain.test")
|
@@ -30,13 +31,12 @@ describe Whois::Server::Adapters::Standard do
|
|
30
31
|
context "with bind option" do
|
31
32
|
it "binds the request to given host and port" do
|
32
33
|
response = "Whois Response"
|
33
|
-
server = described_class.new(:tld, ".test", "whois.test", { :
|
34
|
-
server.configure(:
|
34
|
+
server = described_class.new(:tld, ".test", "whois.test", { port: 20 })
|
35
|
+
server.configure(bind_host: "192.168.1.100", bind_port: 3000)
|
35
36
|
expect(server.query_handler).to receive(:call).with("domain.test", "whois.test", 20, "192.168.1.100", 3000).and_return(response)
|
36
37
|
|
37
38
|
server.lookup("domain.test")
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
41
|
-
|
42
42
|
end
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Whois::Server::Adapters::Verisign do
|
4
|
-
|
5
6
|
let(:definition) { [:tld, ".test", "whois.test", {}] }
|
6
7
|
let(:server) { described_class.new(*definition) }
|
7
8
|
|
@@ -24,7 +25,7 @@ describe Whois::Server::Adapters::Verisign do
|
|
24
25
|
it "follows all referrals" do
|
25
26
|
referral = File.read(fixture("referrals/crsnic.com.txt"))
|
26
27
|
response = "Match for example.test."
|
27
|
-
expected = referral
|
28
|
+
expected = "#{referral}\n#{response}"
|
28
29
|
expect(server.query_handler).to receive(:call).with("=example.test", "whois.test", 43).and_return(referral)
|
29
30
|
expect(server.query_handler).to receive(:call).with("example.test", "whois.markmonitor.com", 43).and_return(response)
|
30
31
|
|
@@ -56,5 +57,4 @@ describe Whois::Server::Adapters::Verisign do
|
|
56
57
|
end
|
57
58
|
end
|
58
59
|
end
|
59
|
-
|
60
60
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Whois::Server::Adapters::Web do
|
4
|
-
|
5
6
|
before(:each) do
|
6
|
-
@definition = [:tld, ".test", nil, { :
|
7
|
+
@definition = [:tld, ".test", nil, { url: "http://whois.test" }]
|
7
8
|
end
|
8
9
|
|
9
10
|
|
@@ -20,5 +21,4 @@ describe Whois::Server::Adapters::Web do
|
|
20
21
|
}.to raise_error(Whois::WebInterfaceError, /whois\.test/)
|
21
22
|
end
|
22
23
|
end
|
23
|
-
|
24
24
|
end
|
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'whois/server/socket_handler'
|
3
5
|
|
4
6
|
describe Whois::Server::SocketHandler do
|
5
|
-
|
6
7
|
describe "#call" do
|
7
|
-
[
|
8
|
+
[Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ETIMEDOUT, Errno::EPIPE, SocketError].each do |error|
|
8
9
|
it "re-raises #{error} as Whois::ConnectionError" do
|
9
10
|
expect(subject).to receive(:execute).and_raise(error)
|
10
11
|
expect {
|
@@ -13,15 +14,16 @@ describe Whois::Server::SocketHandler do
|
|
13
14
|
end
|
14
15
|
|
15
16
|
it "executes a socket connection for given args" do
|
16
|
-
socket =
|
17
|
+
socket = instance_double(TCPSocket)
|
17
18
|
expect(socket).to receive(:write).with("example.test\r\n")
|
18
19
|
expect(socket).to receive(:read)
|
19
20
|
expect(socket).to receive(:close)
|
20
21
|
|
21
|
-
expect(TCPSocket).to receive(:new)
|
22
|
+
expect(TCPSocket).to receive(:new)
|
23
|
+
.with("whois.test", 43)
|
24
|
+
.and_return(socket)
|
22
25
|
subject.call("example.test", "whois.test", 43)
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
26
|
-
|
27
29
|
end
|
data/spec/whois/server_spec.rb
CHANGED
@@ -1,41 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Whois::Server do
|
4
6
|
describe ".load_json" do
|
5
7
|
it "loads a definition from a JSON file" do
|
6
|
-
expect(File).to receive(:read).with("tld.json").and_return(
|
7
|
-
{
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}
|
8
|
+
expect(File).to receive(:read).with("tld.json").and_return(<<~JSON)
|
9
|
+
{
|
10
|
+
"ae.org": {
|
11
|
+
"host": "whois.centralnic.com"
|
12
|
+
},
|
13
|
+
"ar.com": {
|
14
|
+
"host": "whois.centralnic.com"
|
15
|
+
}
|
16
|
+
}
|
15
17
|
JSON
|
16
18
|
with_definitions do
|
17
19
|
described_class.load_json("tld.json")
|
18
20
|
expect(described_class.definitions(:tld)).to eq([
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
["ae.org", "whois.centralnic.com", {}],
|
22
|
+
["ar.com", "whois.centralnic.com", {}],
|
23
|
+
])
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
it "convert option keys to Symbol" do
|
26
|
-
expect(File).to receive(:read).with("tld.json").and_return(
|
27
|
-
{
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
}
|
28
|
+
expect(File).to receive(:read).with("tld.json").and_return(<<~JSON)
|
29
|
+
{
|
30
|
+
"com": {
|
31
|
+
"host": "whois.crsnic.net",
|
32
|
+
"adapter": "verisign"
|
33
|
+
}
|
34
|
+
}
|
33
35
|
JSON
|
34
36
|
with_definitions do
|
35
37
|
described_class.load_json("tld.json")
|
36
38
|
expect(described_class.definitions(:tld)).to eq([
|
37
|
-
|
38
|
-
|
39
|
+
["com", "whois.crsnic.net", { adapter: "verisign" }],
|
40
|
+
])
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
@@ -70,7 +72,7 @@ describe Whois::Server do
|
|
70
72
|
it "accepts a hash of options" do
|
71
73
|
with_definitions do
|
72
74
|
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", { :
|
75
|
+
expect(described_class.definitions(Whois::Server::TYPE_TLD)).to eq([["foo", "whois.foo", { foo: "bar" }]])
|
74
76
|
end
|
75
77
|
end
|
76
78
|
end
|
@@ -81,7 +83,7 @@ describe Whois::Server do
|
|
81
83
|
expect(server.type).to eq(:tld)
|
82
84
|
expect(server.allocation).to eq("test")
|
83
85
|
expect(server.host).to eq("whois.test")
|
84
|
-
expect(server.options).to eq(
|
86
|
+
expect(server.options).to eq({})
|
85
87
|
end
|
86
88
|
|
87
89
|
it "returns a standard adapter by default" do
|
@@ -92,25 +94,26 @@ describe Whois::Server do
|
|
92
94
|
it "accepts an :adapter option as Class and returns an instance of given adapter" do
|
93
95
|
a = Class.new do
|
94
96
|
attr_reader :args
|
97
|
+
|
95
98
|
def initialize(*args)
|
96
99
|
@args = args
|
97
100
|
end
|
98
101
|
end
|
99
|
-
server = Whois::Server.factory(:tld, "test", "whois.test", :
|
102
|
+
server = Whois::Server.factory(:tld, "test", "whois.test", adapter: a)
|
100
103
|
expect(server).to be_a(a)
|
101
104
|
expect(server.args).to eq([:tld, "test", "whois.test", {}])
|
102
105
|
end
|
103
106
|
|
104
107
|
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", :
|
108
|
+
server = Whois::Server.factory(:tld, "test", "whois.test", adapter: :none)
|
106
109
|
expect(server).to be_a(Whois::Server::Adapters::None)
|
107
|
-
server = Whois::Server.factory(:tld, "test", "whois.test", :
|
110
|
+
server = Whois::Server.factory(:tld, "test", "whois.test", adapter: "none")
|
108
111
|
expect(server).to be_a(Whois::Server::Adapters::None)
|
109
112
|
end
|
110
113
|
|
111
114
|
it "deletes the adapter option" do
|
112
|
-
server = Whois::Server.factory(:tld, "test", "whois.test", :
|
113
|
-
expect(server.options).to eq({ :
|
115
|
+
server = Whois::Server.factory(:tld, "test", "whois.test", adapter: Whois::Server::Adapters::None, foo: "bar")
|
116
|
+
expect(server.options).to eq({ foo: "bar" })
|
114
117
|
end
|
115
118
|
end
|
116
119
|
|
@@ -296,5 +299,4 @@ describe Whois::Server do
|
|
296
299
|
end
|
297
300
|
end
|
298
301
|
end
|
299
|
-
|
300
302
|
end
|