From 5cc16552ab4538dbcc2b9f7d6f60fa8d545928bb Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 31 Mar 2018 22:42:54 +0300 Subject: [PATCH 1/6] Backport Rails 5 test assertions #799 --- test/support/rails5_assetions.rb | 94 ++++++++++++++++++++++++++++++++ test/test_helper.rb | 1 + 2 files changed, 95 insertions(+) create mode 100644 test/support/rails5_assetions.rb diff --git a/test/support/rails5_assetions.rb b/test/support/rails5_assetions.rb new file mode 100644 index 000000000..55a2e8dc6 --- /dev/null +++ b/test/support/rails5_assetions.rb @@ -0,0 +1,94 @@ +module ActiveSupport + module Testing + module Assertions + UNTRACKED = Object.new # :nodoc: + + # Assertion that the result of evaluating an expression is changed before + # and after invoking the passed in block. + # + # assert_changes 'Status.all_good?' do + # post :create, params: { status: { ok: false } } + # end + # + # You can pass the block as a string to be evaluated in the context of + # the block. A lambda can be passed for the block as well. + # + # assert_changes -> { Status.all_good? } do + # post :create, params: { status: { ok: false } } + # end + # + # The assertion is useful to test side effects. The passed block can be + # anything that can be converted to string with #to_s. + # + # assert_changes :@object do + # @object = 42 + # end + # + # The keyword arguments :from and :to can be given to specify the + # expected initial value and the expected value after the block was + # executed. + # + # assert_changes :@object, from: nil, to: :foo do + # @object = :foo + # end + # + # An error message can be specified. + # + # assert_changes -> { Status.all_good? }, 'Expected the status to be bad' do + # post :create, params: { status: { incident: true } } + # end + def assert_changes(expression, message = nil, from: UNTRACKED, to: UNTRACKED, &block) + exp = expression.respond_to?(:call) ? expression : -> { eval(expression.to_s, block.binding) } + + before = exp.call + retval = yield + + unless from == UNTRACKED + error = "#{expression.inspect} isn't #{from.inspect}" + error = "#{message}.\n#{error}" if message + assert from === before, error + end + + after = exp.call + + if to == UNTRACKED + error = "#{expression.inspect} didn't changed" + error = "#{message}.\n#{error}" if message + assert_not_equal before, after, error + else + error = "#{expression.inspect} didn't change to #{to}" + error = "#{message}.\n#{error}" if message + assert to === after, error + end + + retval + end + + # Assertion that the result of evaluating an expression is changed before + # and after invoking the passed in block. + # + # assert_no_changes 'Status.all_good?' do + # post :create, params: { status: { ok: true } } + # end + # + # An error message can be specified. + # + # assert_no_changes -> { Status.all_good? }, 'Expected the status to be good' do + # post :create, params: { status: { ok: false } } + # end + def assert_no_changes(expression, message = nil, &block) + exp = expression.respond_to?(:call) ? expression : -> { eval(expression.to_s, block.binding) } + + before = exp.call + retval = yield + after = exp.call + + error = "#{expression.inspect} did change to #{after}" + error = "#{message}.\n#{error}" if message + assert_equal before, after, error + + retval + end + end + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 7bde0991d..d85d5de73 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -11,6 +11,7 @@ require 'minitest/mock' require 'capybara/rails' require 'capybara/minitest' require 'webmock/minitest' +require 'support/rails5_assetions' # Remove once upgraded to Rails 5 Setting.address_processing = false From 139b7f290d515d0d618432d278abb4d8d160427b Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 1 Apr 2018 22:42:49 +0300 Subject: [PATCH 2/6] Update fixtures --- test/fixtures/billing/prices.yml | 30 +++++++++++++++++++++++++++--- test/fixtures/domains.yml | 4 ++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/test/fixtures/billing/prices.yml b/test/fixtures/billing/prices.yml index ef2cd09a7..17e34d3f2 100644 --- a/test/fixtures/billing/prices.yml +++ b/test/fixtures/billing/prices.yml @@ -1,7 +1,31 @@ -cash: - duration: 1 year - price_cents: 500 +create_one_month: + duration: 1 month + price_cents: 100 operation_category: create valid_from: 2010-07-05 valid_to: 2010-07-05 zone: test + +renew_one_month: + duration: 1 month + price_cents: 100 + operation_category: renew + valid_from: 2010-07-05 + valid_to: 2010-07-05 + zone: test + +create_one_year: + duration: 1 year + price_cents: 1000 + operation_category: create + valid_from: 2010-07-05 + valid_to: 2010-07-05 + zone: test + +renew_one_year: + duration: 1 year + price_cents: 1000 + operation_category: renew + valid_from: 2010-07-05 + valid_to: 2010-07-05 + zone: test diff --git a/test/fixtures/domains.yml b/test/fixtures/domains.yml index b2b2a24b5..53de2837b 100644 --- a/test/fixtures/domains.yml +++ b/test/fixtures/domains.yml @@ -40,7 +40,7 @@ metro: invalid: name: invalid.test - transfer_code: any - valid_to: 2010-07-05 + transfer_code: 1438d6 + valid_to: <%= Time.zone.parse('2010-07-05').utc.to_s(:db) %> registrar: bestnames registrant: invalid From 29a8f39cb629896665e7f1fcaf03c2cc097b9546 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 1 Apr 2018 22:59:19 +0300 Subject: [PATCH 3/6] Prohibit renewing an invalid domain #678 --- app/models/epp/domain.rb | 2 +- .../epp/domain/domain_renew_test.rb | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/integration/epp/domain/domain_renew_test.rb diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index fb01fe38a..249f90a98 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -18,7 +18,7 @@ class Epp::Domain < Domain after_validation :validate_contacts def validate_contacts - return true if is_renewal || is_transfer + return true if is_transfer ok = true active_admins = admin_domain_contacts.select { |x| !x.marked_for_destruction? } diff --git a/test/integration/epp/domain/domain_renew_test.rb b/test/integration/epp/domain/domain_renew_test.rb new file mode 100644 index 000000000..a60ec6843 --- /dev/null +++ b/test/integration/epp/domain/domain_renew_test.rb @@ -0,0 +1,32 @@ +require 'test_helper' + +class EppDomainRenewTest < ActionDispatch::IntegrationTest + self.use_transactional_fixtures = false + + def setup + travel_to Time.zone.parse('2010-07-05') + end + + def test_domain_cannot_be_renewed_when_invalid + request_xml = <<-XML + + + + + + invalid.test + 2010-07-05 + 1 + + + + + XML + + assert_no_changes -> { domains(:invalid).valid_to } do + post '/epp/command/renew', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' + end + assert_equal '2304', Nokogiri::XML(response.body).at_css('result')[:code], + Nokogiri::XML(response.body).css('result').text + end +end From 7155d08f6e39f88a546109785b5ddd1ccb55ca47 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 1 Apr 2018 23:03:52 +0300 Subject: [PATCH 4/6] Fix test --- test/integration/registrar/domains_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/registrar/domains_test.rb b/test/integration/registrar/domains_test.rb index f3936c578..35411815f 100644 --- a/test/integration/registrar/domains_test.rb +++ b/test/integration/registrar/domains_test.rb @@ -9,7 +9,7 @@ class RegistrarDomainsTest < ActionDispatch::IntegrationTest Domain,Transfer code,Registrant name,Registrant code,Date of expiry library.test,45118f5,Acme Ltd,acme-ltd-001,2010-07-05 shop.test,65078d5,John,john-001,2010-07-05 - invalid.test,any,any,any,2010-07-05 + invalid.test,1438d6,any,any,2010-07-05 airport.test,55438j5,John,john-001,2010-07-05 CSV From d766e2d82c32585218673fc7a34a067c3d60c91f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Mon, 2 Apr 2018 20:53:53 +0300 Subject: [PATCH 5/6] Changelog update 180403 --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 472c5545d..0740b23f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +03.04.2018 +* BUG: Fixed bug with sometimes failing banklink payments [#642](https://github.com/internetee/registry/issues/642) +* EPP: Domain and assoviated objects are now validated on domain renew [#678](https://github.com/internetee/registry/issues/678) +* Admin: drop uniqueness requirement from registrar's registry number field [#776](https://github.com/internetee/registry/issues/776) +* Security: Loofah gem update to 2.2.2 [#783](https://github.com/internetee/registry/pull/783) +* Disabled spellcheck for browsers to cleanuo ui [#759](https://github.com/internetee/registry/issues/759) +* Admin: refaktoered registrar management [#770](https://github.com/internetee/registry/pull/770) +* Fix structure.sql [#796](https://github.com/internetee/registry/pull/796) + 19.03.2018 * EPP transfer and REPP bulk transfer reuses contact objects [#746](https://github.com/internetee/registry/issues/746) * Gems: Rack (1.6.9) and Rack-protection (1.5.5) update [#768](https://github.com/internetee/registry/issues/768) From efda76a19515137ac9893b991cde36b1b57b774b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Tue, 3 Apr 2018 19:08:32 +0300 Subject: [PATCH 6/6] Update CHANGELOG.md spelling corrections --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0740b23f9..66e29f9f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,10 @@ 03.04.2018 -* BUG: Fixed bug with sometimes failing banklink payments [#642](https://github.com/internetee/registry/issues/642) -* EPP: Domain and assoviated objects are now validated on domain renew [#678](https://github.com/internetee/registry/issues/678) +* BUG: Fixed bug with sometimes failing bank-link payments [#642](https://github.com/internetee/registry/issues/642) +* EPP: Domain and associated objects are now validated on domain renew [#678](https://github.com/internetee/registry/issues/678) * Admin: drop uniqueness requirement from registrar's registry number field [#776](https://github.com/internetee/registry/issues/776) * Security: Loofah gem update to 2.2.2 [#783](https://github.com/internetee/registry/pull/783) -* Disabled spellcheck for browsers to cleanuo ui [#759](https://github.com/internetee/registry/issues/759) -* Admin: refaktoered registrar management [#770](https://github.com/internetee/registry/pull/770) +* Disabled spellcheck for browsers to cleanup UI [#759](https://github.com/internetee/registry/issues/759) +* Admin: refactored registrar management [#770](https://github.com/internetee/registry/pull/770) * Fix structure.sql [#796](https://github.com/internetee/registry/pull/796) 19.03.2018