diff --git a/Gemfile b/Gemfile index 4fdce6e61..8385bbb27 100644 --- a/Gemfile +++ b/Gemfile @@ -62,7 +62,7 @@ gem 'omniauth-tara', github: 'internetee/omniauth-tara' gem 'epp', github: 'internetee/epp', branch: :master -gem 'epp-xml', '1.1.0', github: 'internetee/epp-xml', branch: 'update-paths-for-new-domain-schema' +gem 'epp-xml', '1.2.0', github: 'internetee/epp-xml', branch: '11-flexible-paths-for-schemes' gem 'que' gem 'daemons-rails', '1.2.1' gem 'que-web' diff --git a/Gemfile.lock b/Gemfile.lock index a21a15879..8e3f8880a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -28,10 +28,10 @@ GIT GIT remote: https://github.com/internetee/epp-xml.git - revision: 687514dc239d22b29d0138d83c909d70d19dc06d - branch: update-paths-for-new-domain-schema + revision: b821c16a002722709a0fdf3d1aa23606ed7d62ff + branch: 11-flexible-paths-for-schemes specs: - epp-xml (1.1.0) + epp-xml (1.2.0) activesupport (>= 4.1) builder (~> 3.2) @@ -541,7 +541,7 @@ DEPENDENCIES domain_name e_invoice! epp! - epp-xml (= 1.1.0)! + epp-xml (= 1.2.0)! figaro (~> 1.2) haml (~> 5.0) isikukood @@ -584,4 +584,4 @@ DEPENDENCIES wkhtmltopdf-binary (~> 0.12.5.1) BUNDLED WITH - 2.2.19 + 2.2.20 diff --git a/app/models/depp/domain.rb b/app/models/depp/domain.rb index 3bb3b7473..d4a7f94be 100644 --- a/app/models/depp/domain.rb +++ b/app/models/depp/domain.rb @@ -32,7 +32,7 @@ module Depp def initialize(args = {}) self.current_user = args[:current_user] - self.epp_xml = EppXml::Domain.new(cl_trid_prefix: current_user.tag) + self.epp_xml = EppXml::Domain.new(cl_trid_prefix: current_user.tag, schema_prefix: 'domain-ee', schema_version: '1.1') end def info(domain_name) diff --git a/lib/epp_constraint.rb b/lib/epp_constraint.rb index a0ad72719..c1b13ef85 100644 --- a/lib/epp_constraint.rb +++ b/lib/epp_constraint.rb @@ -1,7 +1,10 @@ class EppConstraint OBJECT_TYPES = { - domain: { domain: Xsd::Schema.filename(for_prefix: 'domain-ee') }, - contact: { contact: Xsd::Schema.filename(for_prefix: 'contact-ee') }, + domain: [ + { domain: Xsd::Schema.filename(for_prefix: 'domain-ee') }, + { domain: Xsd::Schema.filename(for_prefix: 'domain-eis') } + ], + contact: { contact: Xsd::Schema.filename(for_prefix: 'contact-ee') } }.freeze def initialize(type) @@ -13,13 +16,25 @@ class EppConstraint # TODO: Maybe move this to controller to keep params clean return redirect_to_error_controller(request) if request.params[:action] == 'wrong_schema' - request.params[:raw_frame] = request.params[:raw_frame].gsub!(/(?<=>)(.*?)(?=<)/) { |s| s.strip} if request.params[:raw_frame] + if request.params[:raw_frame] + request.params[:raw_frame] = request.params[:raw_frame].gsub!(/(?<=>)(.*?)(?=<)/) do |s| + s.strip + end + end request.params[:nokogiri_frame] ||= Nokogiri::XML(request.params[:raw_frame] || request.params[:frame]) request.params[:parsed_frame] ||= request.params[:nokogiri_frame].dup.remove_namespaces! unless %i[poll session].include?(@type) element = "//#{@type}:#{request.params[:action]}" - return false if request.params[:nokogiri_frame].xpath("#{element}", OBJECT_TYPES[@type]).none? + + if @type == :domain + OBJECT_TYPES[@type].each do |obj| + return true unless request.params[:nokogiri_frame].xpath(element.to_s, obj).none? + end + return false + end + + return false if request.params[:nokogiri_frame].xpath(element.to_s, OBJECT_TYPES[@type]).none? end request.params[:epp_object_type] = @type diff --git a/test/integration/epp/domain/info/base_test.rb b/test/integration/epp/domain/info/base_test.rb index 04f8f4ef0..214cdfb6f 100644 --- a/test/integration/epp/domain/info/base_test.rb +++ b/test/integration/epp/domain/info/base_test.rb @@ -22,18 +22,67 @@ class EppDomainInfoBaseTest < EppTestCase XML post epp_info_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } response_xml = Nokogiri::XML(response.body) assert_epp_response :completed_successfully assert assert_schema_is_bigger(response_xml, 'domain-ee', 1.1) - assert_equal 'shop.test', response_xml.at_xpath('//domain:name', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text - assert_equal 'ok', response_xml.at_xpath('//domain:status', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}")['s'] - assert_equal 'john-001', response_xml.at_xpath('//domain:registrant', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text - assert_equal '2010-07-05T00:00:00+03:00', response_xml.at_xpath('//domain:crDate', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text - assert_equal '2010-07-06T00:00:00+03:00', response_xml.at_xpath('//domain:upDate', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text - assert_equal '2010-07-07T00:00:00+03:00', response_xml.at_xpath('//domain:exDate', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text + assert_equal 'shop.test', + response_xml.at_xpath('//domain:name', + 'domain' => Xsd::Schema.filename(for_prefix: 'domain-ee').to_s).text + assert_equal 'ok', + response_xml.at_xpath('//domain:status', + 'domain' => Xsd::Schema.filename(for_prefix: 'domain-ee').to_s)['s'] + assert_equal 'john-001', + response_xml.at_xpath('//domain:registrant', + 'domain' => Xsd::Schema.filename(for_prefix: 'domain-ee').to_s).text + assert_equal '2010-07-05T00:00:00+03:00', + response_xml.at_xpath('//domain:crDate', + 'domain' => Xsd::Schema.filename(for_prefix: 'domain-ee').to_s).text + assert_equal '2010-07-06T00:00:00+03:00', + response_xml.at_xpath('//domain:upDate', + 'domain' => Xsd::Schema.filename(for_prefix: 'domain-ee').to_s).text + assert_equal '2010-07-07T00:00:00+03:00', + response_xml.at_xpath('//domain:exDate', + 'domain' => Xsd::Schema.filename(for_prefix: 'domain-ee').to_s).text + end + + def test_returns_valid_response_if_schema_version_is_previous + dispute = disputes(:expired) + dispute.update!(starts_at: Time.zone.now, expires_at: Time.zone.now + 5.days, closed: nil) + + domain = domains(:shop) + domain.update_columns(statuses: [DomainStatus::DISPUTED], + created_at: Time.zone.parse('2010-07-05'), + updated_at: Time.zone.parse('2010-07-06'), + creator_str: 'test', + valid_to: Time.zone.parse('2010-07-07')) + + domain.versions.destroy_all + + request_xml = <<-XML + + + + + + shop.test + + + + + XML + + post epp_info_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + response_xml = Nokogiri::XML(response.body) + assert_epp_response :completed_successfully + schema = EPP_ALL_SCHEMA + + schema_validation_errors = schema.validate(response_xml) + assert_equal 0, schema_validation_errors.size end def test_returns_valid_response_if_disputed @@ -63,14 +112,13 @@ class EppDomainInfoBaseTest < EppTestCase XML post epp_info_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } response_xml = Nokogiri::XML(response.body) assert_epp_response :completed_successfully schema = EPP_ALL_SCHEMA schema_validation_errors = schema.validate(response_xml) - p schema_validation_errors assert_equal 0, schema_validation_errors.size end @@ -95,7 +143,7 @@ class EppDomainInfoBaseTest < EppTestCase XML post epp_info_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } response_xml = Nokogiri::XML(response.body) assert_epp_response :completed_successfully @@ -122,10 +170,12 @@ class EppDomainInfoBaseTest < EppTestCase XML post epp_info_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } response_xml = Nokogiri::XML(response.body) - assert_equal '65078d5', response_xml.at_xpath('//domain:authInfo/domain:pw', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text + assert_equal '65078d5', + response_xml.at_xpath('//domain:authInfo/domain:pw', + 'domain' => Xsd::Schema.filename(for_prefix: 'domain-ee').to_s).text end # Transfer code is the only info we conceal from other registrars, hence a bit oddly-looking @@ -150,10 +200,12 @@ class EppDomainInfoBaseTest < EppTestCase XML post epp_info_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } + headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } response_xml = Nokogiri::XML(response.body) - assert_equal '65078d5', response_xml.at_xpath('//domain:authInfo/domain:pw', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text + assert_equal '65078d5', + response_xml.at_xpath('//domain:authInfo/domain:pw', + 'domain' => Xsd::Schema.filename(for_prefix: 'domain-ee').to_s).text end def test_conceals_transfer_code_when_domain_is_not_owned_by_current_user @@ -174,10 +226,10 @@ class EppDomainInfoBaseTest < EppTestCase XML post epp_info_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } + headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } response_xml = Nokogiri::XML(response.body) assert_nil response_xml.at_xpath('//domain:authInfo/domain:pw', - 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}") + 'domain' => Xsd::Schema.filename(for_prefix: 'domain-ee').to_s) end end