From f1c9736951b0463da1a6080ef760b8b765413c77 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 12 Apr 2017 18:29:04 +0300 Subject: [PATCH 1/7] Remove unused "registrant_write_" keys from database config examples --- config/database-example-development.yml | 10 ---------- config/database-example-registrant.yml | 15 --------------- config/database-robot.yml | 9 --------- config/database-travis.yml | 4 ---- 4 files changed, 38 deletions(-) diff --git a/config/database-example-development.yml b/config/database-example-development.yml index 8bcaf097f..ba798d7e0 100644 --- a/config/database-example-development.yml +++ b/config/database-example-development.yml @@ -18,11 +18,6 @@ api_log_development: <<: *default database: registry_api_log_development -registrant_write_development: - <<: *default - database: registry_development - - test: <<: *default database: registry_test @@ -34,8 +29,3 @@ whois_test: api_log_test: <<: *default database: registry_api_log_test - -registrant_write_test: - <<: *default - database: registry_test - diff --git a/config/database-example-registrant.yml b/config/database-example-registrant.yml index 693c25115..7aaaf9216 100644 --- a/config/database-example-registrant.yml +++ b/config/database-example-registrant.yml @@ -25,14 +25,6 @@ staging: username: registrant_read_only password: registrant_read_only_pwd -registrant_write_staging: - <<: *default - database: registry_development # registry real database - host: localhost - username: registrant_write # user should have write access only to registrant_verifications table - password: registrant_write_pwd - - # # Production config for Registrant # @@ -43,10 +35,3 @@ production: host: localhost # registry production mirror location username: registrant_read_only password: registrant_read_only_pwd - -registrant_write_production: - <<: *default - database: registry_production # registry production database name - host: localhost # registry database location - username: registrant_write # user should have write access only to registrant_verifications table - password: registrant_write_pwd diff --git a/config/database-robot.yml b/config/database-robot.yml index f6eabc6cd..1a7809ccb 100644 --- a/config/database-robot.yml +++ b/config/database-robot.yml @@ -18,11 +18,6 @@ api_log_test: <<: *default database: registry_api_log_test -registrant_write_test: - <<: *default - database: registry_test - -# only for testing assets production: <<: *default database: registry_test @@ -34,7 +29,3 @@ whois_test: api_log_test: <<: *default database: registry_api_log_test - -registrant_write_test: - <<: *default - database: registry_test diff --git a/config/database-travis.yml b/config/database-travis.yml index 8bd81faa4..b79e2c453 100644 --- a/config/database-travis.yml +++ b/config/database-travis.yml @@ -17,7 +17,3 @@ whois_test: api_log_test: <<: *default database: registry_api_log_test - -registrant_write_test: - <<: *default - database: registry_test From 718c336ee1942220b08c840883a58a9de33b3c80 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 15 Apr 2017 23:31:49 +0300 Subject: [PATCH 2/7] Add expire time spec for EPP domain:renew #430 --- .../epp/domain/renew/expire_time_spec.rb | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 spec/requests/epp/domain/renew/expire_time_spec.rb diff --git a/spec/requests/epp/domain/renew/expire_time_spec.rb b/spec/requests/epp/domain/renew/expire_time_spec.rb new file mode 100644 index 000000000..670d01cfb --- /dev/null +++ b/spec/requests/epp/domain/renew/expire_time_spec.rb @@ -0,0 +1,88 @@ +require 'rails_helper' + +RSpec.describe 'EPP domain:renew' do + let(:request) { post '/epp/command/renew', frame: request_xml } + let!(:user) { create(:api_user_epp, registrar: registrar) } + let!(:registrar) { create(:registrar_with_unlimited_balance) } + let!(:pricelist) { create(:pricelist, + category: 'com', + duration: '1year', + price: Money.from_amount(1), + operation_category: 'renew', + valid_from: Time.zone.parse('05.07.2010'), + valid_to: Time.zone.parse('05.07.2010')) + } + + before :example do + travel_to Time.zone.parse('05.07.2010') + sign_in_to_epp_area(user: user) + end + + context 'when given expire time is the same as current' do + let!(:domain) { create(:domain, + registrar: registrar, + name: 'test.com', + expire_time: Time.zone.parse('05.07.2010')) + } + let(:request_xml) { <<-XML + + + + + + test.com + 2010-07-05 + 1 + + + + + XML + } + + it 'renews domain' do + request + domain.reload + expect(domain.expire_time).to eq(Time.zone.parse('05.07.2011').end_of_day) + end + + specify do + request + expect(response).to have_code_of(1000) + end + end + + context 'when given expire time is not the same as current' do + let!(:domain) { create(:domain, + registrar: registrar, + name: 'test.com', + expire_time: Time.zone.parse('05.07.2010')) + } + let(:request_xml) { <<-XML + + + + + + test.com + 2010-07-04 + 1 + + + + + XML + } + + it 'does not renew domain' do + request + domain.reload + expect(domain.expire_time).to eq(Time.zone.parse('05.07.2010')) + end + + specify do + request + expect(response).to have_code_of(2306) + end + end +end From 2cfcb6d54c5619dff09578cc54adb56ad3a8f9fb Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 15 Apr 2017 23:38:23 +0300 Subject: [PATCH 3/7] Add expire time spec for EPP domain:renew #430 --- spec/requests/epp/domain/renew/expire_time_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/requests/epp/domain/renew/expire_time_spec.rb b/spec/requests/epp/domain/renew/expire_time_spec.rb index 670d01cfb..520ed338a 100644 --- a/spec/requests/epp/domain/renew/expire_time_spec.rb +++ b/spec/requests/epp/domain/renew/expire_time_spec.rb @@ -43,7 +43,7 @@ RSpec.describe 'EPP domain:renew' do it 'renews domain' do request domain.reload - expect(domain.expire_time).to eq(Time.zone.parse('05.07.2011').end_of_day) + expect(domain.expire_time).to eq(Time.zone.parse('05.07.2011')) end specify do From d79ce87fba20c83c1b284e388adc0c080600f2fc Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 15 Apr 2017 23:41:01 +0300 Subject: [PATCH 4/7] Use serializable transaction for EPP domain:renew #430 --- app/controllers/epp/domains_controller.rb | 47 +++++++++++++---------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index 675dcb90e..6962f42c8 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -105,29 +105,36 @@ class Epp::DomainsController < EppController balance_ok?('renew', period, period_unit) # loading pricelist - ActiveRecord::Base.transaction do - success = @domain.renew( - params[:parsed_frame].css('curExpDate').text, - period, period_unit - ) + begin + ActiveRecord::Base.transaction(isolation: :serializable) do + @domain.reload - if success - unless balance_ok?('renew', period, period_unit) - handle_errors - fail ActiveRecord::Rollback + success = @domain.renew( + params[:parsed_frame].css('curExpDate').text, + period, period_unit + ) + + if success + unless balance_ok?('renew', period, period_unit) + handle_errors + fail ActiveRecord::Rollback + end + + current_user.registrar.debit!({ + sum: @domain_pricelist.price.amount, + description: "#{I18n.t('renew')} #{@domain.name}", + activity_type: AccountActivity::RENEW, + log_pricelist_id: @domain_pricelist.id + }) + + render_epp_response '/epp/domains/renew' + else + handle_errors(@domain) end - - current_user.registrar.debit!({ - sum: @domain_pricelist.price.amount, - description: "#{I18n.t('renew')} #{@domain.name}", - activity_type: AccountActivity::RENEW, - log_pricelist_id: @domain_pricelist.id - }) - - render_epp_response '/epp/domains/renew' - else - handle_errors(@domain) end + rescue ActiveRecord::StatementInvalid => e + sleep rand / 100 + retry end end From 87f48d67885252847e1c9fba32f54697ebc4cc82 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 16 Apr 2017 17:16:40 +0300 Subject: [PATCH 5/7] Improve EPP domain:renew specs #430 --- .../epp/domain/renew/account_balance_spec.rb | 89 +++++++++++++++++++ .../epp/domain/renew/expire_time_spec.rb | 4 +- .../{renew_spec.rb => renew/limit_spec.rb} | 0 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 spec/requests/epp/domain/renew/account_balance_spec.rb rename spec/requests/epp/domain/{renew_spec.rb => renew/limit_spec.rb} (100%) diff --git a/spec/requests/epp/domain/renew/account_balance_spec.rb b/spec/requests/epp/domain/renew/account_balance_spec.rb new file mode 100644 index 000000000..6543b7225 --- /dev/null +++ b/spec/requests/epp/domain/renew/account_balance_spec.rb @@ -0,0 +1,89 @@ +require 'rails_helper' + +RSpec.describe 'EPP domain:renew' do + let(:request) { post '/epp/command/renew', frame: request_xml } + let!(:user) { create(:api_user_epp, registrar: registrar) } + let!(:pricelist) { create(:pricelist, + category: 'com', + duration: '1year', + price: Money.from_amount(1), + operation_category: 'renew', + valid_from: Time.zone.parse('05.07.2010'), + valid_to: Time.zone.parse('05.07.2010')) + } + + before :example do + travel_to Time.zone.parse('05.07.2010') + sign_in_to_epp_area(user: user) + end + + context 'when account balance is sufficient' do + let!(:registrar) { create(:registrar_with_unlimited_balance) } + let!(:domain) { create(:domain, + registrar: registrar, + name: 'test.com', + expire_time: Time.zone.parse('05.07.2010')) + } + let(:request_xml) { <<-XML + + + + + + test.com + 2010-07-05 + 1 + + + + + XML + } + + it 'renews domain' do + request + domain.reload + expect(domain.expire_time).to eq(Time.zone.parse('05.07.2011')) + end + + specify do + request + expect(response).to have_code_of(1000) + end + end + + context 'when account balance is not sufficient' do + let!(:registrar) { create(:registrar_with_zero_balance) } + let!(:domain) { create(:domain, + registrar: registrar, + name: 'test.com', + expire_time: Time.zone.parse('05.07.2010')) + } + let(:request_xml) { <<-XML + + + + + + test.com + 2010-07-04 + 1 + + + + + XML + } + + it 'does not renew domain' do + request + domain.reload + expect(domain.expire_time).to eq(Time.zone.parse('05.07.2010')) + end + + specify do + request + expect(response).to have_code_of(2104) + end + end +end diff --git a/spec/requests/epp/domain/renew/expire_time_spec.rb b/spec/requests/epp/domain/renew/expire_time_spec.rb index 520ed338a..ae9006548 100644 --- a/spec/requests/epp/domain/renew/expire_time_spec.rb +++ b/spec/requests/epp/domain/renew/expire_time_spec.rb @@ -18,7 +18,7 @@ RSpec.describe 'EPP domain:renew' do sign_in_to_epp_area(user: user) end - context 'when given expire time is the same as current' do + context 'when given expire time and current match' do let!(:domain) { create(:domain, registrar: registrar, name: 'test.com', @@ -52,7 +52,7 @@ RSpec.describe 'EPP domain:renew' do end end - context 'when given expire time is not the same as current' do + context 'when given expire time and current do not match' do let!(:domain) { create(:domain, registrar: registrar, name: 'test.com', diff --git a/spec/requests/epp/domain/renew_spec.rb b/spec/requests/epp/domain/renew/limit_spec.rb similarity index 100% rename from spec/requests/epp/domain/renew_spec.rb rename to spec/requests/epp/domain/renew/limit_spec.rb From f03ce111971ba6531b5b0a1f18807af6183ad71b Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 17 Apr 2017 16:22:25 +0300 Subject: [PATCH 6/7] Fix EPP domain:renew specs #430 --- spec/requests/epp/domain/renew/account_balance_spec.rb | 1 + spec/requests/epp/domain/renew/expire_time_spec.rb | 1 + spec/requests/epp/domain/renew/limit_spec.rb | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/requests/epp/domain/renew/account_balance_spec.rb b/spec/requests/epp/domain/renew/account_balance_spec.rb index 6543b7225..6d13b674d 100644 --- a/spec/requests/epp/domain/renew/account_balance_spec.rb +++ b/spec/requests/epp/domain/renew/account_balance_spec.rb @@ -13,6 +13,7 @@ RSpec.describe 'EPP domain:renew' do } before :example do + Setting.days_to_renew_domain_before_expire = 1 travel_to Time.zone.parse('05.07.2010') sign_in_to_epp_area(user: user) end diff --git a/spec/requests/epp/domain/renew/expire_time_spec.rb b/spec/requests/epp/domain/renew/expire_time_spec.rb index ae9006548..9de9da653 100644 --- a/spec/requests/epp/domain/renew/expire_time_spec.rb +++ b/spec/requests/epp/domain/renew/expire_time_spec.rb @@ -14,6 +14,7 @@ RSpec.describe 'EPP domain:renew' do } before :example do + Setting.days_to_renew_domain_before_expire = 1 travel_to Time.zone.parse('05.07.2010') sign_in_to_epp_area(user: user) end diff --git a/spec/requests/epp/domain/renew/limit_spec.rb b/spec/requests/epp/domain/renew/limit_spec.rb index 69a482bf4..98885fcd4 100644 --- a/spec/requests/epp/domain/renew/limit_spec.rb +++ b/spec/requests/epp/domain/renew/limit_spec.rb @@ -7,7 +7,8 @@ RSpec.describe 'EPP domain:renew' do subject(:response_code) { response_xml.xpath('//xmlns:result').first['code'] } subject(:response_description) { response_xml.css('result msg').text } - before do + before :example do + Setting.days_to_renew_domain_before_expire = 1 travel_to Time.zone.parse('05.07.2010') sign_in_to_epp_area(user: user) FactoryGirl.create(:account, registrar: registrar, balance: 1) From 74ba4a5b01fc887042bfd6619ebf36ab5ddeed59 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 17 Apr 2017 16:40:14 +0300 Subject: [PATCH 7/7] Fix EPP domain:renew specs #430 --- spec/requests/epp/domain/renew/account_balance_spec.rb | 2 +- spec/requests/epp/domain/renew/expire_time_spec.rb | 2 +- spec/requests/epp/domain/renew/limit_spec.rb | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/requests/epp/domain/renew/account_balance_spec.rb b/spec/requests/epp/domain/renew/account_balance_spec.rb index 6d13b674d..9dc840422 100644 --- a/spec/requests/epp/domain/renew/account_balance_spec.rb +++ b/spec/requests/epp/domain/renew/account_balance_spec.rb @@ -13,7 +13,7 @@ RSpec.describe 'EPP domain:renew' do } before :example do - Setting.days_to_renew_domain_before_expire = 1 + Setting.days_to_renew_domain_before_expire = 0 travel_to Time.zone.parse('05.07.2010') sign_in_to_epp_area(user: user) end diff --git a/spec/requests/epp/domain/renew/expire_time_spec.rb b/spec/requests/epp/domain/renew/expire_time_spec.rb index 9de9da653..b6b5caf99 100644 --- a/spec/requests/epp/domain/renew/expire_time_spec.rb +++ b/spec/requests/epp/domain/renew/expire_time_spec.rb @@ -14,7 +14,7 @@ RSpec.describe 'EPP domain:renew' do } before :example do - Setting.days_to_renew_domain_before_expire = 1 + Setting.days_to_renew_domain_before_expire = 0 travel_to Time.zone.parse('05.07.2010') sign_in_to_epp_area(user: user) end diff --git a/spec/requests/epp/domain/renew/limit_spec.rb b/spec/requests/epp/domain/renew/limit_spec.rb index 98885fcd4..c8fbee7f0 100644 --- a/spec/requests/epp/domain/renew/limit_spec.rb +++ b/spec/requests/epp/domain/renew/limit_spec.rb @@ -8,7 +8,6 @@ RSpec.describe 'EPP domain:renew' do subject(:response_description) { response_xml.css('result msg').text } before :example do - Setting.days_to_renew_domain_before_expire = 1 travel_to Time.zone.parse('05.07.2010') sign_in_to_epp_area(user: user) FactoryGirl.create(:account, registrar: registrar, balance: 1)