From 3eb645a590726487d7239c72ac4453ca6e40c3c5 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 2 Jun 2021 14:43:29 +0500 Subject: [PATCH 1/4] Refactor schema checking to custom assertion --- test/integration/epp/domain/info/base_test.rb | 5 +---- test/test_helper.rb | 7 +++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/integration/epp/domain/info/base_test.rb b/test/integration/epp/domain/info/base_test.rb index 214cdfb6f..4aaa6c8ba 100644 --- a/test/integration/epp/domain/info/base_test.rb +++ b/test/integration/epp/domain/info/base_test.rb @@ -116,10 +116,7 @@ class EppDomainInfoBaseTest < EppTestCase response_xml = Nokogiri::XML(response.body) assert_epp_response :completed_successfully - schema = EPP_ALL_SCHEMA - - schema_validation_errors = schema.validate(response_xml) - assert_equal 0, schema_validation_errors.size + assert_correct_against_schema response_xml end def test_returns_valid_response_if_release_prohibited diff --git a/test/test_helper.rb b/test/test_helper.rb index a8ed1a3ca..16eda7fc3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -75,6 +75,13 @@ class EppTestCase < ActionDispatch::IntegrationTest assert schema_version >= version end + def assert_correct_against_schema(response_xml, message = nil) + schema = EPP_ALL_SCHEMA + + schema_validation_errors = schema.validate(response_xml) + assert_equal 0, schema_validation_errors.size, message + end + private def prefix_schema_tag(prefix, response_xml) From f2f56d835065a030099367e4683765c2336ba068 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 2 Jun 2021 15:34:13 +0500 Subject: [PATCH 2/4] Add base tests & make domain crID optional --- app/views/epp/domains/info.xml.builder | 2 +- test/integration/epp/domain/info/base_test.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/epp/domains/info.xml.builder b/app/views/epp/domains/info.xml.builder index 492248958..d1695f20c 100644 --- a/app/views/epp/domains/info.xml.builder +++ b/app/views/epp/domains/info.xml.builder @@ -41,7 +41,7 @@ xml.epp_head do xml.tag!('domain:clID', @domain.registrar.code) - xml.tag!('domain:crID', @domain.cr_id) + xml.tag!('domain:crID', @domain.cr_id) if @domain.cr_id.present? xml.tag!('domain:crDate', @domain.created_at.try(:iso8601)) if @domain.updated_at > @domain.created_at diff --git a/test/integration/epp/domain/info/base_test.rb b/test/integration/epp/domain/info/base_test.rb index 4aaa6c8ba..dd54e651e 100644 --- a/test/integration/epp/domain/info/base_test.rb +++ b/test/integration/epp/domain/info/base_test.rb @@ -144,10 +144,7 @@ class EppDomainInfoBaseTest < EppTestCase response_xml = Nokogiri::XML(response.body) assert_epp_response :completed_successfully - schema = EPP_ALL_SCHEMA - - schema_validation_errors = schema.validate(response_xml) - assert_equal 0, schema_validation_errors.size + assert_correct_against_schema response_xml end def test_reveals_transfer_code_when_domain_is_owned_by_current_user @@ -173,6 +170,7 @@ class EppDomainInfoBaseTest < EppTestCase assert_equal '65078d5', response_xml.at_xpath('//domain:authInfo/domain:pw', 'domain' => Xsd::Schema.filename(for_prefix: 'domain-ee').to_s).text + assert_correct_against_schema response_xml end # Transfer code is the only info we conceal from other registrars, hence a bit oddly-looking @@ -203,6 +201,7 @@ class EppDomainInfoBaseTest < EppTestCase assert_equal '65078d5', response_xml.at_xpath('//domain:authInfo/domain:pw', 'domain' => Xsd::Schema.filename(for_prefix: 'domain-ee').to_s).text + assert_correct_against_schema response_xml end def test_conceals_transfer_code_when_domain_is_not_owned_by_current_user @@ -226,6 +225,7 @@ class EppDomainInfoBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_nil response_xml.at_xpath('//domain:authInfo/domain:pw', 'domain' => Xsd::Schema.filename(for_prefix: 'domain-ee').to_s) end From 860c3c8008f7d301a63411d8f4c93534307a8aea Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 2 Jun 2021 15:45:03 +0500 Subject: [PATCH 3/4] Add domain base & auction tests Add tests for domain create, delete, renew, transfer, update --- test/integration/epp/domain/base_test.rb | 2 + .../epp/domain/check/auction_test.rb | 5 +++ .../integration/epp/domain/check/base_test.rb | 8 ++++ .../epp/domain/create/auction_idn_test.rb | 18 ++++++++ .../epp/domain/create/auction_test.rb | 14 ++++++ .../epp/domain/create/base_test.rb | 45 +++++++++++++++++++ .../epp/domain/delete/base_test.rb | 18 ++++++++ .../integration/epp/domain/renew/base_test.rb | 25 +++++++++++ .../epp/domain/transfer/query_test.rb | 7 +++ .../epp/domain/transfer/request_test.rb | 34 ++++++++++++++ .../epp/domain/update/base_test.rb | 41 +++++++++++++++++ 11 files changed, 217 insertions(+) diff --git a/test/integration/epp/domain/base_test.rb b/test/integration/epp/domain/base_test.rb index e8c905062..557d25f59 100644 --- a/test/integration/epp/domain/base_test.rb +++ b/test/integration/epp/domain/base_test.rb @@ -17,7 +17,9 @@ class EppDomainBaseTest < EppTestCase post epp_info_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + response_xml = Nokogiri::XML(response.body) assert_epp_response :object_does_not_exist + assert_correct_against_schema response_xml end def test_invalid_path diff --git a/test/integration/epp/domain/check/auction_test.rb b/test/integration/epp/domain/check/auction_test.rb index ece849b00..d8a7b5919 100644 --- a/test/integration/epp/domain/check/auction_test.rb +++ b/test/integration/epp/domain/check/auction_test.rb @@ -32,6 +32,7 @@ class EppDomainCheckAuctionTest < 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 '0', response_xml.at_xpath('//domain:name', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}")['avail'] assert_equal 'Domain is at auction', response_xml.at_xpath('//domain:reason', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text @@ -57,6 +58,7 @@ class EppDomainCheckAuctionTest < 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 '0', response_xml.at_xpath('//domain:name', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}")['avail'] assert_equal 'Domain is at auction', response_xml.at_xpath('//domain:reason', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text @@ -82,6 +84,7 @@ class EppDomainCheckAuctionTest < 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 '0', response_xml.at_xpath('//domain:name', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}")['avail'] assert_equal 'Domain is at auction', response_xml.at_xpath('//domain:reason', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text @@ -107,6 +110,7 @@ class EppDomainCheckAuctionTest < 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 '0', response_xml.at_xpath('//domain:name', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}")['avail'] assert_equal 'Awaiting payment', response_xml.at_xpath('//domain:reason', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text @@ -132,6 +136,7 @@ class EppDomainCheckAuctionTest < 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 '1', response_xml.at_xpath('//domain:name', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}")['avail'] assert_nil response_xml.at_xpath('//domain:reason', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}") diff --git a/test/integration/epp/domain/check/base_test.rb b/test/integration/epp/domain/check/base_test.rb index 07e1e2081..f2f85bed3 100644 --- a/test/integration/epp/domain/check/base_test.rb +++ b/test/integration/epp/domain/check/base_test.rb @@ -20,6 +20,7 @@ class EppDomainCheckBaseTest < EppTestCase response_xml = Nokogiri::XML(response.body) assert_epp_response :completed_successfully + assert_correct_against_schema response_xml assert_equal 'some.test', response_xml.at_xpath('//domain:name', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text end @@ -41,6 +42,7 @@ class EppDomainCheckBaseTest < 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('//domain:name', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}")['avail'] assert_nil response_xml.at_xpath('//domain:reason', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}") end @@ -65,6 +67,7 @@ class EppDomainCheckBaseTest < 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('//domain:name', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}")['avail'] assert_nil response_xml.at_xpath('//domain:reason', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}") end @@ -87,6 +90,7 @@ class EppDomainCheckBaseTest < 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('//domain:name', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}")['avail'] assert_equal 'invalid format', response_xml.at_xpath('//domain:reason', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text end @@ -111,6 +115,7 @@ class EppDomainCheckBaseTest < 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('//domain:name', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}")['avail'] assert_equal 'in use', response_xml.at_xpath('//domain:reason', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text end @@ -135,6 +140,7 @@ class EppDomainCheckBaseTest < 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('//domain:name', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}")['avail'] assert_equal 'Blocked', response_xml.at_xpath('//domain:reason', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text end @@ -159,6 +165,7 @@ class EppDomainCheckBaseTest < 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('//domain:name', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}")['avail'] assert_equal 'Zone with the same origin exists', response_xml.at_xpath('//domain:reason', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text end @@ -183,6 +190,7 @@ class EppDomainCheckBaseTest < 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('//domain:cd', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").size end end diff --git a/test/integration/epp/domain/create/auction_idn_test.rb b/test/integration/epp/domain/create/auction_idn_test.rb index 2f2fd6fd9..8424c82cb 100644 --- a/test/integration/epp/domain/create/auction_idn_test.rb +++ b/test/integration/epp/domain/create/auction_idn_test.rb @@ -43,6 +43,9 @@ class EppDomainCreateAuctionIdnTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml + refute Domain.where(name: @idn_auction.domain).exists? @idn_auction.reload @@ -78,6 +81,9 @@ class EppDomainCreateAuctionIdnTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames'} end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml + refute Domain.where(name: @idn_auction.domain).exists? @idn_auction.reload @@ -112,6 +118,9 @@ class EppDomainCreateAuctionIdnTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames'} end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml + refute Domain.where(name: @idn_auction.domain).exists? @idn_auction.reload @@ -146,6 +155,9 @@ class EppDomainCreateAuctionIdnTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames'} end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml + refute Domain.where(name: @idn_auction.domain).exists? @idn_auction.reload @@ -184,6 +196,9 @@ class EppDomainCreateAuctionIdnTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames'} end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml + @idn_auction.reload assert @idn_auction.domain_registered? assert Domain.where(name: @idn_auction.domain).exists? @@ -221,6 +236,9 @@ class EppDomainCreateAuctionIdnTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames'} end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml + @idn_auction.reload assert @idn_auction.domain_registered? assert Domain.where(name: @idn_auction.domain).exists? diff --git a/test/integration/epp/domain/create/auction_test.rb b/test/integration/epp/domain/create/auction_test.rb index 3c2b14d5c..08ac79ad0 100644 --- a/test/integration/epp/domain/create/auction_test.rb +++ b/test/integration/epp/domain/create/auction_test.rb @@ -35,6 +35,8 @@ class EppDomainCreateAuctionTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end assert_epp_response :completed_successfully + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml end def test_registers_domain_with_correct_registration_code_after_another_auction_when_payment_is_received @@ -73,6 +75,8 @@ class EppDomainCreateAuctionTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end assert_epp_response :completed_successfully + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml end def test_registers_domain_with_correct_registration_code_when_payment_is_received @@ -109,6 +113,8 @@ class EppDomainCreateAuctionTest < EppTestCase @auction.reload assert @auction.domain_registered? assert_epp_response :completed_successfully + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml end def test_domain_cannot_be_registered_without_registration_code @@ -138,6 +144,8 @@ class EppDomainCreateAuctionTest < 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 @@ -171,6 +179,8 @@ class EppDomainCreateAuctionTest < 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 :invalid_authorization_information end @@ -203,6 +213,8 @@ class EppDomainCreateAuctionTest < 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 @@ -231,6 +243,8 @@ class EppDomainCreateAuctionTest < 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 :parameter_value_policy_error end end diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb index 914a6352a..4c6b9e7af 100644 --- a/test/integration/epp/domain/create/base_test.rb +++ b/test/integration/epp/domain/create/base_test.rb @@ -42,6 +42,8 @@ class EppDomainCreateBaseTest < 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 :parameter_value_syntax_error end @@ -73,6 +75,8 @@ class EppDomainCreateBaseTest < 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 :data_management_policy_violation end @@ -107,6 +111,8 @@ class EppDomainCreateBaseTest < 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 :data_management_policy_violation error_description = 'Legaldoc size exceeds maximum allowed size of 8mB' @@ -143,6 +149,8 @@ class EppDomainCreateBaseTest < 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 :completed_successfully end @@ -174,6 +182,8 @@ class EppDomainCreateBaseTest < 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 @@ -210,6 +220,8 @@ class EppDomainCreateBaseTest < 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 :completed_successfully end @@ -248,6 +260,8 @@ class EppDomainCreateBaseTest < 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 :parameter_value_policy_error end @@ -285,6 +299,8 @@ class EppDomainCreateBaseTest < 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 :parameter_value_policy_error end @@ -322,6 +338,8 @@ class EppDomainCreateBaseTest < 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 :parameter_value_policy_error end @@ -360,6 +378,8 @@ class EppDomainCreateBaseTest < 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 :parameter_value_policy_error end @@ -398,6 +418,8 @@ class EppDomainCreateBaseTest < 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 :parameter_value_policy_error end @@ -432,6 +454,8 @@ class EppDomainCreateBaseTest < 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 :completed_successfully @@ -475,6 +499,8 @@ class EppDomainCreateBaseTest < 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 :completed_successfully @@ -511,6 +537,9 @@ class EppDomainCreateBaseTest < EppTestCase post epp_create_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 :required_parameter_missing Setting.legal_document_is_mandatory = false @@ -553,6 +582,8 @@ class EppDomainCreateBaseTest < 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 :completed_successfully reserved_domain.reload @@ -588,6 +619,8 @@ class EppDomainCreateBaseTest < EppTestCase post epp_create_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 assert_equal transfer_code, Domain.find_by(name: name).transfer_code end @@ -619,6 +652,8 @@ class EppDomainCreateBaseTest < 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 :data_management_policy_violation end @@ -649,6 +684,8 @@ class EppDomainCreateBaseTest < 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 :data_management_policy_violation end @@ -679,6 +716,8 @@ class EppDomainCreateBaseTest < 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 :invalid_authorization_information end @@ -708,6 +747,8 @@ class EppDomainCreateBaseTest < 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 @@ -737,6 +778,8 @@ class EppDomainCreateBaseTest < EppTestCase post epp_create_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => "session=#{session.session_id}" } end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :billing_failure end @@ -766,6 +809,8 @@ class EppDomainCreateBaseTest < 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 :billing_failure end end diff --git a/test/integration/epp/domain/delete/base_test.rb b/test/integration/epp/domain/delete/base_test.rb index 952448c90..b13c20964 100644 --- a/test/integration/epp/domain/delete/base_test.rb +++ b/test/integration/epp/domain/delete/base_test.rb @@ -35,6 +35,8 @@ class EppDomainDeleteBaseTest < EppTestCase XML 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_includes Domain.find_by(name: 'invalid.test').statuses, DomainStatus::PENDING_DELETE_CONFIRMATION assert_epp_response :completed_successfully_action_pending end @@ -64,6 +66,8 @@ class EppDomainDeleteBaseTest < EppTestCase assert_no_difference 'Domain.count' do 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_status_prohibits_operation end @@ -92,6 +96,8 @@ class EppDomainDeleteBaseTest < EppTestCase perform_enqueued_jobs do 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 @domain.reload @@ -126,6 +132,9 @@ class EppDomainDeleteBaseTest < EppTestCase perform_enqueued_jobs do 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 + @domain.reload assert_not @domain.registrant_verification_asked? @@ -160,6 +169,9 @@ class EppDomainDeleteBaseTest < EppTestCase perform_enqueued_jobs do 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 + @domain.reload assert_not @domain.registrant_verification_asked? @@ -193,6 +205,8 @@ class EppDomainDeleteBaseTest < EppTestCase perform_enqueued_jobs do 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 @domain.reload assert_not @domain.registrant_verification_asked? @@ -219,6 +233,8 @@ class EppDomainDeleteBaseTest < EppTestCase XML 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_epp_response :completed_successfully end @@ -246,6 +262,8 @@ class EppDomainDeleteBaseTest < EppTestCase XML 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_epp_response :object_status_prohibits_operation end diff --git a/test/integration/epp/domain/renew/base_test.rb b/test/integration/epp/domain/renew/base_test.rb index 50732f163..d886bd563 100644 --- a/test/integration/epp/domain/renew/base_test.rb +++ b/test/integration/epp/domain/renew/base_test.rb @@ -26,6 +26,9 @@ class EppDomainRenewBaseTest < EppTestCase post epp_renew_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml + domain.reload assert_epp_response :completed_successfully @@ -57,6 +60,9 @@ class EppDomainRenewBaseTest < EppTestCase post epp_renew_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml + domain.reload assert_epp_response :completed_successfully @@ -87,6 +93,9 @@ class EppDomainRenewBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } domain.reload end + + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :object_status_prohibits_operation end @@ -115,6 +124,9 @@ class EppDomainRenewBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => "session=#{session.session_id}" } domain.reload end + + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :authorization_error end @@ -143,6 +155,9 @@ class EppDomainRenewBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => "session=#{session.session_id}" } domain.reload end + + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :billing_failure end @@ -170,6 +185,9 @@ class EppDomainRenewBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } domain.reload end + + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :billing_failure end @@ -197,6 +215,9 @@ class EppDomainRenewBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } domain.reload end + + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :parameter_value_policy_error end @@ -226,6 +247,10 @@ class EppDomainRenewBaseTest < EppTestCase post epp_renew_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml + domain.reload assert_epp_response :object_status_prohibits_operation diff --git a/test/integration/epp/domain/transfer/query_test.rb b/test/integration/epp/domain/transfer/query_test.rb index e87be291b..d4a1d1951 100644 --- a/test/integration/epp/domain/transfer/query_test.rb +++ b/test/integration/epp/domain/transfer/query_test.rb @@ -5,6 +5,9 @@ class EppDomainTransferQueryTest < EppTestCase post epp_transfer_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } xml_doc = Nokogiri::XML(response.body) + + assert_correct_against_schema xml_doc + assert_epp_response :completed_successfully assert_equal 'shop.test', xml_doc.xpath('//domain:name', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text assert_equal 'serverApproved', xml_doc.xpath('//domain:trStatus', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text @@ -32,6 +35,8 @@ class EppDomainTransferQueryTest < 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 :invalid_authorization_information end @@ -39,6 +44,8 @@ class EppDomainTransferQueryTest < EppTestCase domains(:shop).transfers.delete_all 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 :object_does_not_exist end diff --git a/test/integration/epp/domain/transfer/request_test.rb b/test/integration/epp/domain/transfer/request_test.rb index a44533f8b..44be712f0 100644 --- a/test/integration/epp/domain/transfer/request_test.rb +++ b/test/integration/epp/domain/transfer/request_test.rb @@ -22,6 +22,8 @@ class EppDomainTransferRequestTest < EppTestCase post epp_transfer_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully @domain.reload @@ -43,6 +45,8 @@ class EppDomainTransferRequestTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } assert_epp_response :completed_successfully + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml @domain.reload @@ -63,6 +67,8 @@ class EppDomainTransferRequestTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } assert_epp_response :completed_successfully + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml @domain.reload @@ -87,6 +93,8 @@ class EppDomainTransferRequestTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } assert_epp_response :completed_successfully + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml @domain.reload @@ -106,6 +114,8 @@ class EppDomainTransferRequestTest < EppTestCase post epp_transfer_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } assert_epp_response :completed_successfully + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml end def test_creates_new_domain_transfer @@ -113,11 +123,15 @@ class EppDomainTransferRequestTest < EppTestCase post epp_transfer_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml end def test_approves_automatically_if_auto_approval_is_enabled post epp_transfer_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_equal 'serverApproved', Nokogiri::XML(response.body).xpath('//domain:trStatus', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text end @@ -125,6 +139,8 @@ class EppDomainTransferRequestTest < EppTestCase def test_assigns_new_registrar post epp_transfer_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml @domain.reload assert_equal @new_registrar, @domain.registrar end @@ -135,6 +151,8 @@ class EppDomainTransferRequestTest < EppTestCase post epp_transfer_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml @domain.reload refute_equal @domain.transfer_code, @old_transfer_code end @@ -146,6 +164,8 @@ class EppDomainTransferRequestTest < EppTestCase post epp_transfer_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml end def test_duplicates_registrant_admin_and_tech_contacts @@ -153,11 +173,15 @@ class EppDomainTransferRequestTest < EppTestCase post epp_transfer_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml end def test_reuses_identical_contact post epp_transfer_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_equal 1, @new_registrar.contacts.where(name: 'William').size end @@ -166,6 +190,8 @@ class EppDomainTransferRequestTest < EppTestCase post epp_transfer_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } end + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml end def test_non_transferable_domain @@ -177,6 +203,8 @@ class EppDomainTransferRequestTest < EppTestCase assert_equal registrars(:bestnames), domains(:shop).registrar assert_epp_response :object_status_prohibits_operation + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml end def test_discarded_domain_cannot_be_transferred @@ -188,6 +216,8 @@ class EppDomainTransferRequestTest < EppTestCase assert_equal registrars(:bestnames), @domain.registrar assert_epp_response :object_is_not_eligible_for_transfer + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml end def test_same_registrar @@ -196,6 +226,8 @@ class EppDomainTransferRequestTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end assert_epp_response :use_error + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml end def test_wrong_transfer_code @@ -220,6 +252,8 @@ class EppDomainTransferRequestTest < EppTestCase @domain.reload assert_epp_response :invalid_authorization_information + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml refute_equal @new_registrar, @domain.registrar end diff --git a/test/integration/epp/domain/update/base_test.rb b/test/integration/epp/domain/update/base_test.rb index e6eba6d1d..0fb0a5fff 100644 --- a/test/integration/epp/domain/update/base_test.rb +++ b/test/integration/epp/domain/update/base_test.rb @@ -38,6 +38,8 @@ class EppDomainUpdateBaseTest < 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 @domain.reload assert_equal 'f0ff7d17b0', @domain.transfer_code assert_epp_response :completed_successfully @@ -82,6 +84,8 @@ class EppDomainUpdateBaseTest < 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_status_prohibits_operation end @@ -106,6 +110,7 @@ class EppDomainUpdateBaseTest < EppTestCase assert_epp_response :object_status_prohibits_operation response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_equal DomainStatus::PENDING_UPDATE, response_xml.at_xpath('//domain:status', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee')}").text end @@ -142,6 +147,8 @@ class EppDomainUpdateBaseTest < EppTestCase end @domain.reload + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully_action_pending assert_not_equal new_registrant, @domain.registrant assert @domain.registrant_verification_asked? @@ -183,6 +190,8 @@ class EppDomainUpdateBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } @domain.reload assert_epp_response :completed_successfully + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_equal @domain.registrant, new_registrant assert_not @domain.statuses.include? "pendingUpdate" @@ -221,6 +230,8 @@ class EppDomainUpdateBaseTest < EppTestCase end @domain.reload + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully_action_pending assert_not_equal new_registrant, @domain.registrant assert @domain.registrant_verification_asked? @@ -259,6 +270,8 @@ class EppDomainUpdateBaseTest < EppTestCase end @domain.reload + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully_action_pending assert_not_equal new_registrant, @domain.registrant assert @domain.registrant_verification_asked? @@ -290,6 +303,8 @@ class EppDomainUpdateBaseTest < 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 :required_parameter_missing Setting.legal_document_is_mandatory = old_value end @@ -332,6 +347,8 @@ class EppDomainUpdateBaseTest < EppTestCase @domain.reload # NOTE: completed_successfully_action_pending + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully refute_includes @domain.statuses, DomainStatus::PENDING_UPDATE @@ -365,6 +382,8 @@ class EppDomainUpdateBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } @domain.reload + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully assert_not @domain.registrant_verification_asked? refute_includes @domain.statuses, DomainStatus::PENDING_UPDATE @@ -407,6 +426,8 @@ class EppDomainUpdateBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } @domain.reload + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully assert new_registrant, @domain.registrant assert_not @domain.registrant_verification_asked? @@ -450,6 +471,8 @@ class EppDomainUpdateBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } @domain.reload + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :invalid_authorization_information assert_not_equal new_registrant, @domain.registrant assert @domain.disputed? @@ -486,6 +509,8 @@ class EppDomainUpdateBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } @domain.reload + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully assert_equal new_registrant, @domain.registrant assert_not @domain.registrant_verification_asked? @@ -523,6 +548,8 @@ class EppDomainUpdateBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } @domain.reload + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully assert_equal new_registrant, @domain.registrant assert_not @domain.registrant_verification_asked? @@ -562,6 +589,8 @@ class EppDomainUpdateBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } @domain.reload + response_xml = Nokogiri::XML(response.body) + assert_correct_against_schema response_xml assert_epp_response :completed_successfully assert_equal new_registrant, @domain.registrant assert_not @domain.registrant_verification_asked? @@ -599,6 +628,9 @@ class EppDomainUpdateBaseTest < 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 + @domain.reload assert_epp_response :completed_successfully @@ -624,6 +656,9 @@ class EppDomainUpdateBaseTest < 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 + @domain.reload assert_epp_response :completed_successfully assert_includes(@domain.statuses, DomainStatus::CLIENT_HOLD) @@ -652,6 +687,9 @@ class EppDomainUpdateBaseTest < 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 + @domain.reload assert_epp_response :completed_successfully assert_not_includes(@domain.statuses, DomainStatus::CLIENT_HOLD) @@ -677,6 +715,9 @@ class EppDomainUpdateBaseTest < 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 + @domain.reload assert_epp_response :object_does_not_exist end From 7163695ad14f3b81842d70622bf8e6c55a7fdc2a Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Thu, 3 Jun 2021 12:56:18 +0500 Subject: [PATCH 4/4] Add tests & fixes for epp contact --- app/models/concerns/roids.rb | 24 +++++++++++++++++ app/models/concerns/user_events.rb | 2 +- app/models/contact.rb | 5 +--- app/models/domain.rb | 21 +-------------- .../epp/contact/check/base_test.rb | 6 +++++ .../epp/contact/create/base_test.rb | 14 ++++++++++ .../epp/contact/delete/base_test.rb | 9 +++++++ .../integration/epp/contact/info/base_test.rb | 4 +++ .../epp/contact/transfer/base_test.rb | 2 ++ .../epp/contact/update/base_test.rb | 26 ++++++++++++++++--- 10 files changed, 84 insertions(+), 29 deletions(-) create mode 100644 app/models/concerns/roids.rb 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