whois 5.0.1 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +8 -0
- data/.github/workflows/codeql-analysis.yml +64 -0
- data/.github/workflows/release.yml +16 -0
- data/.github/workflows/tests.yml +29 -0
- data/.rubocop.yml +27 -0
- data/.rubocop_opinionated.yml +135 -0
- data/.rubocop_todo.yml +166 -0
- data/.simplecov +2 -0
- data/.tool-versions +1 -0
- data/CHANGELOG.md +76 -53
- data/CONTRIBUTING.md +12 -12
- data/Gemfile +5 -0
- data/LICENSE.txt +1 -1
- data/README.md +22 -22
- 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 -99
- data/lib/whois/client.rb +4 -2
- data/lib/whois/errors.rb +4 -2
- data/lib/whois/record/part.rb +5 -4
- data/lib/whois/record.rb +4 -2
- data/lib/whois/server/adapters/afilias.rb +4 -1
- data/lib/whois/server/adapters/arin.rb +7 -4
- data/lib/whois/server/adapters/arpa.rb +20 -19
- data/lib/whois/server/adapters/base.rb +26 -40
- 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/server.rb +41 -47
- data/lib/whois/version.rb +4 -2
- data/lib/whois.rb +13 -11
- data/spec/integration/whois_spec.rb +6 -6
- data/spec/spec_helper.rb +4 -4
- data/spec/support/helpers/connectivity_helper.rb +3 -3
- 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 +4 -4
- data/spec/whois/server/adapters/arin_spec.rb +9 -10
- 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 +8 -8
- data/spec/whois/server/adapters/none_spec.rb +2 -2
- data/spec/whois/server/adapters/not_implemented_spec.rb +4 -4
- data/spec/whois/server/adapters/standard_spec.rb +5 -5
- data/spec/whois/server/adapters/verisign_spec.rb +5 -5
- data/spec/whois/server/adapters/web_spec.rb +4 -4
- 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 +13 -39
- data/.travis.yml +0 -18
- data/bin/setup +0 -8
- data/tasks/spec.rake +0 -199
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
#--
|
|
2
4
|
# Ruby Whois
|
|
3
5
|
#
|
|
4
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
|
5
7
|
#
|
|
6
|
-
# Copyright (c) 2009-
|
|
8
|
+
# Copyright (c) 2009-2022 Simone Carletti <weppos@weppos.net>
|
|
7
9
|
#++
|
|
8
10
|
|
|
9
11
|
|
|
@@ -56,4 +58,4 @@ module Whois
|
|
|
56
58
|
|
|
57
59
|
end
|
|
58
60
|
end
|
|
59
|
-
end
|
|
61
|
+
end
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
#--
|
|
2
4
|
# Ruby Whois
|
|
3
5
|
#
|
|
4
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
|
5
7
|
#
|
|
6
|
-
# Copyright (c) 2009-
|
|
8
|
+
# Copyright (c) 2009-2022 Simone Carletti <weppos@weppos.net>
|
|
7
9
|
#++
|
|
8
10
|
|
|
9
11
|
|
|
@@ -40,6 +42,7 @@ module Whois
|
|
|
40
42
|
|
|
41
43
|
def extract_referral(response)
|
|
42
44
|
return unless (match = response.match(/Registrar WHOIS Server:(.+?)$/))
|
|
45
|
+
|
|
43
46
|
server = match[match.size - 1].strip
|
|
44
47
|
server.empty? ? nil : server
|
|
45
48
|
end
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
#--
|
|
2
4
|
# Ruby Whois
|
|
3
5
|
#
|
|
4
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
|
5
7
|
#
|
|
6
|
-
# Copyright (c) 2009-
|
|
8
|
+
# Copyright (c) 2009-2022 Simone Carletti <weppos@weppos.net>
|
|
7
9
|
#++
|
|
8
10
|
|
|
9
11
|
|
|
@@ -22,9 +24,9 @@ module Whois
|
|
|
22
24
|
# Array of connection errors to rescue
|
|
23
25
|
# and wrap into a {Whois::ConnectionError}
|
|
24
26
|
RESCUABLE_CONNECTION_ERRORS = [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
]
|
|
27
|
+
SystemCallError,
|
|
28
|
+
SocketError,
|
|
29
|
+
].freeze
|
|
28
30
|
|
|
29
31
|
# Performs the Socket request.
|
|
30
32
|
#
|
|
@@ -36,8 +38,8 @@ module Whois
|
|
|
36
38
|
#
|
|
37
39
|
def call(query, *args)
|
|
38
40
|
execute(query, *args)
|
|
39
|
-
rescue *RESCUABLE_CONNECTION_ERRORS =>
|
|
40
|
-
raise ConnectionError, "#{
|
|
41
|
+
rescue *RESCUABLE_CONNECTION_ERRORS => e
|
|
42
|
+
raise ConnectionError, "#{e.class}: #{e.message}"
|
|
41
43
|
end
|
|
42
44
|
|
|
43
45
|
# Executes the low-level Socket connection.
|
data/lib/whois/server.rb
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
#--
|
|
3
4
|
# Ruby Whois
|
|
4
5
|
#
|
|
5
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
|
6
7
|
#
|
|
7
|
-
# Copyright (c) 2009-
|
|
8
|
+
# Copyright (c) 2009-2022 Simone Carletti <weppos@weppos.net>
|
|
8
9
|
#++
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
require 'ipaddr'
|
|
12
13
|
require 'json'
|
|
13
|
-
require
|
|
14
|
+
require "whois/server/adapters/base"
|
|
15
|
+
require "whois/server/adapters/arin"
|
|
16
|
+
require "whois/server/adapters/arpa"
|
|
17
|
+
require "whois/server/adapters/afilias"
|
|
18
|
+
require "whois/server/adapters/formatted"
|
|
19
|
+
require "whois/server/adapters/none"
|
|
20
|
+
require "whois/server/adapters/not_implemented"
|
|
21
|
+
require "whois/server/adapters/standard"
|
|
22
|
+
require "whois/server/adapters/verisign"
|
|
23
|
+
require "whois/server/adapters/web"
|
|
14
24
|
|
|
15
25
|
|
|
16
26
|
module Whois
|
|
@@ -26,25 +36,15 @@ module Whois
|
|
|
26
36
|
# WHOIS server adapters. Each adapter is a subclass of {Whois::Server::Adapters::Base},
|
|
27
37
|
# customized to handle WHOIS queries for a type or a group of servers.
|
|
28
38
|
module Adapters
|
|
29
|
-
autoload :Base, "whois/server/adapters/base"
|
|
30
|
-
autoload :Arin, "whois/server/adapters/arin"
|
|
31
|
-
autoload :Arpa, "whois/server/adapters/arpa"
|
|
32
|
-
autoload :Afilias, "whois/server/adapters/afilias"
|
|
33
|
-
autoload :Formatted, "whois/server/adapters/formatted"
|
|
34
|
-
autoload :None, "whois/server/adapters/none"
|
|
35
|
-
autoload :NotImplemented, "whois/server/adapters/not_implemented"
|
|
36
|
-
autoload :Standard, "whois/server/adapters/standard"
|
|
37
|
-
autoload :Verisign, "whois/server/adapters/verisign"
|
|
38
|
-
autoload :Web, "whois/server/adapters/web"
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
# @return [Array<Symbol>] the definition types
|
|
42
42
|
TYPES = [
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
TYPE_TLD = :tld,
|
|
44
|
+
TYPE_IPV4 = :ipv4,
|
|
45
|
+
TYPE_IPV6 = :ipv6,
|
|
46
|
+
TYPE_ASN16 = :asn16,
|
|
47
|
+
TYPE_ASN32 = :asn32,
|
|
48
48
|
].freeze
|
|
49
49
|
|
|
50
50
|
# Empty hash constant used to save allocation for definitions with empty settings.
|
|
@@ -67,7 +67,7 @@ module Whois
|
|
|
67
67
|
# @return [void]
|
|
68
68
|
def load_definitions
|
|
69
69
|
clear_definitions
|
|
70
|
-
Dir[File.expand_path(
|
|
70
|
+
Dir[File.expand_path('../../data/*.json', __dir__)].each { |f| load_json(f) }
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
# Loads the definitions from a JSON file.
|
|
@@ -77,16 +77,17 @@ module Whois
|
|
|
77
77
|
# @return [void]
|
|
78
78
|
def load_json(file)
|
|
79
79
|
type = File.basename(file, File.extname(file)).to_sym
|
|
80
|
-
JSON.
|
|
80
|
+
JSON.parse(File.read(file)).each do |allocation, settings|
|
|
81
81
|
next if allocation == "_"
|
|
82
|
+
|
|
82
83
|
settings.reject! { |k, _| k.start_with?("_") }
|
|
83
84
|
host = settings.delete("host")
|
|
84
85
|
host = intern_string(host) if host
|
|
85
86
|
options = if settings.empty?
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
EMPTY_HASH
|
|
88
|
+
else
|
|
89
|
+
settings.map { |k, v| [k.to_sym, v.is_a?(String) ? intern_string(v) : v] }.to_h.freeze
|
|
90
|
+
end
|
|
90
91
|
define(type, allocation, host, options)
|
|
91
92
|
end
|
|
92
93
|
end
|
|
@@ -112,7 +113,7 @@ module Whois
|
|
|
112
113
|
#
|
|
113
114
|
def definitions(type)
|
|
114
115
|
TYPES.include?(type) or
|
|
115
|
-
|
|
116
|
+
raise(ArgumentError, "`#{type}` is not a valid definition type")
|
|
116
117
|
|
|
117
118
|
_definitions(type).values
|
|
118
119
|
end
|
|
@@ -156,7 +157,7 @@ module Whois
|
|
|
156
157
|
#
|
|
157
158
|
def define(type, allocation, host, options = EMPTY_HASH)
|
|
158
159
|
TYPES.include?(type) or
|
|
159
|
-
|
|
160
|
+
raise(ArgumentError, "`#{type}` is not a valid definition type")
|
|
160
161
|
|
|
161
162
|
_definitions(type)[allocation] = [allocation, host, options.freeze]
|
|
162
163
|
end
|
|
@@ -234,19 +235,13 @@ module Whois
|
|
|
234
235
|
# but the object type doesn't have any supported WHOIS adapter associated.
|
|
235
236
|
def guess(string)
|
|
236
237
|
# Top Level Domain match
|
|
237
|
-
if matches_tld?(string)
|
|
238
|
-
return factory(:tld, ".", "whois.iana.org")
|
|
239
|
-
end
|
|
238
|
+
return factory(:tld, ".", "whois.iana.org") if matches_tld?(string)
|
|
240
239
|
|
|
241
240
|
# IP address (secure match)
|
|
242
|
-
if matches_ip?(string)
|
|
243
|
-
return find_for_ip(string)
|
|
244
|
-
end
|
|
241
|
+
return find_for_ip(string) if matches_ip?(string)
|
|
245
242
|
|
|
246
243
|
# Email Address (secure match)
|
|
247
|
-
if matches_email?(string)
|
|
248
|
-
return find_for_email(string)
|
|
249
|
-
end
|
|
244
|
+
return find_for_email(string) if matches_email?(string)
|
|
250
245
|
|
|
251
246
|
# Domain Name match
|
|
252
247
|
if (server = find_for_domain(string))
|
|
@@ -254,9 +249,7 @@ module Whois
|
|
|
254
249
|
end
|
|
255
250
|
|
|
256
251
|
# ASN match
|
|
257
|
-
if matches_asn?(string)
|
|
258
|
-
return find_for_asn(string)
|
|
259
|
-
end
|
|
252
|
+
return find_for_asn(string) if matches_asn?(string)
|
|
260
253
|
|
|
261
254
|
# Game Over
|
|
262
255
|
raise ServerNotFound, "Unable to find a WHOIS server for `#{string}'"
|
|
@@ -276,12 +269,11 @@ module Whois
|
|
|
276
269
|
ip = IPAddr.new(string)
|
|
277
270
|
type = ip.ipv4? ? TYPE_IPV4 : TYPE_IPV6
|
|
278
271
|
_definitions(type).each do |_, definition|
|
|
279
|
-
if IPAddr.new(definition.first).include?(ip)
|
|
280
|
-
return factory(type, *definition)
|
|
281
|
-
end
|
|
272
|
+
return factory(type, *definition) if IPAddr.new(definition.first).include?(ip)
|
|
282
273
|
end
|
|
283
274
|
rescue ArgumentError
|
|
284
275
|
# continue
|
|
276
|
+
nil
|
|
285
277
|
end
|
|
286
278
|
raise AllocationUnknown, "IP Allocation for `#{string}' unknown"
|
|
287
279
|
end
|
|
@@ -304,7 +296,7 @@ module Whois
|
|
|
304
296
|
token = string
|
|
305
297
|
defs = _definitions(TYPE_TLD)
|
|
306
298
|
|
|
307
|
-
while token != ""
|
|
299
|
+
while token != ""
|
|
308
300
|
if (found = defs[token])
|
|
309
301
|
return factory(:tld, *found)
|
|
310
302
|
else
|
|
@@ -328,7 +320,7 @@ module Whois
|
|
|
328
320
|
# that matches one of the existing server definitions.
|
|
329
321
|
def find_for_asn(string)
|
|
330
322
|
asn = string[/\d+/].to_i
|
|
331
|
-
asn_type = asn <=
|
|
323
|
+
asn_type = asn <= 65_535 ? TYPE_ASN16 : TYPE_ASN32
|
|
332
324
|
_definitions(asn_type).each do |_, definition|
|
|
333
325
|
if (range = definition.first.split.map(&:to_i)) && asn >= range.first && asn <= range.last
|
|
334
326
|
return factory(asn_type, *definition)
|
|
@@ -379,9 +371,10 @@ module Whois
|
|
|
379
371
|
end
|
|
380
372
|
|
|
381
373
|
def valid_ipv4?(addr)
|
|
382
|
-
if /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z
|
|
383
|
-
return
|
|
374
|
+
if (m = /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/.match(addr))
|
|
375
|
+
return m.captures.all? { |i| i.to_i < 256 }
|
|
384
376
|
end
|
|
377
|
+
|
|
385
378
|
false
|
|
386
379
|
end
|
|
387
380
|
|
|
@@ -391,9 +384,10 @@ module Whois
|
|
|
391
384
|
return true if addr.match?(/\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*)?\Z/)
|
|
392
385
|
return true if addr.match?(/\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*)?\Z/)
|
|
393
386
|
# IPv6 (IPv4 compat)
|
|
394
|
-
return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:/ =~ addr && valid_ipv4?(
|
|
395
|
-
return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ addr && valid_ipv4?(
|
|
396
|
-
return true if /\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ addr && valid_ipv4?(
|
|
387
|
+
return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:/ =~ addr && valid_ipv4?(Regexp.last_match.post_match)
|
|
388
|
+
return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ addr && valid_ipv4?(Regexp.last_match.post_match)
|
|
389
|
+
return true if /\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ addr && valid_ipv4?(Regexp.last_match.post_match)
|
|
390
|
+
|
|
397
391
|
false
|
|
398
392
|
end
|
|
399
393
|
|
data/lib/whois/version.rb
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
#--
|
|
2
4
|
# Ruby Whois
|
|
3
5
|
#
|
|
4
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
|
5
7
|
#
|
|
6
|
-
# Copyright (c) 2009-
|
|
8
|
+
# Copyright (c) 2009-2022 Simone Carletti <weppos@weppos.net>
|
|
7
9
|
#++
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
module Whois
|
|
11
13
|
# The current library version.
|
|
12
|
-
VERSION = "5.0
|
|
14
|
+
VERSION = "5.1.0"
|
|
13
15
|
end
|
data/lib/whois.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
#--
|
|
2
4
|
# Ruby Whois
|
|
3
5
|
#
|
|
4
6
|
# An intelligent pure Ruby WHOIS client and parser.
|
|
5
7
|
#
|
|
6
|
-
# Copyright (c) 2009-
|
|
8
|
+
# Copyright (c) 2009-2022 Simone Carletti <weppos@weppos.net>
|
|
7
9
|
#++
|
|
8
10
|
|
|
9
11
|
|
|
@@ -35,7 +37,7 @@ module Whois
|
|
|
35
37
|
Client.new.lookup(object)
|
|
36
38
|
end
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
alias whois lookup
|
|
39
41
|
|
|
40
42
|
|
|
41
43
|
# @deprecated
|
|
@@ -45,11 +47,11 @@ module Whois
|
|
|
45
47
|
return
|
|
46
48
|
end
|
|
47
49
|
|
|
48
|
-
deprecate(%
|
|
50
|
+
deprecate(%{Whois.available? is deprecated. Call Whois.whois("#{object}").parser.available?})
|
|
49
51
|
|
|
50
52
|
result = lookup(object).parser.available?
|
|
51
53
|
if result.nil?
|
|
52
|
-
warn "This method is not supported for this kind of object.\n"
|
|
54
|
+
warn "This method is not supported for this kind of object.\n" \
|
|
53
55
|
"Use Whois.lookup('#{object}') instead."
|
|
54
56
|
end
|
|
55
57
|
result
|
|
@@ -62,11 +64,11 @@ module Whois
|
|
|
62
64
|
return
|
|
63
65
|
end
|
|
64
66
|
|
|
65
|
-
deprecate(%
|
|
67
|
+
deprecate(%{Whois.registered? is deprecated. Call Whois.whois("#{object}").parser.registered?})
|
|
66
68
|
|
|
67
69
|
result = lookup(object).parser.registered?
|
|
68
70
|
if result.nil?
|
|
69
|
-
warn "This method is not supported for this kind of object.\n"
|
|
71
|
+
warn "This method is not supported for this kind of object.\n" \
|
|
70
72
|
"Use Whois.lookup('#{object}') instead."
|
|
71
73
|
end
|
|
72
74
|
result
|
|
@@ -87,9 +89,9 @@ module Whois
|
|
|
87
89
|
# @api private
|
|
88
90
|
# @private
|
|
89
91
|
def bug!(error, message)
|
|
90
|
-
raise error, message.dup
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
raise error, message.dup <<
|
|
93
|
+
" Please report the issue at" \
|
|
94
|
+
" http://github.com/weppos/whois/issues"
|
|
93
95
|
end
|
|
94
96
|
|
|
95
97
|
|
|
@@ -107,10 +109,10 @@ module Whois
|
|
|
107
109
|
end
|
|
108
110
|
|
|
109
111
|
def extract_callstack(callstack)
|
|
110
|
-
gem_root = File.expand_path(
|
|
112
|
+
gem_root = "#{File.expand_path('../..', __dir__)}/"
|
|
111
113
|
offending_line = callstack.find { |line| !line.start_with?(gem_root) } || callstack.first
|
|
112
114
|
if offending_line
|
|
113
|
-
if md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/)
|
|
115
|
+
if (md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/))
|
|
114
116
|
md.captures
|
|
115
117
|
else
|
|
116
118
|
offending_line
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe Whois do
|
|
4
|
-
|
|
5
|
-
let(:response) { "Domain: example.it\nStatus: AVAILABLE\n" }
|
|
6
|
+
let(:response) { "Domain: example.it\nStatus: AVAILABLE\n" }
|
|
6
7
|
|
|
7
8
|
describe "Basic WHOIS querying and parsing" do
|
|
8
9
|
it "works" do
|
|
@@ -32,7 +33,7 @@ describe Whois do
|
|
|
32
33
|
.with("example.it", "whois.nic.it", 43, "192.168.1.1", 3000)
|
|
33
34
|
.and_return(response)
|
|
34
35
|
|
|
35
|
-
client = Whois::Client.new(:
|
|
36
|
+
client = Whois::Client.new(bind_host: "192.168.1.1", bind_port: 3000)
|
|
36
37
|
client.lookup("example.it")
|
|
37
38
|
end
|
|
38
39
|
end
|
|
@@ -46,7 +47,7 @@ describe Whois do
|
|
|
46
47
|
.with("example.it", "whois.nic.it", 43, Whois::Server::Adapters::Base::DEFAULT_BIND_HOST, 3000)
|
|
47
48
|
.and_return(response)
|
|
48
49
|
|
|
49
|
-
client = Whois::Client.new(:
|
|
50
|
+
client = Whois::Client.new(bind_port: 3000)
|
|
50
51
|
client.lookup("example.it")
|
|
51
52
|
end
|
|
52
53
|
end
|
|
@@ -60,7 +61,7 @@ describe Whois do
|
|
|
60
61
|
.with("example.it", "whois.example.com", 43)
|
|
61
62
|
.and_return(response)
|
|
62
63
|
|
|
63
|
-
client = Whois::Client.new(:
|
|
64
|
+
client = Whois::Client.new(host: "whois.example.com")
|
|
64
65
|
record = client.lookup("example.it")
|
|
65
66
|
|
|
66
67
|
expect(record.parts.size).to eq(1)
|
|
@@ -69,5 +70,4 @@ describe Whois do
|
|
|
69
70
|
end
|
|
70
71
|
end
|
|
71
72
|
end
|
|
72
|
-
|
|
73
73
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'rspec'
|
|
2
4
|
require 'whois'
|
|
3
5
|
|
|
4
|
-
unless defined?(SPEC_ROOT)
|
|
5
|
-
SPEC_ROOT = File.expand_path("../", __FILE__)
|
|
6
|
-
end
|
|
6
|
+
SPEC_ROOT = File.expand_path(__dir__) unless defined?(SPEC_ROOT)
|
|
7
7
|
|
|
8
8
|
# The fixtures are UTF-8 encoded.
|
|
9
9
|
# Make sure Ruby uses the proper encoding.
|
|
@@ -12,7 +12,7 @@ Encoding.default_internal = Encoding::UTF_8
|
|
|
12
12
|
|
|
13
13
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
|
14
14
|
# in spec/support/ and its subdirectories.
|
|
15
|
-
Dir[File.join(SPEC_ROOT, "support/**/*.rb")].each { |f| require f }
|
|
15
|
+
Dir[File.join(SPEC_ROOT, "support/**/*.rb")].sort.each { |f| require f }
|
|
16
16
|
|
|
17
17
|
RSpec.configure do |config|
|
|
18
18
|
config.mock_with :rspec
|
data/spec/whois/client_spec.rb
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe Whois::Client do
|
|
4
|
-
|
|
5
6
|
describe "#initialize" do
|
|
6
7
|
it "accepts a zero parameters" do
|
|
7
|
-
expect { described_class.new }.
|
|
8
|
+
expect { described_class.new }.not_to raise_error
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
it "accepts a settings parameter" do
|
|
11
|
-
expect { described_class.new({ foo: "bar" }) }.
|
|
12
|
+
expect { described_class.new({ foo: "bar" }) }.not_to raise_error
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
|
|
@@ -111,7 +112,7 @@ describe Whois::Client do
|
|
|
111
112
|
client = described_class.new(timeout: 5)
|
|
112
113
|
expect {
|
|
113
114
|
client.lookup("example.test")
|
|
114
|
-
}.
|
|
115
|
+
}.not_to raise_error
|
|
115
116
|
end
|
|
116
117
|
|
|
117
118
|
it "supports unlimited timeout" do
|
|
@@ -125,9 +126,8 @@ describe Whois::Client do
|
|
|
125
126
|
client = described_class.new.tap { |c| c.timeout = nil }
|
|
126
127
|
expect {
|
|
127
128
|
client.lookup("example.test")
|
|
128
|
-
}.
|
|
129
|
+
}.not_to raise_error
|
|
129
130
|
end
|
|
130
|
-
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
# FIXME: use RSpec metadata
|
|
@@ -140,5 +140,4 @@ describe Whois::Client do
|
|
|
140
140
|
end
|
|
141
141
|
end
|
|
142
142
|
end
|
|
143
|
-
|
|
144
143
|
end
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe Whois::Record::Part do
|
|
4
|
-
|
|
5
6
|
describe "#initialize" do
|
|
6
7
|
it "accepts an empty value" do
|
|
7
8
|
expect {
|
|
8
9
|
instance = described_class.new
|
|
9
10
|
expect(instance.body).to be_nil
|
|
10
|
-
}.
|
|
11
|
+
}.not_to raise_error
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
it "accepts an empty hash" do
|
|
14
15
|
expect {
|
|
15
16
|
instance = described_class.new({})
|
|
16
17
|
expect(instance.body).to be_nil
|
|
17
|
-
}.
|
|
18
|
+
}.not_to raise_error
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
it "initializes a new instance from given hash" do
|
|
@@ -34,5 +35,4 @@ describe Whois::Record::Part do
|
|
|
34
35
|
expect(instance.host).to eq("whois.example.test")
|
|
35
36
|
end
|
|
36
37
|
end
|
|
37
|
-
|
|
38
38
|
end
|
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
|
|
|
@@ -38,12 +39,11 @@ describe Whois::Server::Adapters::Afilias do
|
|
|
38
39
|
referral = File.read(fixture("referrals/afilias.bz.txt"))
|
|
39
40
|
server.options[:referral] = false
|
|
40
41
|
expect(server.query_handler).to receive(:call).with("example.test", "whois.afilias-grs.info", 43).and_return(referral)
|
|
41
|
-
expect(server.query_handler).
|
|
42
|
+
expect(server.query_handler).not_to receive(:call).with("example.test", "whois.belizenic.bz", 43)
|
|
42
43
|
|
|
43
44
|
record = server.lookup("example.test")
|
|
44
45
|
expect(record.parts.size).to eq(1)
|
|
45
46
|
end
|
|
46
47
|
end
|
|
47
48
|
end
|
|
48
|
-
|
|
49
49
|
end
|