21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-05-06 02:35:11 +02:00
chexpire/test/services/whois/parser/sonic_test.rb

45 lines
1.6 KiB
Ruby
Raw Normal View History

2019-02-28 22:33:48 +01:00
# Copyright (C) 2018 Colin Darie <colin@darie.eu>, 2018 Evolix <info@evolix.fr>
# License: GNU AGPL-3+ (see full text in LICENSE file)
require "test_helper"
module Whois
class SonicTest < ActiveSupport::TestCase
test "should parse a whois response for .so" do
2019-03-03 11:03:04 +01:00
parser = Whois::Parser::Sonic.new("domain.so")
2019-02-28 22:33:48 +01:00
whois_output = file_fixture("whois/domain.so.txt").read
response = parser.parse(whois_output)
2019-03-03 11:03:04 +01:00
assert_kind_of Whois::Response, response
2019-02-28 22:33:48 +01:00
2019-02-28 23:27:56 +01:00
assert_equal Time.new(2010, 10, 31, 0, 0, 0, 0), response.created_at
2019-02-28 22:33:48 +01:00
assert response.created_at.utc?
2019-02-28 23:27:56 +01:00
# We can't use Time.new here
# Sonic times have subseconds and the parsed version
# is different than the generated time (which doesn't have
# subseconds).
assert_equal Time.parse("2018-11-11T11:09:47.823Z"), response.updated_at
2019-02-28 22:33:48 +01:00
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
2019-03-03 11:03:04 +01:00
parser = Whois::Parser::Sonic.new("willneverexist.so")
2019-02-28 22:33:48 +01:00
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
2019-03-03 11:03:04 +01:00
parser = Whois::Parser::Sonic.new("domain.so")
2019-02-28 22:33:48 +01:00
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