From e5979c4b2b92e51ac6e3801a838c1f96f05768d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Lecour?= Date: Thu, 28 Feb 2019 22:33:48 +0100 Subject: [PATCH] Add Sonic registry for .so TLD --- app/services/whois/parser.rb | 2 + app/services/whois/parser/sonic.rb | 47 ++++++++++ test/fixtures/files/whois/domain.so.txt | 90 +++++++++++++++++++ .../files/whois/willneverexist.so.txt | 47 ++++++++++ test/services/whois/parser/sonic_test.rb | 43 +++++++++ 5 files changed, 229 insertions(+) create mode 100644 app/services/whois/parser/sonic.rb create mode 100644 test/fixtures/files/whois/domain.so.txt create mode 100644 test/fixtures/files/whois/willneverexist.so.txt create mode 100644 test/services/whois/parser/sonic_test.rb diff --git a/app/services/whois/parser.rb b/app/services/whois/parser.rb index 263f17d..15fad75 100644 --- a/app/services/whois/parser.rb +++ b/app/services/whois/parser.rb @@ -7,6 +7,7 @@ require "whois/parser/afilias" require "whois/parser/afnic" require "whois/parser/cira" require "whois/parser/neustar" +require "whois/parser/sonic" require "whois/parser/verisign" module Whois @@ -16,6 +17,7 @@ module Whois AFNIC, CIRA, Neustar, + Sonic, Verisign, ].freeze diff --git a/app/services/whois/parser/sonic.rb b/app/services/whois/parser/sonic.rb new file mode 100644 index 0000000..a33b89b --- /dev/null +++ b/app/services/whois/parser/sonic.rb @@ -0,0 +1,47 @@ +# Copyright (C) 2018 Colin Darie , 2018 Evolix +# License: GNU AGPL-3+ (see full text in LICENSE file) + +require "domain_helper" +require "whois/errors" +require_relative "base" + +module Whois + module Parser + class Sonic < Base + # https://sonic.so + SUPPORTED_TLD = %w[ + .so + ].freeze + + COMMENT_REGEX = /^(%|>)+ +(?.+)$/ + FIELD_REGEX = /^(?[^:]+)\s*:\s+(?.+)$/ + + def self.supports?(domain) + SUPPORTED_TLD.include?(tld(domain)) + end + + protected + + def do_parse + raise_not_found if get_field("Domain Status", value: "No Object Found") + + 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 diff --git a/test/fixtures/files/whois/domain.so.txt b/test/fixtures/files/whois/domain.so.txt new file mode 100644 index 0000000..db79ccb --- /dev/null +++ b/test/fixtures/files/whois/domain.so.txt @@ -0,0 +1,90 @@ +% IANA WHOIS server +% for more information on IANA, visit http://www.iana.org +% This query returned 1 object + +refer: whois.nic.so + +domain: SO + +organisation: Ministry of Post and Telecommunications +address: Mogadishu +address: Somalia + +contact: administrative +name: Administrator +organisation: Ministry of Post and Telecommunications +address: Mogadishu +address: Somalia +phone: +252 1 587 1200 +fax-no: +252 1 231 599 +e-mail: admin@mipt.gov.so + +contact: technical +name: Tech Manager +organisation: soNIC +address: Via Republic +address: Mogadishu Benadir 1000 +address: Somalia +phone: +252 61 8250888 +fax-no: +252 61 8250991 +e-mail: admin@sonic.gov.so + +nserver: D.NIC.SO 196.216.168.54 2001:43f8:120:0:0:0:0:54 +nserver: E.NIC.SO 2001:500:14:6101:ad:0:0:1 204.61.216.101 + +whois: whois.nic.so + +status: ACTIVE +remarks: Registration information: http://www.nic.so/ + +created: 1997-08-28 +changed: 2016-04-18 +source: IANA + +Domain Name: domain.so +Domain ID: 35445-sonic +WHOIS Server: whois.nic.so +Updated Date: 2018-11-11T11:09:47.823Z +Creation Date: 2010-10-31T00:00:00.0Z +Registry Expiry Date: 2021-10-31T00:00:00.0Z +Domain Status: clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited +Domain Status: inactive https://icann.org/epp#inactive +Registrar: SONIC +Registrar Abuse Phone: +252.618250888 +Registrar Abuse Email: admin@sonic.gov.so +Registrant ID: 53306-sonic +Registrant Name: SONIC +Registrant Organization: 0 +Registrant Street: Via Republic +Registrant City: Mogadishu +Registrant State/Province: Benadir +Registrant Postal Code: 1000 +Registrant Country: SO +Registrant Phone: +252.618250888 +Registrant Fax: +252.618250991 +Registrant Email: admin@sonic.gov.so +Admin ID: 53306-sonic +Admin Name: SONIC +Admin Organization: 0 +Admin Street: Via Republic +Admin City: Mogadishu +Admin State/Province: Benadir +Admin Postal Code: 1000 +Admin Country: SO +Admin Phone: +252.618250888 +Admin Fax: +252.618250991 +Admin Email: admin@sonic.gov.so +Tech ID: 53306-sonic +Tech Name: SONIC +Tech Organization: 0 +Tech Street: Via Republic +Tech City: Mogadishu +Tech State/Province: Benadir +Tech Postal Code: 1000 +Tech Country: SO +Tech Phone: +252.618250888 +Tech Fax: +252.618250991 +Tech Email: admin@sonic.gov.so +DNSSEC: unsigned +>>> Last update of WHOIS database: 2019-02-28T21:14:58.920Z <<< + diff --git a/test/fixtures/files/whois/willneverexist.so.txt b/test/fixtures/files/whois/willneverexist.so.txt new file mode 100644 index 0000000..e45cba8 --- /dev/null +++ b/test/fixtures/files/whois/willneverexist.so.txt @@ -0,0 +1,47 @@ +% IANA WHOIS server +% for more information on IANA, visit http://www.iana.org +% This query returned 1 object + +refer: whois.nic.so + +domain: SO + +organisation: Ministry of Post and Telecommunications +address: Mogadishu +address: Somalia + +contact: administrative +name: Administrator +organisation: Ministry of Post and Telecommunications +address: Mogadishu +address: Somalia +phone: +252 1 587 1200 +fax-no: +252 1 231 599 +e-mail: admin@mipt.gov.so + +contact: technical +name: Tech Manager +organisation: soNIC +address: Via Republic +address: Mogadishu Benadir 1000 +address: Somalia +phone: +252 61 8250888 +fax-no: +252 61 8250991 +e-mail: admin@sonic.gov.so + +nserver: D.NIC.SO 196.216.168.54 2001:43f8:120:0:0:0:0:54 +nserver: E.NIC.SO 2001:500:14:6101:ad:0:0:1 204.61.216.101 + +whois: whois.nic.so + +status: ACTIVE +remarks: Registration information: http://www.nic.so/ + +created: 1997-08-28 +changed: 2016-04-18 +source: IANA + +Domain Name: willneverexist.so +Domain Status: No Object Found +>>> Last update of WHOIS database: 2019-02-28T21:14:58.920Z <<< + diff --git a/test/services/whois/parser/sonic_test.rb b/test/services/whois/parser/sonic_test.rb new file mode 100644 index 0000000..66a7f42 --- /dev/null +++ b/test/services/whois/parser/sonic_test.rb @@ -0,0 +1,43 @@ +# Copyright (C) 2018 Colin Darie , 2018 Evolix +# License: GNU AGPL-3+ (see full text in LICENSE file) + +require "test_helper" +require "whois/parser/sonic" +require "whois/response" +require "whois/errors" + +module Whois + class SonicTest < ActiveSupport::TestCase + test "should parse a whois response for .so" do + parser = Parser::Sonic.new("domain.so") + whois_output = file_fixture("whois/domain.so.txt").read + response = parser.parse(whois_output) + assert_kind_of Response, response + + assert_equal Time.new(2018, 11, 11, 11, 9, 47, 0), response.created_at + assert response.created_at.utc? + + assert_equal Time.new(2018, 12, 3, 21, 21, 22, 0), response.updated_at + assert_equal Time.new(2021, 10, 31, 0, 0, 0, 0), response.expire_at + end + + test "should raises DomainNotFoundError for .so when domain is not registered" do + parser = Parser::Sonic.new("willneverexist.so") + not_found = file_fixture("whois/willneverexist.so.txt").read + + assert_raises DomainNotFoundError do + parser.parse(not_found) + end + end + + test "should raises InvalidDateError for .so when a date is not parsable" do + parser = Parser::Sonic.new("domain.so") + whois_output = file_fixture("whois/domain.so.txt").read + whois_output.gsub!("2010-10-31T00:00:00.0Z", "not a date") + + assert_raises InvalidDateError do + parser.parse(whois_output) + end + end + end +end