mirror of
https://github.com/Evolix/chexpire.git
synced 2024-05-05 02:05:09 +02:00
Whois: intercept domain not found
This commit is contained in:
parent
123bec60af
commit
62a53314c5
|
@ -3,6 +3,7 @@ module Whois
|
|||
|
||||
class WhoisCommandError < WhoisError; end
|
||||
class UnsupportedDomainError < WhoisError; end
|
||||
class DomainNotFoundError < WhoisError; end
|
||||
class ParserError < WhoisError; end
|
||||
|
||||
class FieldNotFoundError < ParserError; end
|
||||
|
|
|
@ -31,6 +31,7 @@ module Whois
|
|||
response
|
||||
rescue StandardError => ex
|
||||
logger.log :parser_error, ex
|
||||
raise
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -57,6 +58,16 @@ module Whois
|
|||
end
|
||||
end
|
||||
|
||||
def comment_include?(str)
|
||||
entries.any? { |e|
|
||||
e.comment? && e.text? && e.text.include?(str)
|
||||
}
|
||||
end
|
||||
|
||||
def raise_not_found
|
||||
fail DomainNotFoundError, "Domain #{domain} not found in the registry database."
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_entries(raw)
|
||||
|
|
|
@ -24,6 +24,10 @@ module Whois
|
|||
def field?
|
||||
false
|
||||
end
|
||||
|
||||
def text?
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,6 +10,10 @@ module Whois
|
|||
super index
|
||||
@text = text.strip
|
||||
end
|
||||
|
||||
def text?
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,43 +1,52 @@
|
|||
require "domain_helper"
|
||||
require "whois/errors"
|
||||
require_relative "base"
|
||||
|
||||
module Whois::Parser
|
||||
class Fr < Base
|
||||
SUPPORTED_TLD = %w[.fr].freeze
|
||||
COMMENT_REGEX = /^%+ +(?<text>.+)$/
|
||||
FIELD_REGEX = /^(?<name>[^:]+)\s*:\s+(?<value>.+)$/
|
||||
module Whois
|
||||
module Parser
|
||||
class Fr < Base
|
||||
SUPPORTED_TLD = %w[.fr].freeze
|
||||
COMMENT_REGEX = /^%+ +(?<text>.+)$/
|
||||
FIELD_REGEX = /^(?<name>[^:]+)\s*:\s+(?<value>.+)$/
|
||||
|
||||
def self.supports?(domain)
|
||||
SUPPORTED_TLD.include?(tld(domain))
|
||||
end
|
||||
def self.supports?(domain)
|
||||
SUPPORTED_TLD.include?(tld(domain))
|
||||
end
|
||||
|
||||
protected
|
||||
protected
|
||||
|
||||
def do_parse
|
||||
set_date_format
|
||||
def do_parse
|
||||
raise_not_found if comment_include?("No entries found")
|
||||
|
||||
domain_index = get_field!("domain", value: domain).index
|
||||
set_date_format
|
||||
|
||||
created_date = get_value!("created", after: domain_index)
|
||||
response.created_at = parse_date(created_date)
|
||||
extract_values
|
||||
end
|
||||
|
||||
expire_date = get_value!("Expiry Date", after: domain_index)
|
||||
response.expire_at = parse_date(expire_date)
|
||||
private
|
||||
|
||||
updated_date = get_value!("last-update", after: domain_index)
|
||||
response.updated_at = parse_date(updated_date)
|
||||
end
|
||||
def extract_values
|
||||
domain_index = get_field!("domain", value: domain).index
|
||||
|
||||
private
|
||||
created_date = get_value!("created", after: domain_index)
|
||||
response.created_at = parse_date(created_date)
|
||||
|
||||
def parse_date(str)
|
||||
super "#{str} UTC"
|
||||
end
|
||||
expire_date = get_value!("Expiry Date", after: domain_index)
|
||||
response.expire_at = parse_date(expire_date)
|
||||
|
||||
def set_date_format
|
||||
afnic_format = get_field!("complete date format").value
|
||||
updated_date = get_value!("last-update", after: domain_index)
|
||||
response.updated_at = parse_date(updated_date)
|
||||
end
|
||||
|
||||
@date_format = "%d/%m/%Y %Z" if afnic_format == "DD/MM/YYYY"
|
||||
def parse_date(str)
|
||||
super "#{str} UTC"
|
||||
end
|
||||
|
||||
def set_date_format
|
||||
afnic_format = get_field!("complete date format").value
|
||||
|
||||
@date_format = "%d/%m/%Y %Z" if afnic_format == "DD/MM/YYYY"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
71
test/fixtures/files/whois/willneverexist.fr.txt
vendored
Normal file
71
test/fixtures/files/whois/willneverexist.fr.txt
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
% IANA WHOIS server
|
||||
% for more information on IANA, visit http://www.iana.org
|
||||
% This query returned 1 object
|
||||
|
||||
refer: whois.nic.fr
|
||||
|
||||
domain: FR
|
||||
|
||||
organisation: Association Française pour le Nommage Internet en Coopération (A.F.N.I.C.)
|
||||
address: Immeuble Le Stephenson
|
||||
address: 1 rue Stephenson
|
||||
address: 78180 Montigny-le-Bretonneux
|
||||
address: France
|
||||
|
||||
contact: administrative
|
||||
name: TLD Admin Contact
|
||||
organisation: Association Française pour le Nommage Internet en Coopération (A.F.N.I.C.)
|
||||
address: Immeuble Le Stephenson
|
||||
address: 1 rue Stephenson
|
||||
address: 78180 Montigny-le-Bretonneux
|
||||
address: France
|
||||
phone: +33 1 39 30 83 05
|
||||
fax-no: +33 1 39 30 83 01
|
||||
e-mail: tld-admin@nic.fr
|
||||
|
||||
contact: technical
|
||||
name: TLD Tech Contact
|
||||
organisation: Association Française pour le Nommage Internet en Coopération (A.F.N.I.C.)
|
||||
address: Immeuble Le Stephenson
|
||||
address: 1 rue Stephenson
|
||||
address: 78180 Montigny-le-Bretonneux
|
||||
address: France
|
||||
phone: +33 1 39 30 83 81
|
||||
fax-no: +33 1 39 30 83 01
|
||||
e-mail: tld-tech@nic.fr
|
||||
|
||||
nserver: D.EXT.NIC.FR 192.5.4.2 2001:500:2e:0:0:0:0:2
|
||||
nserver: D.NIC.FR 194.0.9.1 2001:678:c:0:0:0:0:1
|
||||
nserver: E.EXT.NIC.FR 193.176.144.22 2a00:d78:0:102:193:176:144:22
|
||||
nserver: F.EXT.NIC.FR 194.146.106.46 2001:67c:1010:11:0:0:0:53
|
||||
nserver: G.EXT.NIC.FR 194.0.36.1 2001:678:4c:0:0:0:0:1
|
||||
ds-rdata: 35095 8 2 23c6caadc9927ee98061f2b52c9b8da6b53f3f648f814a4a86a0faf9843e2c4e
|
||||
ds-rdata: 42104 8 2 8D913A49C3FA2A39BA0065B4E18BA793E3AD128F7C6C8AA008AEFE0A14435DD5
|
||||
|
||||
whois: whois.nic.fr
|
||||
|
||||
status: ACTIVE
|
||||
remarks: Registration information: http://www.nic.fr/
|
||||
|
||||
created: 1986-09-02
|
||||
changed: 2018-01-22
|
||||
source: IANA
|
||||
|
||||
%%
|
||||
%% This is the AFNIC Whois server.
|
||||
%%
|
||||
%% complete date format : DD/MM/YYYY
|
||||
%% short date format : DD/MM
|
||||
%% version : FRNIC-2.5
|
||||
%%
|
||||
%% Rights restricted by copyright.
|
||||
%% See https://www.afnic.fr/en/products-and-services/services/whois/whois-special-notice/
|
||||
%%
|
||||
%% Use '-h' option to obtain more information about this service.
|
||||
%%
|
||||
%% [11.22.33.44 REQUEST] >> willneverexist.fr
|
||||
%%
|
||||
%% RL Net [##########] - RL IP [#########.]
|
||||
%%
|
||||
|
||||
%% No entries found in the AFNIC Database.
|
|
@ -1,16 +1,14 @@
|
|||
require "test_helper"
|
||||
require "whois/parser/fr"
|
||||
require "whois/response"
|
||||
require "whois/errors"
|
||||
|
||||
module Whois
|
||||
class FrTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@parser = Parser::Fr.new("domain.fr")
|
||||
@domain_fr = file_fixture("whois/domain.fr.txt").read
|
||||
end
|
||||
|
||||
test "should parse a whois response" do
|
||||
response = @parser.parse(@domain_fr)
|
||||
parser = Parser::Fr.new("domain.fr")
|
||||
domain_fr = file_fixture("whois/domain.fr.txt").read
|
||||
response = parser.parse(domain_fr)
|
||||
assert_kind_of Response, response
|
||||
|
||||
assert_equal Time.new(2004, 2, 18, 0, 0, 0, 0), response.created_at
|
||||
|
@ -19,5 +17,14 @@ module Whois
|
|||
assert_equal Time.new(2017, 1, 28, 0, 0, 0, 0), response.updated_at
|
||||
assert_equal Time.new(2019, 2, 17, 0, 0, 0, 0), response.expire_at
|
||||
end
|
||||
|
||||
test "should raises DomainNotFoundError when domain is not registered" do
|
||||
parser = Parser::Fr.new("willneverexist.fr")
|
||||
not_found_fr = file_fixture("whois/willneverexist.fr.txt").read
|
||||
|
||||
assert_raises DomainNotFoundError do
|
||||
parser.parse(not_found_fr)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue