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 e3b7a39ee..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 },
@@ -76,6 +76,230 @@ 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