From 36a53bd11a10534ce229fa4ee8c75d74335e9b8c Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 1 Feb 2019 13:20:58 +0200 Subject: [PATCH 1/5] Handle blocked and reserved domains in EPP domain:info Closes #597 --- app/controllers/epp/domains_controller.rb | 42 ++++++++++------ app/models/dns/domain_name.rb | 16 ++++-- .../registered_domain.xml.builder} | 0 .../info/unregistered_domain.xml.builder | 16 ++++++ test/integration/epp/domain/info/base_test.rb | 50 +++++++++++++++++++ test/models/dns/domain_name_test.rb | 12 +++++ 6 files changed, 117 insertions(+), 19 deletions(-) rename app/views/epp/domains/{info.xml.builder => info/registered_domain.xml.builder} (100%) create mode 100644 app/views/epp/domains/info/unregistered_domain.xml.builder diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index 65ee56306..4500566b0 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -4,9 +4,9 @@ class Epp::DomainsController < EppController skip_authorization_check only: :info def info - if Domain.release_to_auction - domain_name = DNS::DomainName.new(params[:parsed_frame].at_css('name').text.strip.downcase) + domain_name = DNS::DomainName.new(params[:parsed_frame].at_css('name').text.strip.downcase) + if Domain.release_to_auction if domain_name.at_auction? @name = domain_name @status = 'At auction' @@ -25,22 +25,34 @@ class Epp::DomainsController < EppController end end - find_domain - find_password - authorize! :info, @domain, @password + if domain_name.registered? + find_domain + find_password + authorize! :info, @domain, @password - @hosts = params[:parsed_frame].css('name').first['hosts'] || 'all' + @hosts = params[:parsed_frame].css('name').first['hosts'] || 'all' - case @hosts - when 'del' - @nameservers = @domain.delegated_nameservers.sort - when 'sub' - @nameservers = @domain.subordinate_nameservers.sort - when 'all' - @nameservers = @domain.nameservers.sort + case @hosts + when 'del' + @nameservers = @domain.delegated_nameservers.sort + when 'sub' + @nameservers = @domain.subordinate_nameservers.sort + when 'all' + @nameservers = @domain.nameservers.sort + end + + render_epp_response '/epp/domains/info/registered_domain' + else + if domain_name.blocked? + @name = domain_name + @status = 'Blocked' + render_epp_response '/epp/domains/info/unregistered_domain' + elsif domain_name.reserved? + @name = domain_name + @status = 'Reserved' + render_epp_response '/epp/domains/info/unregistered_domain' + end end - - render_epp_response '/epp/domains/info' end def create diff --git a/app/models/dns/domain_name.rb b/app/models/dns/domain_name.rb index be7ece5c6..090454093 100644 --- a/app/models/dns/domain_name.rb +++ b/app/models/dns/domain_name.rb @@ -57,10 +57,6 @@ module DNS name end - private - - attr_reader :name - def registered? Domain.find_by_idn(name) end @@ -69,6 +65,18 @@ module DNS BlockedDomain.where(name: name).any? end + def reserved? + ReservedDomain.where(name: name).any? + end + + def to_s + name + end + + private + + attr_reader :name + def zone_with_same_origin? DNS::Zone.where(origin: name).any? end diff --git a/app/views/epp/domains/info.xml.builder b/app/views/epp/domains/info/registered_domain.xml.builder similarity index 100% rename from app/views/epp/domains/info.xml.builder rename to app/views/epp/domains/info/registered_domain.xml.builder diff --git a/app/views/epp/domains/info/unregistered_domain.xml.builder b/app/views/epp/domains/info/unregistered_domain.xml.builder new file mode 100644 index 000000000..a34dfa51a --- /dev/null +++ b/app/views/epp/domains/info/unregistered_domain.xml.builder @@ -0,0 +1,16 @@ +xml.epp_head do + xml.response do + xml.result code: '1000' do + xml.msg 'Command completed successfully' + end + + xml.resData do + xml.tag! 'domain:infData', 'xmlns:domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd' do + xml.tag! 'domain:name', @name + xml.tag! 'domain:status', 's' => @status + end + end + + render 'epp/shared/trID', builder: xml + end +end \ No newline at end of file diff --git a/test/integration/epp/domain/info/base_test.rb b/test/integration/epp/domain/info/base_test.rb index a112ed840..93f04a476 100644 --- a/test/integration/epp/domain/info/base_test.rb +++ b/test/integration/epp/domain/info/base_test.rb @@ -106,4 +106,54 @@ class EppDomainInfoBaseTest < ApplicationIntegrationTest assert_nil response_xml.at_xpath('//domain:authInfo/domain:pw', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd') end + + def test_blocked_domain + assert_equal 'blocked.test', blocked_domains(:one).name + + request_xml = <<-XML + + + + + + blocked.test + + + + + XML + + post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' + + response_xml = Nokogiri::XML(response.body) + assert_equal '1000', response_xml.at_css('result')[:code] + assert_equal 1, response_xml.css('result').size + assert_equal 'blocked.test', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text + assert_equal 'Blocked', response_xml.at_xpath('//domain:status', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['s'] + end + + def test_reserved_domain + assert_equal 'reserved.test', reserved_domains(:one).name + + request_xml = <<-XML + + + + + + reserved.test + + + + + XML + + post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' + + response_xml = Nokogiri::XML(response.body) + assert_equal '1000', response_xml.at_css('result')[:code] + assert_equal 1, response_xml.css('result').size + assert_equal 'reserved.test', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text + assert_equal 'Reserved', response_xml.at_xpath('//domain:status', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['s'] + end end diff --git a/test/models/dns/domain_name_test.rb b/test/models/dns/domain_name_test.rb index 0fdd81d34..e1e9df79e 100644 --- a/test/models/dns/domain_name_test.rb +++ b/test/models/dns/domain_name_test.rb @@ -111,4 +111,16 @@ class DNS::DomainNameTest < ActiveSupport::TestCase domain_name = DNS::DomainName.new('shop.test') assert_equal 'shop.test', domain_name.to_s end + + def test_blocked + assert_equal 'blocked.test', blocked_domains(:one).name + assert DNS::DomainName.new('blocked.test').blocked? + assert_not DNS::DomainName.new('nonblocked .test').blocked? + end + + def test_reserved + assert_equal 'reserved.test', reserved_domains(:one).name + assert DNS::DomainName.new('reserved.test').reserved? + assert_not DNS::DomainName.new('unreserved.test').reserved? + end end From 9fab0a3000a9436eacaee392bfef4604352ada40 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 1 Feb 2019 13:25:21 +0200 Subject: [PATCH 2/5] Remove useless comments --- .../epp/domains/info/registered_domain.xml.builder | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/app/views/epp/domains/info/registered_domain.xml.builder b/app/views/epp/domains/info/registered_domain.xml.builder index 850334955..3272b7ea4 100644 --- a/app/views/epp/domains/info/registered_domain.xml.builder +++ b/app/views/epp/domains/info/registered_domain.xml.builder @@ -34,8 +34,6 @@ xml.epp_head do end end - ## TODO Find out what this domain:host is all about - xml.tag!('domain:clID', @domain.registrar.code) xml.tag!('domain:crID', @domain.cr_id) @@ -43,16 +41,13 @@ xml.epp_head do if @domain.updated_at > @domain.created_at upID = @domain.updator.try(:registrar) - upID = upID.code if upID.present? # Did updator return a kind of User that has a registrar? - xml.tag!('domain:upID', upID) if upID.present? # optional upID + upID = upID.code if upID.present? + xml.tag!('domain:upID', upID) if upID.present? xml.tag!('domain:upDate', @domain.updated_at.try(:iso8601)) end xml.tag!('domain:exDate', @domain.valid_to.iso8601) - # TODO Make domain transferrable - #xml.tag!('domain:trDate', @domain.transferred_at) if @domain.transferred_at - if can? :view_password, @domain, @password xml.tag!('domain:authInfo') do xml.tag!('domain:pw', @domain.transfer_code) @@ -65,7 +60,6 @@ xml.epp_head do ds_data = Setting.ds_data_allowed ? @domain.dnskeys.find_all { |key| key.ds_digest.present? } : [] key_data = Setting.key_data_allowed ? @domain.dnskeys.find_all { |key| key.public_key.present? } : [] - # is there any reason to include without xml.extension do def tag_key_data(xml, key) xml.tag!('secDNS:keyData') do From 22e1523a99a062d4d018b8fc2cbec1648c24bb15 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 1 Feb 2019 13:28:18 +0200 Subject: [PATCH 3/5] Reformat --- .../info/registered_domain.xml.builder | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/views/epp/domains/info/registered_domain.xml.builder b/app/views/epp/domains/info/registered_domain.xml.builder index 3272b7ea4..eb1234934 100644 --- a/app/views/epp/domains/info/registered_domain.xml.builder +++ b/app/views/epp/domains/info/registered_domain.xml.builder @@ -5,7 +5,7 @@ xml.epp_head do end xml.resData do - xml.tag!('domain:infData', 'xmlns:domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd') do + xml.tag! 'domain:infData', 'xmlns:domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd' do xml.tag!('domain:name', @domain.name) xml.tag!('domain:roid', @domain.roid) @domain.statuses.each do |s| @@ -27,8 +27,13 @@ xml.epp_head do @nameservers.each do |x| xml.tag!('domain:hostAttr') do xml.tag!('domain:hostName', x.hostname) - x.ipv4.each{|ip| xml.tag!('domain:hostAddr', ip, 'ip' => 'v4') } if x.ipv4.present? - x.ipv6.each{|ip| xml.tag!('domain:hostAddr', ip, 'ip' => 'v6') } if x.ipv6.present? + if x.ipv4.present? + x.ipv4.each { |ip| xml.tag!('domain:hostAddr', ip, 'ip' => 'v4') } + end + + if x.ipv6.present? + x.ipv6.each { |ip| xml.tag!('domain:hostAddr', ip, 'ip' => 'v6') } + end end end end @@ -40,8 +45,8 @@ xml.epp_head do xml.tag!('domain:crDate', @domain.created_at.try(:iso8601)) if @domain.updated_at > @domain.created_at - upID = @domain.updator.try(:registrar) - upID = upID.code if upID.present? + upID = @domain.updator.try(:registrar) + upID = upID.code if upID.present? xml.tag!('domain:upID', upID) if upID.present? xml.tag!('domain:upDate', @domain.updated_at.try(:iso8601)) end @@ -57,8 +62,10 @@ xml.epp_head do end if @domain.dnskeys.any? - ds_data = Setting.ds_data_allowed ? @domain.dnskeys.find_all { |key| key.ds_digest.present? } : [] - key_data = Setting.key_data_allowed ? @domain.dnskeys.find_all { |key| key.public_key.present? } : [] + ds_data = Setting.ds_data_allowed ? + @domain.dnskeys.find_all { |key| key.ds_digest.present? } : [] + key_data = Setting.key_data_allowed ? + @domain.dnskeys.find_all { |key| key.public_key.present? } : [] xml.extension do def tag_key_data(xml, key) From 2862dd81d1cded8d45d8cfcc1b9ad3326ad422ff Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Fri, 1 Feb 2019 13:55:55 +0200 Subject: [PATCH 4/5] Fix variable name --- app/views/epp/domains/info/registered_domain.xml.builder | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/epp/domains/info/registered_domain.xml.builder b/app/views/epp/domains/info/registered_domain.xml.builder index eb1234934..5424b73d4 100644 --- a/app/views/epp/domains/info/registered_domain.xml.builder +++ b/app/views/epp/domains/info/registered_domain.xml.builder @@ -45,9 +45,9 @@ xml.epp_head do xml.tag!('domain:crDate', @domain.created_at.try(:iso8601)) if @domain.updated_at > @domain.created_at - upID = @domain.updator.try(:registrar) - upID = upID.code if upID.present? - xml.tag!('domain:upID', upID) if upID.present? + updator = @domain.updator.try(:registrar) + updator = updator.code if updator.present? + xml.tag!('domain:upID', updator) if updator.present? xml.tag!('domain:upDate', @domain.updated_at.try(:iso8601)) end From b81c971b3757c0bc31aec8a654eea7d23020d2bd Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 18 Feb 2019 15:05:52 +0200 Subject: [PATCH 5/5] Refactor --- app/controllers/epp/domains_controller.rb | 24 +++++++++---------- app/models/dns/domain_name.rb | 4 ---- .../epp/domains/info_auction.xml.builder | 16 ------------- 3 files changed, 11 insertions(+), 33 deletions(-) delete mode 100644 app/views/epp/domains/info_auction.xml.builder diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index 4500566b0..d9504a71d 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -10,17 +10,17 @@ class Epp::DomainsController < EppController if domain_name.at_auction? @name = domain_name @status = 'At auction' - render_epp_response '/epp/domains/info_auction' + render_epp_response '/epp/domains/info/unregistered_domain' return elsif domain_name.awaiting_payment? @name = domain_name @status = 'Awaiting payment' - render_epp_response '/epp/domains/info_auction' + render_epp_response '/epp/domains/info/unregistered_domain' return elsif domain_name.pending_registration? @name = domain_name @status = 'Reserved' - render_epp_response '/epp/domains/info_auction' + render_epp_response '/epp/domains/info/unregistered_domain' return end end @@ -42,16 +42,14 @@ class Epp::DomainsController < EppController end render_epp_response '/epp/domains/info/registered_domain' - else - if domain_name.blocked? - @name = domain_name - @status = 'Blocked' - render_epp_response '/epp/domains/info/unregistered_domain' - elsif domain_name.reserved? - @name = domain_name - @status = 'Reserved' - render_epp_response '/epp/domains/info/unregistered_domain' - end + elsif domain_name.blocked? + @name = domain_name + @status = 'Blocked' + render_epp_response '/epp/domains/info/unregistered_domain' + elsif domain_name.reserved? + @name = domain_name + @status = 'Reserved' + render_epp_response '/epp/domains/info/unregistered_domain' end end diff --git a/app/models/dns/domain_name.rb b/app/models/dns/domain_name.rb index 090454093..05eea2086 100644 --- a/app/models/dns/domain_name.rb +++ b/app/models/dns/domain_name.rb @@ -53,10 +53,6 @@ module DNS Whois::Record.refresh(self) end - def to_s - name - end - def registered? Domain.find_by_idn(name) end diff --git a/app/views/epp/domains/info_auction.xml.builder b/app/views/epp/domains/info_auction.xml.builder deleted file mode 100644 index b95553935..000000000 --- a/app/views/epp/domains/info_auction.xml.builder +++ /dev/null @@ -1,16 +0,0 @@ -xml.epp_head do - xml.response do - xml.result('code' => '1000') do - xml.msg 'Command completed successfully' - end - - xml.resData do - xml.tag! 'domain:infData', 'xmlns:domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd' do - xml.tag!('domain:name', @name) - xml.tag!('domain:status', 's' => @status) - end - end - - render('epp/shared/trID', builder: xml) - end -end