mirror of
https://github.com/Evolix/chexpire.git
synced 2024-05-05 02:05:09 +02:00
Verisign Parser for .com & .net
This commit is contained in:
parent
0436101ae7
commit
9c040f9fc4
|
@ -7,6 +7,5 @@ module Whois
|
|||
class ParserError < Error; end
|
||||
|
||||
class FieldNotFoundError < ParserError; end
|
||||
class MissingDateFormatError < ParserError; end
|
||||
class InvalidDateError < ParserError; end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
require "null_logger"
|
||||
require "whois/errors"
|
||||
require "whois/parser/fr"
|
||||
require "whois/parser/verisign"
|
||||
|
||||
module Whois
|
||||
module Parser
|
||||
PARSERS = [Fr].freeze
|
||||
PARSERS = [Fr, Verisign].freeze
|
||||
|
||||
class << self
|
||||
def for(domain, logger: NullLogger.new)
|
||||
|
|
|
@ -49,13 +49,15 @@ module Whois
|
|||
end
|
||||
|
||||
def parse_date(str)
|
||||
fail MissingDateFormatError, "Date format not set" if date_format.nil?
|
||||
|
||||
begin
|
||||
Time.strptime(str, date_format)
|
||||
rescue ArgumentError
|
||||
raise InvalidDateError, "Date `#{str}` does not match format #{date_format}"
|
||||
date_format.nil? ? Time.parse(str) : Time.strptime(str, date_format)
|
||||
rescue ArgumentError
|
||||
msg = if date_format.nil?
|
||||
"Date `#{str}` is not parsable without specifying a date format"
|
||||
else
|
||||
"Date `#{str}` does not match format #{date_format}"
|
||||
end
|
||||
|
||||
raise InvalidDateError, msg
|
||||
end
|
||||
|
||||
def comment_include?(str)
|
||||
|
@ -64,6 +66,12 @@ module Whois
|
|||
}
|
||||
end
|
||||
|
||||
def text_include?(str)
|
||||
entries.any? { |e|
|
||||
e.text? && e.text.include?(str)
|
||||
}
|
||||
end
|
||||
|
||||
def raise_not_found
|
||||
fail DomainNotFoundError, "Domain #{domain} not found in the registry database."
|
||||
end
|
||||
|
|
49
app/services/whois/parser/verisign.rb
Normal file
49
app/services/whois/parser/verisign.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require "domain_helper"
|
||||
require "whois/errors"
|
||||
require_relative "base"
|
||||
|
||||
module Whois
|
||||
module Parser
|
||||
class Verisign < Base
|
||||
SUPPORTED_TLD = %w[
|
||||
.com
|
||||
.net
|
||||
.cc
|
||||
.tv
|
||||
.name
|
||||
.jobs
|
||||
.edu
|
||||
.gov
|
||||
].freeze
|
||||
COMMENT_REGEX = /^(%|>)+ +(?<text>.+)$/
|
||||
FIELD_REGEX = /^(?<name>[^:]+)\s*:\s+(?<value>.+)$/
|
||||
|
||||
def self.supports?(domain)
|
||||
SUPPORTED_TLD.include?(tld(domain))
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def do_parse
|
||||
raise_not_found if text_include?("No match for domain")
|
||||
|
||||
extract_values
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def extract_values
|
||||
domain_index = get_field!("Domain Name", value: domain.upcase).index
|
||||
|
||||
created_date = get_value!("Creation Date", after: domain_index)
|
||||
response.created_at = parse_date(created_date)
|
||||
|
||||
expire_date = get_value!("Registry Expiry Date", after: domain_index)
|
||||
response.expire_at = parse_date(expire_date)
|
||||
|
||||
updated_date = get_value!("Updated Date", after: domain_index)
|
||||
response.updated_at = parse_date(updated_date)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
139
test/fixtures/files/whois/domain.com.txt
vendored
Normal file
139
test/fixtures/files/whois/domain.com.txt
vendored
Normal file
|
@ -0,0 +1,139 @@
|
|||
% IANA WHOIS server
|
||||
% for more information on IANA, visit http://www.iana.org
|
||||
% This query returned 1 object
|
||||
|
||||
refer: whois.verisign-grs.com
|
||||
|
||||
domain: COM
|
||||
|
||||
organisation: VeriSign Global Registry Services
|
||||
address: 12061 Bluemont Way
|
||||
address: Reston Virginia 20190
|
||||
address: United States
|
||||
|
||||
contact: administrative
|
||||
name: Registry Customer Service
|
||||
organisation: VeriSign Global Registry Services
|
||||
address: 12061 Bluemont Way
|
||||
address: Reston Virginia 20190
|
||||
address: United States
|
||||
phone: +1 703 925-6999
|
||||
fax-no: +1 703 948 3978
|
||||
e-mail: info@verisign-grs.com
|
||||
|
||||
contact: technical
|
||||
name: Registry Customer Service
|
||||
organisation: VeriSign Global Registry Services
|
||||
address: 12061 Bluemont Way
|
||||
address: Reston Virginia 20190
|
||||
address: United States
|
||||
phone: +1 703 925-6999
|
||||
fax-no: +1 703 948 3978
|
||||
e-mail: info@verisign-grs.com
|
||||
|
||||
nserver: A.GTLD-SERVERS.NET 192.5.6.30 2001:503:a83e:0:0:0:2:30
|
||||
nserver: B.GTLD-SERVERS.NET 192.33.14.30 2001:503:231d:0:0:0:2:30
|
||||
nserver: C.GTLD-SERVERS.NET 192.26.92.30 2001:503:83eb:0:0:0:0:30
|
||||
nserver: D.GTLD-SERVERS.NET 192.31.80.30 2001:500:856e:0:0:0:0:30
|
||||
nserver: E.GTLD-SERVERS.NET 192.12.94.30 2001:502:1ca1:0:0:0:0:30
|
||||
nserver: F.GTLD-SERVERS.NET 192.35.51.30 2001:503:d414:0:0:0:0:30
|
||||
nserver: G.GTLD-SERVERS.NET 192.42.93.30 2001:503:eea3:0:0:0:0:30
|
||||
nserver: H.GTLD-SERVERS.NET 192.54.112.30 2001:502:8cc:0:0:0:0:30
|
||||
nserver: I.GTLD-SERVERS.NET 192.43.172.30 2001:503:39c1:0:0:0:0:30
|
||||
nserver: J.GTLD-SERVERS.NET 192.48.79.30 2001:502:7094:0:0:0:0:30
|
||||
nserver: K.GTLD-SERVERS.NET 192.52.178.30 2001:503:d2d:0:0:0:0:30
|
||||
nserver: L.GTLD-SERVERS.NET 192.41.162.30 2001:500:d937:0:0:0:0:30
|
||||
nserver: M.GTLD-SERVERS.NET 192.55.83.30 2001:501:b1f9:0:0:0:0:30
|
||||
ds-rdata: 30909 8 2 E2D3C916F6DEEAC73294E8268FB5885044A833FC5459588F4A9184CFC41A5766
|
||||
|
||||
whois: whois.verisign-grs.com
|
||||
|
||||
status: ACTIVE
|
||||
remarks: Registration information: http://www.verisigninc.com
|
||||
|
||||
created: 1985-01-01
|
||||
changed: 2017-10-05
|
||||
source: IANA
|
||||
|
||||
Domain Name: DOMAIN.COM
|
||||
Registry Domain ID: 608082_DOMAIN_COM-VRSN
|
||||
Registrar WHOIS Server: whois.domain.com
|
||||
Registrar URL: http://www.domain.com
|
||||
Updated Date: 2018-02-13T18:33:26Z
|
||||
Creation Date: 1994-07-01T04:00:00Z
|
||||
Registry Expiry Date: 2021-01-07T13:34:24Z
|
||||
Registrar: Domain.com, LLC
|
||||
Registrar IANA ID: 886
|
||||
Registrar Abuse Contact Email: compliance@domain-inc.net
|
||||
Registrar Abuse Contact Phone: 602-226-2389
|
||||
Domain Status: clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited
|
||||
Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited
|
||||
Domain Status: clientUpdateProhibited https://icann.org/epp#clientUpdateProhibited
|
||||
Name Server: NS-1250.AWSDNS-28.ORG
|
||||
Name Server: NS-166.AWSDNS-20.COM
|
||||
Name Server: NS-2022.AWSDNS-60.CO.UK
|
||||
Name Server: NS-683.AWSDNS-21.NET
|
||||
DNSSEC: unsigned
|
||||
URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/
|
||||
>>> Last update of whois database: 2018-06-05T14:05:20Z <<<
|
||||
|
||||
Domain Name: DOMAIN.COM
|
||||
Registry Domain ID: 608082_DOMAIN_COM-VRSN
|
||||
Registrar WHOIS Server: whois.domain.com
|
||||
Registrar URL: www.domain.com
|
||||
Updated Date: 2016-10-21T20:11:05
|
||||
Creation Date: 1994-07-01T04:00:00
|
||||
Registrar Registration Expiration Date: 2021-01-07T13:34:24
|
||||
Registrar: Domain.com, LLC
|
||||
Registrar IANA ID: 886
|
||||
Reseller: Domain Name Holding Company, Inc
|
||||
Domain Status: clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited
|
||||
Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited
|
||||
Domain Status: clientUpdateProhibited https://icann.org/epp#clientUpdateProhibited
|
||||
Registry Registrant ID:
|
||||
Registrant Name: Data Protected Data Protected
|
||||
Registrant Organization: Data Protected
|
||||
Registrant Street: 123 Data Protected
|
||||
Registrant City: Toronto
|
||||
Registrant State/Province: ON
|
||||
Registrant Postal Code: M6K 3M1
|
||||
Registrant Country: CA
|
||||
Registrant Phone: +1.0000000000
|
||||
Registrant Phone Ext:
|
||||
Registrant Fax: +1.0000000000
|
||||
Registrant Fax Ext:
|
||||
Registrant Email: noreply@data-protected.net
|
||||
Registry Admin ID:
|
||||
Admin Name: Data Protected Data Protected
|
||||
Admin Organization: Data Protected
|
||||
Admin Street: 123 Data Protected
|
||||
Admin City: Toronto
|
||||
Admin State/Province: ON
|
||||
Admin Postal Code: M6K 3M1
|
||||
Admin Country: CA
|
||||
Admin Phone: +1.0000000000
|
||||
Admin Phone Ext:
|
||||
Admin Fax: +1.0000000000
|
||||
Admin Fax Ext:
|
||||
Admin Email: noreply@data-protected.net
|
||||
Registry Tech ID:
|
||||
Tech Name: Data Protected Data Protected
|
||||
Tech Organization: Data Protected
|
||||
Tech Street: 123 Data Protected
|
||||
Tech City: Toronto
|
||||
Tech State/Province: ON
|
||||
Tech Postal Code: M6K 3M1
|
||||
Tech Country: CA
|
||||
Tech Phone: +1.0000000000
|
||||
Tech Phone Ext:
|
||||
Tech Fax: +1.0000000000
|
||||
Tech Fax Ext:
|
||||
Tech Email: noreply@data-protected.net
|
||||
Name Server: ns-166.dnsserver.com
|
||||
Name Server: ns-683.dnsserver.net
|
||||
Name Server: ns-1250.dnsserver.org
|
||||
|
||||
Registrar Abuse Contact Email: compliance@domain-inc.net
|
||||
Registrar Abuse Contact Phone: +1.0123456789
|
||||
URL of the ICANN WHOIS Data Problem Reporting System: http://wdprs.internic.net/
|
||||
>>> Last update of WHOIS database: 2016-10-21T20:11:05 <<<
|
60
test/fixtures/files/whois/willneverexist.com.txt
vendored
Normal file
60
test/fixtures/files/whois/willneverexist.com.txt
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
% IANA WHOIS server
|
||||
% for more information on IANA, visit http://www.iana.org
|
||||
% This query returned 1 object
|
||||
|
||||
refer: whois.verisign-grs.com
|
||||
|
||||
domain: COM
|
||||
|
||||
organisation: VeriSign Global Registry Services
|
||||
address: 12061 Bluemont Way
|
||||
address: Reston Virginia 20190
|
||||
address: United States
|
||||
|
||||
contact: administrative
|
||||
name: Registry Customer Service
|
||||
organisation: VeriSign Global Registry Services
|
||||
address: 12061 Bluemont Way
|
||||
address: Reston Virginia 20190
|
||||
address: United States
|
||||
phone: +1 703 925-6999
|
||||
fax-no: +1 703 948 3978
|
||||
e-mail: info@verisign-grs.com
|
||||
|
||||
contact: technical
|
||||
name: Registry Customer Service
|
||||
organisation: VeriSign Global Registry Services
|
||||
address: 12061 Bluemont Way
|
||||
address: Reston Virginia 20190
|
||||
address: United States
|
||||
phone: +1 703 925-6999
|
||||
fax-no: +1 703 948 3978
|
||||
e-mail: info@verisign-grs.com
|
||||
|
||||
nserver: A.GTLD-SERVERS.NET 192.5.6.30 2001:503:a83e:0:0:0:2:30
|
||||
nserver: B.GTLD-SERVERS.NET 192.33.14.30 2001:503:231d:0:0:0:2:30
|
||||
nserver: C.GTLD-SERVERS.NET 192.26.92.30 2001:503:83eb:0:0:0:0:30
|
||||
nserver: D.GTLD-SERVERS.NET 192.31.80.30 2001:500:856e:0:0:0:0:30
|
||||
nserver: E.GTLD-SERVERS.NET 192.12.94.30 2001:502:1ca1:0:0:0:0:30
|
||||
nserver: F.GTLD-SERVERS.NET 192.35.51.30 2001:503:d414:0:0:0:0:30
|
||||
nserver: G.GTLD-SERVERS.NET 192.42.93.30 2001:503:eea3:0:0:0:0:30
|
||||
nserver: H.GTLD-SERVERS.NET 192.54.112.30 2001:502:8cc:0:0:0:0:30
|
||||
nserver: I.GTLD-SERVERS.NET 192.43.172.30 2001:503:39c1:0:0:0:0:30
|
||||
nserver: J.GTLD-SERVERS.NET 192.48.79.30 2001:502:7094:0:0:0:0:30
|
||||
nserver: K.GTLD-SERVERS.NET 192.52.178.30 2001:503:d2d:0:0:0:0:30
|
||||
nserver: L.GTLD-SERVERS.NET 192.41.162.30 2001:500:d937:0:0:0:0:30
|
||||
nserver: M.GTLD-SERVERS.NET 192.55.83.30 2001:501:b1f9:0:0:0:0:30
|
||||
ds-rdata: 30909 8 2 E2D3C916F6DEEAC73294E8268FB5885044A833FC5459588F4A9184CFC41A5766
|
||||
|
||||
whois: whois.verisign-grs.com
|
||||
|
||||
status: ACTIVE
|
||||
remarks: Registration information: http://www.verisigninc.com
|
||||
|
||||
created: 1985-01-01
|
||||
changed: 2017-10-05
|
||||
source: IANA
|
||||
|
||||
No match for domain "WILLNEVEREXIST.COM".
|
||||
>>> Last update of whois database: 2018-06-05T14:06:36Z <<<
|
||||
|
|
@ -26,5 +26,15 @@ module Whois
|
|||
parser.parse(not_found_fr)
|
||||
end
|
||||
end
|
||||
|
||||
test "should raises InvalidDateError when a date is not in the expected format" do
|
||||
parser = Parser::Fr.new("domain.fr")
|
||||
domain_fr = file_fixture("whois/domain.fr.txt").read
|
||||
domain_fr.gsub!("17/02/2019", "17-02-2019")
|
||||
|
||||
assert_raises InvalidDateError do
|
||||
parser.parse(domain_fr)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
40
test/services/whois/parser/verisign_test.rb
Normal file
40
test/services/whois/parser/verisign_test.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
require "test_helper"
|
||||
require "whois/parser/verisign"
|
||||
require "whois/response"
|
||||
require "whois/errors"
|
||||
|
||||
module Whois
|
||||
class VerisignTest < ActiveSupport::TestCase
|
||||
test "should parse a whois response" do
|
||||
parser = Parser::Verisign.new("domain.com")
|
||||
domain_com = file_fixture("whois/domain.com.txt").read
|
||||
response = parser.parse(domain_com)
|
||||
assert_kind_of Response, response
|
||||
|
||||
assert_equal Time.new(1994, 7, 1, 4, 0, 0, 0), response.created_at
|
||||
assert response.created_at.utc?
|
||||
|
||||
assert_equal Time.new(2018, 2, 13, 18, 33, 26, 0), response.updated_at
|
||||
assert_equal Time.new(2021, 1, 7, 13, 34, 24, 0), response.expire_at
|
||||
end
|
||||
|
||||
test "should raises DomainNotFoundError when domain is not registered" do
|
||||
parser = Parser::Verisign.new("willneverexist.com")
|
||||
not_found_com = file_fixture("whois/willneverexist.com.txt").read
|
||||
|
||||
assert_raises DomainNotFoundError do
|
||||
parser.parse(not_found_com)
|
||||
end
|
||||
end
|
||||
|
||||
test "should raises InvalidDateError when a date is not parsable" do
|
||||
parser = Parser::Verisign.new("domain.com")
|
||||
domain_com = file_fixture("whois/domain.com.txt").read
|
||||
domain_com.gsub!("2018-02-13T18:33:26Z", "not a date")
|
||||
|
||||
assert_raises InvalidDateError do
|
||||
parser.parse(domain_com)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,9 +4,16 @@ require "whois/errors"
|
|||
|
||||
module Whois
|
||||
class ParserTest < ActiveSupport::TestCase
|
||||
test "should instanciate a parser class matching the tld" do
|
||||
test "should instanciate a parser class matching AFNIC tlds" do
|
||||
assert_kind_of Parser::Fr, Parser.for("example.fr")
|
||||
end
|
||||
|
||||
test "should instanciate a parser class matching Verisign tlds" do
|
||||
assert_kind_of Parser::Verisign, Parser.for("example.com")
|
||||
assert_kind_of Parser::Verisign, Parser.for("example.net")
|
||||
end
|
||||
|
||||
test "should raises an exception when a domain is not supported" do
|
||||
assert_raises UnsupportedDomainError do
|
||||
Parser.for("example.xyz")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue