From ac50634a00d7de60caf000bc71bebd75db224252 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 4 Feb 2021 13:59:52 +0200 Subject: [PATCH 1/6] added tests for getting info from contact without prefix --- .../integration/epp/contact/info/base_test.rb | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/integration/epp/contact/info/base_test.rb b/test/integration/epp/contact/info/base_test.rb index 4e4a9190e..6b04d98a2 100644 --- a/test/integration/epp/contact/info/base_test.rb +++ b/test/integration/epp/contact/info/base_test.rb @@ -44,6 +44,56 @@ class EppContactInfoBaseTest < EppTestCase contact: xml_schema).text end + def test_get_info_about_contact_with_prefix + @contact.update_columns(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: 'TEST:JOHN-001') + + 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 '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_hides_password_and_name_when_current_registrar_is_not_sponsoring non_sponsoring_registrar = registrars(:goodnames) @contact.update!(registrar: non_sponsoring_registrar) From 8f4f2509ef607ab86d0761d40cf7a4ef199ac8a8 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 4 Feb 2021 14:02:48 +0200 Subject: [PATCH 2/6] mend --- .ruby-version | 2 +- test/integration/epp/contact/info/base_test.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index 37c2961c2..57cf282eb 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.2 +2.6.5 diff --git a/test/integration/epp/contact/info/base_test.rb b/test/integration/epp/contact/info/base_test.rb index 6b04d98a2..4b4cb017f 100644 --- a/test/integration/epp/contact/info/base_test.rb +++ b/test/integration/epp/contact/info/base_test.rb @@ -46,6 +46,7 @@ class EppContactInfoBaseTest < EppTestCase def test_get_info_about_contact_with_prefix @contact.update_columns(code: 'TEST:JOHN-001') + assert @contact.code, 'TEST:JOHN-001' request_xml = <<-XML @@ -71,6 +72,7 @@ class EppContactInfoBaseTest < EppTestCase def test_get_info_about_contact_without_prefix @contact.update_columns(code: 'TEST:JOHN-001') + assert @contact.code, 'TEST:JOHN-001' request_xml = <<-XML From 1bdfcef36b91e0fa2d9abc7daa1754d6b2571ac3 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 4 Feb 2021 14:04:03 +0200 Subject: [PATCH 3/6] Revert "mend" This reverts commit 8f4f2509ef607ab86d0761d40cf7a4ef199ac8a8. --- .ruby-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index 57cf282eb..37c2961c2 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.6.5 +2.7.2 From c7b40450184f959472bd25bc1017a593eb1e7ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 9 Feb 2021 11:46:47 +0200 Subject: [PATCH 4/6] Contact: Append prefix unless present --- app/controllers/epp/contacts_controller.rb | 6 +++++- test/integration/epp/contact/info/base_test.rb | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/epp/contacts_controller.rb b/app/controllers/epp/contacts_controller.rb index 85305213b..a0c3f503f 100644 --- a/app/controllers/epp/contacts_controller.rb +++ b/app/controllers/epp/contacts_controller.rb @@ -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/test/integration/epp/contact/info/base_test.rb b/test/integration/epp/contact/info/base_test.rb index 4b4cb017f..3edb6d461 100644 --- a/test/integration/epp/contact/info/base_test.rb +++ b/test/integration/epp/contact/info/base_test.rb @@ -71,8 +71,8 @@ class EppContactInfoBaseTest < EppTestCase end def test_get_info_about_contact_without_prefix - @contact.update_columns(code: 'TEST:JOHN-001') - assert @contact.code, 'TEST:JOHN-001' + @contact.update_columns(code: "#{@contact.registrar.code}:JOHN-001".upcase) + assert @contact.code, "#{@contact.registrar.code}:JOHN-001".upcase request_xml = <<-XML @@ -92,7 +92,7 @@ class EppContactInfoBaseTest < EppTestCase 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 "#{@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 From 43ff03e6e147c65620363d8c6356f15879c1f4fd Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 10 Feb 2021 10:42:59 +0200 Subject: [PATCH 5/6] added test for check --- .../epp/contact/check/base_test.rb | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/test/integration/epp/contact/check/base_test.rb b/test/integration/epp/contact/check/base_test.rb index 528d69d86..3fc9f64ac 100644 --- a/test/integration/epp/contact/check/base_test.rb +++ b/test/integration/epp/contact/check/base_test.rb @@ -98,6 +98,58 @@ 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: 'TEST:JOHN-001') + assert @contact.code, 'TEST:JOHN-001' + + request_xml = <<-XML + + + + + + TEST: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 'TEST:JOHN-001', 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 'TEST:JOHN-001', 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 From 0617ef9d7d3e82b3785fcf0520a4149a165a51e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Wed, 10 Feb 2021 12:03:22 +0200 Subject: [PATCH 6/6] Fix contact code check --- app/controllers/epp/contacts_controller.rb | 2 +- app/models/epp/contact.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/epp/contacts_controller.rb b/app/controllers/epp/contacts_controller.rb index a0c3f503f..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 diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index 50ebac065..edc828f81 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -42,8 +42,9 @@ class Epp::Contact < Contact ) end - def check_availability(codes) + def check_availability(codes, reg:) codes = [codes] if codes.is_a?(String) + codes = codes.map { |c| c.include?(':') ? c : "#{reg}:#{c}" } res = [] codes.each do |x|