diff --git a/app/controllers/epp/contacts_controller.rb b/app/controllers/epp/contacts_controller.rb index 85305213b..65354ff48 100644 --- a/app/controllers/epp/contacts_controller.rb +++ b/app/controllers/epp/contacts_controller.rb @@ -14,7 +14,7 @@ module Epp authorize! :check, Epp::Contact ids = params[:parsed_frame].css('id').map(&:text) - @results = Epp::Contact.check_availability(ids) + @results = Epp::Contact.check_availability(ids, reg: current_user.registrar.code) render_epp_response '/epp/contacts/check' end @@ -93,7 +93,11 @@ module Epp def find_contact code = params[:parsed_frame].css('id').text.strip.upcase - @contact = Epp::Contact.find_by!(code: code) + reg_code = current_user.registrar.code.upcase + arr = [code, "#{reg_code}:#{code}", "CID:#{code}", "CID:#{reg_code}:#{code}"] + + contact = arr.find { |c| Epp::Contact.find_by(code: c).present? } + @contact = Epp::Contact.find_by!(code: contact || code) end # diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 50ebac065..0c0ed3d5f 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -42,17 +42,12 @@ class Epp::Contact < Contact ) end - def check_availability(codes) + def check_availability(codes, reg:) codes = [codes] if codes.is_a?(String) - res = [] - codes.each do |x| - contact = find_by_epp_code(x) - if contact - res << { code: contact.code, avail: 0, reason: 'in use' } - else - res << { code: x, avail: 1 } - end + codes.map { |c| c.include?(':') ? c : "#{reg}:#{c}" }.map { |c| c.strip.upcase }.each do |x| + c = find_by_epp_code(x) + res << (c ? { code: c.code, avail: 0, reason: 'in use' } : { code: x, avail: 1 }) end res diff --git a/test/integration/epp/contact/check/base_test.rb b/test/integration/epp/contact/check/base_test.rb index 528d69d86..8f7e3df16 100644 --- a/test/integration/epp/contact/check/base_test.rb +++ b/test/integration/epp/contact/check/base_test.rb @@ -26,7 +26,7 @@ class EppContactCheckBaseTest < EppTestCase response_xml = Nokogiri::XML(response.body) assert_epp_response :completed_successfully - assert_equal 'john-001', response_xml.at_xpath('//contact:id', contact: xml_schema).text + assert_equal "#{@contact.registrar.code}:JOHN-001".upcase, response_xml.at_xpath('//contact:id', contact: xml_schema).text end def test_contact_is_available @@ -52,7 +52,8 @@ class EppContactCheckBaseTest < EppTestCase end def test_contact_is_unavailable - assert_equal 'john-001', @contact.code + @contact.update_columns(code: "#{@contact.registrar.code}:JOHN-001".upcase) + assert @contact.code, "#{@contact.registrar.code}:JOHN-001".upcase request_xml = <<-XML @@ -98,9 +99,61 @@ class EppContactCheckBaseTest < EppTestCase assert_equal 3, response_xml.xpath('//contact:cd', contact: xml_schema).size end + def test_check_contact_with_prefix + @contact.update_columns(code: "#{@contact.registrar.code}:JOHN-001".upcase) + assert @contact.code, "#{@contact.registrar.code}:JOHN-001".upcase + + request_xml = <<-XML + + + + + + BESTNAMES:JOHN-001 + + + + + XML + + post epp_check_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + response_xml = Nokogiri::XML(response.body) + assert_epp_response :completed_successfully + assert_equal "#{@contact.registrar.code}:JOHN-001".upcase, response_xml.at_xpath('//contact:id', contact: xml_schema).text + assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text + end + + def test_check_contact_without_prefix + @contact.update_columns(code: "#{@contact.registrar.code}:JOHN-001".upcase) + assert @contact.code, "#{@contact.registrar.code}:JOHN-001".upcase + + request_xml = <<-XML + + + + + + JOHN-001 + + + + + XML + + post epp_check_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + response_xml = Nokogiri::XML(response.body) + assert_epp_response :completed_successfully + assert_equal "#{@contact.registrar.code}:JOHN-001".upcase, response_xml.at_xpath('//contact:id', contact: xml_schema).text + assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text + end + private def xml_schema 'https://epp.tld.ee/schema/contact-ee-1.1.xsd' end -end \ No newline at end of file +end diff --git a/test/integration/epp/contact/info/base_test.rb b/test/integration/epp/contact/info/base_test.rb index 4e4a9190e..3edb6d461 100644 --- a/test/integration/epp/contact/info/base_test.rb +++ b/test/integration/epp/contact/info/base_test.rb @@ -44,6 +44,58 @@ class EppContactInfoBaseTest < EppTestCase contact: xml_schema).text end + def test_get_info_about_contact_with_prefix + @contact.update_columns(code: 'TEST:JOHN-001') + assert @contact.code, 'TEST:JOHN-001' + + request_xml = <<-XML + + + + + + TEST:JOHN-001 + + + + + 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 + assert_equal 'TEST:JOHN-001', response_xml.at_xpath('//contact:id', contact: xml_schema).text + assert_equal '+555.555', response_xml.at_xpath('//contact:voice', contact: xml_schema).text + end + + def test_get_info_about_contact_without_prefix + @contact.update_columns(code: "#{@contact.registrar.code}:JOHN-001".upcase) + assert @contact.code, "#{@contact.registrar.code}:JOHN-001".upcase + + request_xml = <<-XML + + + + + + JOHN-001 + + + + + 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 + assert_equal "#{@contact.registrar.code}:JOHN-001".upcase, response_xml.at_xpath('//contact:id', contact: xml_schema).text + assert_equal '+555.555', response_xml.at_xpath('//contact:voice', contact: xml_schema).text + end + def test_hides_password_and_name_when_current_registrar_is_not_sponsoring non_sponsoring_registrar = registrars(:goodnames) @contact.update!(registrar: non_sponsoring_registrar)