From 560d9111ce6fa917342cf479aff27f366ac121bb Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 26 Jan 2021 13:04:02 +0200 Subject: [PATCH 1/4] added tests for not unique contacts --- .../epp/domain/create/base_test.rb | 227 ++++++++++++++++++ 1 file changed, 227 insertions(+) diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb index e3b7a39ee..c0cef74b8 100644 --- a/test/integration/epp/domain/create/base_test.rb +++ b/test/integration/epp/domain/create/base_test.rb @@ -76,6 +76,233 @@ class EppDomainCreateBaseTest < EppTestCase assert_epp_response :required_parameter_missing end + def test_create_domain_with_unique_contact + now = Time.zone.parse('2010-07-05') + travel_to now + name = "new.#{dns_zones(:one).origin}" + contact = contacts(:john) + registrant = contact.becomes(Registrant) + + request_xml = <<-XML + + + + + + #{name} + #{registrant.code} + #{contacts(:jane).code} + #{contacts(:william).code} + + + + + #{'test' * 2000} + + + + + XML + + assert_difference 'Domain.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + assert_epp_response :completed_successfully + end + + + def test_create_domain_with_array_of_not_unique_admins_and_techs + now = Time.zone.parse('2010-07-05') + travel_to now + name = "new.#{dns_zones(:one).origin}" + contact = contacts(:john) + registrant = contact.becomes(Registrant) + + request_xml = <<-XML + + + + + + #{name} + #{registrant.code} + #{contact.code} + #{contact.code} + #{contact.code} + #{contact.code} + + + + + #{'test' * 2000} + + + + + XML + + + + assert_no_difference 'Domain.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + assert_epp_response :parameter_value_policy_error + end + + def test_create_domain_with_array_of_not_unique_admins + now = Time.zone.parse('2010-07-05') + travel_to now + name = "new.#{dns_zones(:one).origin}" + contact = contacts(:john) + registrant = contact.becomes(Registrant) + + request_xml = <<-XML + + + + + + #{name} + #{registrant.code} + #{contact.code} + #{contact.code} + #{contact.code} + + + + + #{'test' * 2000} + + + + + XML + + + + assert_no_difference 'Domain.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + + assert_epp_response :parameter_value_policy_error + end + + def test_create_domain_with_array_of_not_unique_techs + now = Time.zone.parse('2010-07-05') + travel_to now + name = "new.#{dns_zones(:one).origin}" + contact = contacts(:john) + registrant = contact.becomes(Registrant) + + request_xml = <<-XML + + + + + + #{name} + #{registrant.code} + #{contact.code} + #{contact.code} + #{contact.code} + + + + + #{'test' * 2000} + + + + + XML + + assert_no_difference 'Domain.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + + assert_epp_response :parameter_value_policy_error + end + + def test_create_domain_with_array_of_not_unique_admin_but_tech_another_one + now = Time.zone.parse('2010-07-05') + travel_to now + name = "new.#{dns_zones(:one).origin}" + contact = contacts(:john) + registrant = contact.becomes(Registrant) + contact_two = contacts(:william) + + request_xml = <<-XML + + + + + + #{name} + #{registrant.code} + #{contact.code} + #{contact.code} + #{contact_two.code} + + + + + #{'test' * 2000} + + + + + XML + + assert_no_difference 'Domain.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + + assert_epp_response :parameter_value_policy_error + end + + def test_create_domain_with_array_of_not_unique_techs_but_admin_another_one + now = Time.zone.parse('2010-07-05') + travel_to now + name = "new.#{dns_zones(:one).origin}" + contact = contacts(:john) + registrant = contact.becomes(Registrant) + contact_two = contacts(:william) + + request_xml = <<-XML + + + + + + #{name} + #{registrant.code} + #{contact_two.code} + #{contact.code} + #{contact.code} + + + + + #{'test' * 2000} + + + + + XML + + assert_no_difference 'Domain.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end + + assert_epp_response :parameter_value_policy_error + end + def test_registers_new_domain_with_required_attributes now = Time.zone.parse('2010-07-05') travel_to now From 3dfb22d79dd9023f9ab55ca623f62a732a9f7a07 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Thu, 28 Jan 2021 16:31:35 +0500 Subject: [PATCH 2/4] Return epp error 2306 is tech are admin contacts are duplicated --- app/models/epp/domain.rb | 8 +++ .../epp/domain/create/base_test.rb | 53 +++++++++---------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index c4d70c2ee..ad96adc64 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -162,6 +162,9 @@ class Epp::Domain < Domain at[:admin_domain_contacts_attributes] = admin_domain_contacts_attrs(frame, action) at[:tech_domain_contacts_attributes] = tech_domain_contacts_attrs(frame, action) + check_for_same_contacts(at[:admin_domain_contacts_attributes], 'admin') + check_for_same_contacts(at[:tech_domain_contacts_attributes], 'tech') + pw = frame.css('authInfo > pw').text at[:transfer_code] = pw if pw.present? @@ -176,6 +179,11 @@ class Epp::Domain < Domain at end + def check_for_same_contacts(contacts, contact_type) + return unless contacts.uniq.count != contacts.count + + add_epp_error('2306', contact_type, nil, %i[domain_contacts invalid]) + end # Adding legal doc to domain and # if something goes wrong - raise Rollback error diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb index c0cef74b8..cbbd8a57d 100644 --- a/test/integration/epp/domain/create/base_test.rb +++ b/test/integration/epp/domain/create/base_test.rb @@ -120,34 +120,33 @@ class EppDomainCreateBaseTest < EppTestCase registrant = contact.becomes(Registrant) request_xml = <<-XML - - - - - - #{name} - #{registrant.code} - #{contact.code} - #{contact.code} - #{contact.code} - #{contact.code} - - - - - #{'test' * 2000} - - - - - XML + + + + + + #{name} + #{registrant.code} + #{contact.code} + #{contact.code} + #{contact.code} + #{contact.code} + + + + + #{'test' * 2000} + + + + + XML - - - assert_no_difference 'Domain.count' do - post epp_create_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + assert_no_difference 'Domain.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end + assert_epp_response :parameter_value_policy_error end @@ -180,7 +179,7 @@ class EppDomainCreateBaseTest < EppTestCase XML - + assert_no_difference 'Domain.count' do post epp_create_path, params: { frame: request_xml }, From 2648f66e78c1eefc012e2266a9228b74c4d36cc0 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 28 Jan 2021 14:09:07 +0200 Subject: [PATCH 3/4] made refactoring: remove paddings and line breaks --- .../epp/domain/create/base_test.rb | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb index cbbd8a57d..9f974ebf8 100644 --- a/test/integration/epp/domain/create/base_test.rb +++ b/test/integration/epp/domain/create/base_test.rb @@ -104,9 +104,9 @@ class EppDomainCreateBaseTest < EppTestCase XML - assert_difference 'Domain.count' do - post epp_create_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + assert_difference 'Domain.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end assert_epp_response :completed_successfully end @@ -181,9 +181,9 @@ class EppDomainCreateBaseTest < EppTestCase - assert_no_difference 'Domain.count' do - post epp_create_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + assert_no_difference 'Domain.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end assert_epp_response :parameter_value_policy_error @@ -218,12 +218,12 @@ class EppDomainCreateBaseTest < EppTestCase XML - assert_no_difference 'Domain.count' do - post epp_create_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + assert_no_difference 'Domain.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end - assert_epp_response :parameter_value_policy_error + assert_epp_response :parameter_value_policy_error end def test_create_domain_with_array_of_not_unique_admin_but_tech_another_one @@ -254,14 +254,14 @@ class EppDomainCreateBaseTest < EppTestCase - XML + XML - assert_no_difference 'Domain.count' do - post epp_create_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } - end + assert_no_difference 'Domain.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end - assert_epp_response :parameter_value_policy_error + assert_epp_response :parameter_value_policy_error end def test_create_domain_with_array_of_not_unique_techs_but_admin_another_one @@ -292,14 +292,14 @@ class EppDomainCreateBaseTest < EppTestCase - XML + XML - assert_no_difference 'Domain.count' do - post epp_create_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } - end + assert_no_difference 'Domain.count' do + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end - assert_epp_response :parameter_value_policy_error + assert_epp_response :parameter_value_policy_error end def test_registers_new_domain_with_required_attributes From 18c994256f8d75a2f36845451beedea4f24892d1 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Thu, 28 Jan 2021 14:16:39 +0200 Subject: [PATCH 4/4] xml padding changed --- .../epp/domain/create/base_test.rb | 244 +++++++++--------- 1 file changed, 121 insertions(+), 123 deletions(-) diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb index 9f974ebf8..35ef38179 100644 --- a/test/integration/epp/domain/create/base_test.rb +++ b/test/integration/epp/domain/create/base_test.rb @@ -13,30 +13,30 @@ class EppDomainCreateBaseTest < EppTestCase vrjxNMH6HtxW\rEA4RJ9Ao6LCWheg8" request_xml = <<-XML - - - - - - #{name} - #{registrant.code} - - - - - - 257 - 3 - 8 - #{pub_key} - - - - #{'test' * 2000} - - - - + + + + + + #{name} + #{registrant.code} + + + + + + 257 + 3 + 8 + #{pub_key} + + + + #{'test' * 2000} + + + + XML assert_no_difference 'Domain.count' do post epp_create_path, params: { frame: request_xml }, @@ -84,25 +84,25 @@ class EppDomainCreateBaseTest < EppTestCase registrant = contact.becomes(Registrant) request_xml = <<-XML - - - - - - #{name} - #{registrant.code} - #{contacts(:jane).code} - #{contacts(:william).code} - - - - - #{'test' * 2000} - - - - - XML + + + + + + #{name} + #{registrant.code} + #{contacts(:jane).code} + #{contacts(:william).code} + + + + + #{'test' * 2000} + + + + + XML assert_difference 'Domain.count' do post epp_create_path, params: { frame: request_xml }, @@ -158,28 +158,26 @@ class EppDomainCreateBaseTest < EppTestCase registrant = contact.becomes(Registrant) request_xml = <<-XML - - - - - - #{name} - #{registrant.code} - #{contact.code} - #{contact.code} - #{contact.code} - - - - - #{'test' * 2000} - - - - - XML - - + + + + + + #{name} + #{registrant.code} + #{contact.code} + #{contact.code} + #{contact.code} + + + + + #{'test' * 2000} + + + + + XML assert_no_difference 'Domain.count' do post epp_create_path, params: { frame: request_xml }, @@ -197,26 +195,26 @@ class EppDomainCreateBaseTest < EppTestCase registrant = contact.becomes(Registrant) request_xml = <<-XML - - - - - - #{name} - #{registrant.code} - #{contact.code} - #{contact.code} - #{contact.code} - - - - - #{'test' * 2000} - - - - - XML + + + + + + #{name} + #{registrant.code} + #{contact.code} + #{contact.code} + #{contact.code} + + + + + #{'test' * 2000} + + + + + XML assert_no_difference 'Domain.count' do post epp_create_path, params: { frame: request_xml }, @@ -235,25 +233,25 @@ class EppDomainCreateBaseTest < EppTestCase contact_two = contacts(:william) request_xml = <<-XML - - - - - - #{name} - #{registrant.code} - #{contact.code} - #{contact.code} - #{contact_two.code} - - - - - #{'test' * 2000} - - - - + + + + + + #{name} + #{registrant.code} + #{contact.code} + #{contact.code} + #{contact_two.code} + + + + + #{'test' * 2000} + + + + XML assert_no_difference 'Domain.count' do @@ -273,25 +271,25 @@ class EppDomainCreateBaseTest < EppTestCase contact_two = contacts(:william) request_xml = <<-XML - - - - - - #{name} - #{registrant.code} - #{contact_two.code} - #{contact.code} - #{contact.code} - - - - - #{'test' * 2000} - - - - + + + + + + #{name} + #{registrant.code} + #{contact_two.code} + #{contact.code} + #{contact.code} + + + + + #{'test' * 2000} + + + + XML assert_no_difference 'Domain.count' do