diff --git a/app/controllers/registrar/xml_consoles_controller.rb b/app/controllers/registrar/xml_consoles_controller.rb index b55339d1e..06177491d 100644 --- a/app/controllers/registrar/xml_consoles_controller.rb +++ b/app/controllers/registrar/xml_consoles_controller.rb @@ -1,15 +1,22 @@ class Registrar class XmlConsolesController < DeppController + PREFS = %w[ + domain-ee + contact-ee + eis + epp-ee + ].freeze + authorize_resource class: false - def show - end + def show; end def create begin @result = depp_current_user.server.request(params[:payload]) - checking_schema_valid_path(params[:payload]) - rescue + + check_schema_path(params[:payload]) + rescue StandardError @result = 'CONNECTION ERROR - Is the EPP server running?' end render :show @@ -19,31 +26,78 @@ class Registrar cl_trid = "#{depp_current_user.tag}-#{Time.zone.now.to_i}" xml_dir_path = Rails.root + 'app/views/registrar/xml_consoles/epp_requests' xml = File.read("#{xml_dir_path}/#{params[:obj]}/#{params[:epp_action]}.xml") - xml.gsub!('ABC-12345', "#{cl_trid}") + xml = prepare_payload(xml, cl_trid) + render plain: xml end - private + protected - def checking_schema_valid_path(payload) - path = regex_to_find_domain_schema(payload) + def check_schema_path(payload) + path = nil + path = regex_to_find_domain_schema(payload) if regex_to_find_domain_schema(payload).present? + path = regex_to_find_contact_schema(payload) if regex_to_find_contact_schema(payload).present? + path = regex_to_find_poll_schema(payload) if regex_to_find_poll_schema(payload).present? - @result = template_wrong_path unless array_valid_paths.include? path - end + @result = wrong_path_response unless array_valid_paths.include? path + end - def array_valid_paths - Xsd::Schema::PREFIXES.map{|prefix| Xsd::Schema.filename(for_prefix: prefix)} - end + def array_valid_paths + Xsd::Schema::PREFIXES.map { |prefix| Xsd::Schema.filename(for_prefix: prefix) } + end - def template_wrong_path - 'Wrong schema path' + def wrong_path_response + cl_trid = "#{depp_current_user.tag}-#{Time.zone.now.to_i}" + + <<~XML + + + + + Wrong schema + + + #{cl_trid} + eePrx-#{Time.zone.now.to_i} + + + + XML end def regex_to_find_domain_schema(payload) - domain_schema_tag = payload.scan(/xmlns:domain[\S]+/) - schema_path = domain_schema_tag.to_s.match(/https?:\/\/[\S]+/)[0] - path = schema_path.split('\\')[0] - path + domain_schema_tag = payload.scan(/xmlns:domain\S+/) + return if domain_schema_tag.empty? + + schema_path = domain_schema_tag.to_s.match(%r{https?://\S+})[0] + schema_path.split('\\')[0] + end + + def regex_to_find_contact_schema(payload) + contact_schema_tag = payload.scan(/xmlns:contact\S+/) + return if contact_schema_tag.empty? + + schema_path = contact_schema_tag.to_s.match(%r{https?://\S+})[0] + schema_path.split('\\')[0] + end + + def regex_to_find_poll_schema(payload) + contact_schema_tag = payload.scan(/poll\S+/) + return if contact_schema_tag.empty? + + 'https://epp.tld.ee/schema/epp-ee-1.0.xsd' + end + + def prepare_payload(xml, cl_trid) + PREFS.map do |pref| + xml.gsub!('"' + pref.to_s + '"', + "\"#{Xsd::Schema.filename(for_prefix: pref.to_s)}\"") + end + + xml.gsub!('ABC-12345', "#{cl_trid}") + xml end end end diff --git a/app/views/registrar/xml_consoles/epp_requests/contact/check.xml b/app/views/registrar/xml_consoles/epp_requests/contact/check.xml index f8d6e05ce..f4c10d8bd 100644 --- a/app/views/registrar/xml_consoles/epp_requests/contact/check.xml +++ b/app/views/registrar/xml_consoles/epp_requests/contact/check.xml @@ -1,9 +1,9 @@ - + + xmlns:contact="contact-ee"> sh8013 diff --git a/app/views/registrar/xml_consoles/epp_requests/contact/check_multiple.xml b/app/views/registrar/xml_consoles/epp_requests/contact/check_multiple.xml index b71871ed1..bdcff03dd 100644 --- a/app/views/registrar/xml_consoles/epp_requests/contact/check_multiple.xml +++ b/app/views/registrar/xml_consoles/epp_requests/contact/check_multiple.xml @@ -1,9 +1,9 @@ - + + xmlns:contact="contact-ee"> sh8013 sh13 vsdfvq diff --git a/app/views/registrar/xml_consoles/epp_requests/contact/create.xml b/app/views/registrar/xml_consoles/epp_requests/contact/create.xml index 2607a7582..fc60b8311 100644 --- a/app/views/registrar/xml_consoles/epp_requests/contact/create.xml +++ b/app/views/registrar/xml_consoles/epp_requests/contact/create.xml @@ -1,8 +1,8 @@ - + - + Sillius Soddus @@ -20,7 +20,7 @@ - + 123 dGVzdCBmYWlsCg== diff --git a/app/views/registrar/xml_consoles/epp_requests/contact/delete.xml b/app/views/registrar/xml_consoles/epp_requests/contact/delete.xml index 2d2e483a2..28b50af64 100644 --- a/app/views/registrar/xml_consoles/epp_requests/contact/delete.xml +++ b/app/views/registrar/xml_consoles/epp_requests/contact/delete.xml @@ -1,9 +1,9 @@ - + + xmlns:contact="contact-ee"> sh8013 wrong-one @@ -11,7 +11,7 @@ - + dGVzdCBmYWlsCg== diff --git a/app/views/registrar/xml_consoles/epp_requests/contact/info.xml b/app/views/registrar/xml_consoles/epp_requests/contact/info.xml index 01685a3a1..44e5d5a1e 100644 --- a/app/views/registrar/xml_consoles/epp_requests/contact/info.xml +++ b/app/views/registrar/xml_consoles/epp_requests/contact/info.xml @@ -1,8 +1,8 @@ - + - + sh8013 Aas34fq diff --git a/app/views/registrar/xml_consoles/epp_requests/contact/update_chg.xml b/app/views/registrar/xml_consoles/epp_requests/contact/update_chg.xml index e7fa45dde..61ea43202 100644 --- a/app/views/registrar/xml_consoles/epp_requests/contact/update_chg.xml +++ b/app/views/registrar/xml_consoles/epp_requests/contact/update_chg.xml @@ -1,8 +1,8 @@ - + - + sh8013 @@ -25,7 +25,7 @@ - + dGVzdCBmYWlsCg== diff --git a/app/views/registrar/xml_consoles/epp_requests/domain/check.xml b/app/views/registrar/xml_consoles/epp_requests/domain/check.xml index 4cb77bf7f..06492bcfe 100644 --- a/app/views/registrar/xml_consoles/epp_requests/domain/check.xml +++ b/app/views/registrar/xml_consoles/epp_requests/domain/check.xml @@ -1,9 +1,9 @@ - + + xmlns:domain="domain-ee"> example.ee diff --git a/app/views/registrar/xml_consoles/epp_requests/domain/client_hold.xml b/app/views/registrar/xml_consoles/epp_requests/domain/client_hold.xml index 0963708a4..68f0b778e 100644 --- a/app/views/registrar/xml_consoles/epp_requests/domain/client_hold.xml +++ b/app/views/registrar/xml_consoles/epp_requests/domain/client_hold.xml @@ -1,9 +1,9 @@ - + + xmlns:domain="domain-ee"> example.ee diff --git a/app/views/registrar/xml_consoles/epp_requests/domain/create.xml b/app/views/registrar/xml_consoles/epp_requests/domain/create.xml index 4e3aa82f0..f57fcfe30 100644 --- a/app/views/registrar/xml_consoles/epp_requests/domain/create.xml +++ b/app/views/registrar/xml_consoles/epp_requests/domain/create.xml @@ -1,9 +1,9 @@ - + + xmlns:domain="domain-ee"> example.ee 1 @@ -31,7 +31,7 @@ AwEAAddt2AkLfYGKgiEZB5SmIF8EvrjxNMH6HtxWEA4RJ9Ao6LCWheg8 - + dGVzdCBmYWlsCg== diff --git a/app/views/registrar/xml_consoles/epp_requests/domain/delete.xml b/app/views/registrar/xml_consoles/epp_requests/domain/delete.xml index 20d739380..f47bb79eb 100644 --- a/app/views/registrar/xml_consoles/epp_requests/domain/delete.xml +++ b/app/views/registrar/xml_consoles/epp_requests/domain/delete.xml @@ -1,14 +1,14 @@ - + + xmlns:domain="domain-ee"> example.ee - + dGVzdCBmYWlsCg== diff --git a/app/views/registrar/xml_consoles/epp_requests/domain/info.xml b/app/views/registrar/xml_consoles/epp_requests/domain/info.xml index 1643d73af..210396c3b 100644 --- a/app/views/registrar/xml_consoles/epp_requests/domain/info.xml +++ b/app/views/registrar/xml_consoles/epp_requests/domain/info.xml @@ -1,9 +1,9 @@ - + + xmlns:domain="domain-ee"> example.ee 2fooBAR diff --git a/app/views/registrar/xml_consoles/epp_requests/domain/renew.xml b/app/views/registrar/xml_consoles/epp_requests/domain/renew.xml index 192c6b5cc..6ef479468 100644 --- a/app/views/registrar/xml_consoles/epp_requests/domain/renew.xml +++ b/app/views/registrar/xml_consoles/epp_requests/domain/renew.xml @@ -1,9 +1,9 @@ - + + xmlns:domain="domain-ee"> example.ee 2014-08-07 1 diff --git a/app/views/registrar/xml_consoles/epp_requests/domain/transfer.xml b/app/views/registrar/xml_consoles/epp_requests/domain/transfer.xml index 20646f08f..f6ee87b79 100644 --- a/app/views/registrar/xml_consoles/epp_requests/domain/transfer.xml +++ b/app/views/registrar/xml_consoles/epp_requests/domain/transfer.xml @@ -1,9 +1,9 @@ - + + xmlns:domain="domain-ee"> example.ee 2BARfoo @@ -11,7 +11,7 @@ - + dGVzdCBmYWlsCg== diff --git a/app/views/registrar/xml_consoles/epp_requests/domain/update.xml b/app/views/registrar/xml_consoles/epp_requests/domain/update.xml index 45363baf7..c087245e7 100644 --- a/app/views/registrar/xml_consoles/epp_requests/domain/update.xml +++ b/app/views/registrar/xml_consoles/epp_requests/domain/update.xml @@ -1,9 +1,9 @@ - + + xmlns:domain="domain-ee"> example.ee @@ -43,7 +43,7 @@ - + dGVzdCBmYWlsCg== diff --git a/app/views/registrar/xml_consoles/epp_requests/poll/poll.xml b/app/views/registrar/xml_consoles/epp_requests/poll/poll.xml index abf77ae19..5ffed010e 100644 --- a/app/views/registrar/xml_consoles/epp_requests/poll/poll.xml +++ b/app/views/registrar/xml_consoles/epp_requests/poll/poll.xml @@ -1,5 +1,5 @@ - + ABC-12345 diff --git a/test/integration/registrar_area/xml_consoles_test.rb b/test/integration/registrar_area/xml_consoles_test.rb new file mode 100644 index 000000000..3d3a617f9 --- /dev/null +++ b/test/integration/registrar_area/xml_consoles_test.rb @@ -0,0 +1,112 @@ +require 'test_helper' + +class RegistrarXmlConsolesIntegrationTest < ApplicationIntegrationTest + setup do + sign_in users(:api_bestnames) + end + + def test_check_schema_path + post registrar_xml_console_path, params: { payload: payload, frame: payload }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + assert_response :ok + end + + def test_load_schema_path + get load_xml_registrar_xml_console_path, params: { obj: 'domain', epp_action: 'update' } + + assert_response :ok + assert_equal update_payload, response.body + end + + private + + def payload + <<~XML + + + + + + auction.test + + + + + XML + end + + def wrong_payload + <<~XML + + + + + + auction.test + + + + + XML + end + + def update_payload + <<~XML + + + + + + example.ee + + + + ns1.example.com + + + ns2.example.com + + + mak21 + + + + + ns1.example.net + + + mak21 + + + mak21 + + newpw + + + + + + + + + 257 + 3 + 8 + 700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f + + + + + + dGVzdCBmYWlsCg== + + + + test_bestnames-#{Time.zone.now.to_i} + + + XML + end +end diff --git a/test/system/registrar_area/xml_consoles_test.rb b/test/system/registrar_area/xml_consoles_test.rb new file mode 100644 index 000000000..836498e46 --- /dev/null +++ b/test/system/registrar_area/xml_consoles_test.rb @@ -0,0 +1,37 @@ +require 'application_system_test_case' + +class RegistrarAreaXmlConsolesTest < ApplicationSystemTestCase + + setup do + sign_in users(:api_bestnames) + end + +# CodeRay + + def test_epp_server_does_not_response + visit registrar_xml_console_path + fill_in 'payload', with: schema_example + click_on 'Send EPP Request' + + el = page.find('.CodeRay', visible: :all) + assert el.text.include? 'CONNECTION ERROR - Is the EPP server running?' + end + + private + + def schema_example + request_xml = <<~XML + + + + + + auction.test + + + + + XML + end + +end \ No newline at end of file