diff --git a/app/models/concerns/roids.rb b/app/models/concerns/roids.rb new file mode 100644 index 000000000..0178a397c --- /dev/null +++ b/app/models/concerns/roids.rb @@ -0,0 +1,24 @@ +module Roids + extend ActiveSupport::Concern + ID_CHAR_LIMIT = 8 + + included do + def roid + id_size = id.to_s.size + if id_size <= ID_CHAR_LIMIT + "EIS-#{id}" + else + roid_with_prefix(id_size) + end + end + + private + + def roid_with_prefix(id_size) + id_delta = id_size - ID_CHAR_LIMIT + id_prefix = id.to_s.split(//).first(id_delta).join('').to_s + id_postfix = id.to_s.split(//).last(id_size - id_delta).join('').to_s + "EIS#{id_prefix}-#{id_postfix}" + end + end +end diff --git a/app/models/concerns/user_events.rb b/app/models/concerns/user_events.rb index 25a225e8b..afce650fe 100644 --- a/app/models/concerns/user_events.rb +++ b/app/models/concerns/user_events.rb @@ -21,7 +21,7 @@ module UserEvents Registrar.find(cr_registrar_id).code else # cr_id optional for domain, but required for contact; but we want something here anyway - self.creator_str # Fallback if we failed, maybe we can find a string here + self.creator_str || self.registrar.code # Fallback end end end diff --git a/app/models/contact.rb b/app/models/contact.rb index c6e3e22ba..b6b1e979b 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -2,6 +2,7 @@ require 'deserializers/xml/legal_document' class Contact < ApplicationRecord include Versions # version/contact_version.rb + include Roids include EppErrors include UserEvents include Contact::Transferable @@ -259,10 +260,6 @@ class Contact < ApplicationRecord end end - def roid - "EIS-#{id}" - end - # kind of decorator in order to always return statuses # if we use separate decorator, then we should add it # to too many places diff --git a/app/models/domain.rb b/app/models/domain.rb index 83e9044fe..5601167a2 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -1,5 +1,6 @@ class Domain < ApplicationRecord include UserEvents + include Roids include Versions # version/domain_version.rb include Domain::Expirable include Domain::Activatable @@ -33,8 +34,6 @@ class Domain < ApplicationRecord has_many :tech_domain_contacts accepts_nested_attributes_for :tech_domain_contacts, allow_destroy: true, reject_if: :tech_change_prohibited? - ID_CHAR_LIMIT = 8 - def registrant_change_prohibited? statuses.include? DomainStatus::SERVER_REGISTRANT_CHANGE_PROHIBITED end @@ -332,15 +331,6 @@ class Domain < ApplicationRecord domain end - def roid - id_size = id.to_s.size - if id_size <= ID_CHAR_LIMIT - "EIS-#{id}" - else - roid_with_prefix(id_size) - end - end - def puny_label name_puny.to_s.split('.').first end @@ -741,13 +731,4 @@ class Domain < ApplicationRecord def self.uses_zone?(zone) exists?(["name ILIKE ?", "%.#{zone.origin}"]) end - - private - - def roid_with_prefix(id_size) - id_delta = id_size - ID_CHAR_LIMIT - id_prefix = id.to_s.split(//).first(id_delta).join('').to_s - id_postfix = id.to_s.split(//).last(id_size - id_delta).join('').to_s - "EIS#{id_prefix}-#{id_postfix}" - end end diff --git a/test/integration/epp/contact/check/base_test.rb b/test/integration/epp/contact/check/base_test.rb index 104bc1b86..549cdf3ae 100644 --- a/test/integration/epp/contact/check/base_test.rb +++ b/test/integration/epp/contact/check/base_test.rb @@ -25,6 +25,7 @@ class EppContactCheckBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully assert_equal "#{@contact.registrar.code}:JOHN-001".upcase, response_xml.at_xpath('//contact:id', contact: xml_schema).text end @@ -47,6 +48,7 @@ class EppContactCheckBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_equal '1', response_xml.at_xpath('//contact:id', contact: xml_schema)['avail'] assert_nil response_xml.at_xpath('//contact:reason', contact: xml_schema) end @@ -72,6 +74,7 @@ class EppContactCheckBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_equal '0', response_xml.at_xpath('//contact:id', contact: xml_schema)['avail'] assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text end @@ -96,6 +99,7 @@ class EppContactCheckBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_equal 3, response_xml.xpath('//contact:cd', contact: xml_schema).size end @@ -120,6 +124,7 @@ class EppContactCheckBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml 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 @@ -146,6 +151,7 @@ class EppContactCheckBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml 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 diff --git a/test/integration/epp/contact/create/base_test.rb b/test/integration/epp/contact/create/base_test.rb index 12b784025..cc91a74a0 100644 --- a/test/integration/epp/contact/create/base_test.rb +++ b/test/integration/epp/contact/create/base_test.rb @@ -33,6 +33,8 @@ class EppContactCreateBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully contact = Contact.find_by(name: name) assert_equal name, contact.name @@ -74,6 +76,8 @@ class EppContactCreateBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :parameter_value_syntax_error end @@ -109,6 +113,8 @@ class EppContactCreateBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :parameter_value_syntax_error end @@ -143,6 +149,8 @@ class EppContactCreateBaseTest < EppTestCase post epp_create_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => "session=#{session.session_id}" } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml contact = Contact.find_by(name: name) assert_equal "#{session.user.registrar.code}:#{code}".upcase, contact.code end @@ -174,6 +182,8 @@ class EppContactCreateBaseTest < EppTestCase post epp_create_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :required_parameter_missing end @@ -216,6 +226,8 @@ class EppContactCreateBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_without_address contact = Contact.find_by(name: name) assert_equal name, contact.name @@ -275,6 +287,8 @@ class EppContactCreateBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully contact = Contact.find_by(name: name) assert_equal name, contact.name diff --git a/test/integration/epp/contact/delete/base_test.rb b/test/integration/epp/contact/delete/base_test.rb index 6171ad00a..a90974189 100644 --- a/test/integration/epp/contact/delete/base_test.rb +++ b/test/integration/epp/contact/delete/base_test.rb @@ -24,6 +24,9 @@ class EppContactDeleteBaseTest < EppTestCase post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end + + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully end @@ -50,6 +53,8 @@ class EppContactDeleteBaseTest < EppTestCase post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert Contact.exists?(id: contact.id) assert_epp_response :object_status_prohibits_operation end @@ -77,6 +82,8 @@ class EppContactDeleteBaseTest < EppTestCase post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert Contact.exists?(id: contact.id) assert_epp_response :object_status_prohibits_operation end @@ -105,6 +112,8 @@ class EppContactDeleteBaseTest < EppTestCase post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :object_association_prohibits_operation end diff --git a/test/integration/epp/contact/info/base_test.rb b/test/integration/epp/contact/info/base_test.rb index 5c4a99b2f..b43273a88 100644 --- a/test/integration/epp/contact/info/base_test.rb +++ b/test/integration/epp/contact/info/base_test.rb @@ -33,6 +33,7 @@ class EppContactInfoBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully assert_equal 'JOHN-001', response_xml.at_xpath('//contact:id', contact: xml_schema).text assert_equal 'ok', response_xml.at_xpath('//contact:status', contact: xml_schema)['s'] @@ -65,6 +66,7 @@ class EppContactInfoBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml 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 @@ -91,6 +93,7 @@ class EppContactInfoBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml 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 @@ -121,6 +124,7 @@ class EppContactInfoBaseTest < EppTestCase assert_epp_response :completed_successfully response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_nil response_xml.at_xpath('//contact:authInfo', contact: xml_schema) assert_equal 'No access', response_xml.at_xpath('//contact:name', contact: xml_schema).text end diff --git a/test/integration/epp/contact/transfer/base_test.rb b/test/integration/epp/contact/transfer/base_test.rb index b1cc86a69..cf28c32c7 100644 --- a/test/integration/epp/contact/transfer/base_test.rb +++ b/test/integration/epp/contact/transfer/base_test.rb @@ -19,6 +19,8 @@ class EppContactTransferBaseTest < EppTestCase post epp_transfer_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :unimplemented end end diff --git a/test/integration/epp/contact/update/base_test.rb b/test/integration/epp/contact/update/base_test.rb index 1c02746ff..081d37c05 100644 --- a/test/integration/epp/contact/update/base_test.rb +++ b/test/integration/epp/contact/update/base_test.rb @@ -41,6 +41,8 @@ class EppContactUpdateBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } @contact.reload + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully assert_equal 'new name', @contact.name assert_equal 'new-email@inbox.test', @contact.email @@ -73,6 +75,8 @@ class EppContactUpdateBaseTest < EppTestCase post epp_update_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_emails 1 end @@ -101,7 +105,8 @@ class EppContactUpdateBaseTest < EppTestCase post epp_update_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } - + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_no_emails end @@ -133,7 +138,8 @@ class EppContactUpdateBaseTest < EppTestCase post epp_update_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } - + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_no_emails end @@ -160,7 +166,8 @@ class EppContactUpdateBaseTest < EppTestCase post epp_update_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } - + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :object_does_not_exist end @@ -196,6 +203,8 @@ class EppContactUpdateBaseTest < EppTestCase post epp_update_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :data_management_policy_violation end @@ -228,7 +237,8 @@ class EppContactUpdateBaseTest < EppTestCase XML post epp_update_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } - + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully end @@ -269,6 +279,8 @@ class EppContactUpdateBaseTest < EppTestCase post epp_update_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully @contact.reload @@ -315,6 +327,8 @@ class EppContactUpdateBaseTest < EppTestCase post epp_update_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_without_address @contact.reload @@ -362,6 +376,8 @@ class EppContactUpdateBaseTest < EppTestCase post epp_update_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml @contact.reload assert_not_equal city, @contact.city @@ -417,6 +433,8 @@ class EppContactUpdateBaseTest < EppTestCase @contact.reload end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully assert_equal 'new name', @contact.name assert_equal 'new-email@inbox.test', @contact.email