From 53feab6a8ccb289c7801ed5abbab8724bff25fc5 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Fri, 2 Oct 2015 13:54:35 +0300 Subject: [PATCH 1/9] git ignore IDE, bundle and editor files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 10d6b7678..941030b69 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,9 @@ todo ## Environment normalisation: /.bundle /vendor/bundle +.idea +# editor tmp files +*.*~ # these should all be checked in to normalise the environment: # Gemfile.lock, .ruby-version, .ruby-gemset From 647d68b053ca79436bcb3d53871649f66b744f0b Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Wed, 21 Oct 2015 15:55:58 +0300 Subject: [PATCH 2/9] config: Allow Operating System portability try to use system version of wkhtmltopddf if installed before trying to use the linux build in project bin, which may crash --- config/initializers/pdfkit.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config/initializers/pdfkit.rb b/config/initializers/pdfkit.rb index b38887c6e..d7bbc64b8 100644 --- a/config/initializers/pdfkit.rb +++ b/config/initializers/pdfkit.rb @@ -1,5 +1,9 @@ PDFKit.configure do |config| - config.wkhtmltopdf = "#{Rails.root}/vendor/bin/wkhtmltopdf" + installed = %x(which wkhtmltopdf).chomp + if installed == "" then + installed = "#{Rails.root}/vendor/bin/wkhtmltopdf" + end + config.wkhtmltopdf = installed config.default_options = { page_size: 'A4', quiet: true From 53695c36471da4d0e70d46252ce56f511c79ab8d Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Wed, 21 Oct 2015 16:08:21 +0300 Subject: [PATCH 3/9] config: EPP port. spec use config; depp/user use config not custom for test --- app/models/depp/user.rb | 2 +- spec/support/epp.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/depp/user.rb b/app/models/depp/user.rb index 44c25bbb1..51ce3f682 100644 --- a/app/models/depp/user.rb +++ b/app/models/depp/user.rb @@ -18,7 +18,7 @@ module Depp def server client_cert = File.read(ENV['cert_path']) client_key = File.read(ENV['key_path']) - port = Rails.env.test? ? 701 : ENV['epp_port'] + port = ENV['epp_port'] || '700' @server_cache ||= Epp::Server.new({ server: ENV['epp_hostname'], diff --git a/spec/support/epp.rb b/spec/support/epp.rb index b14eb79a7..a580ee01e 100644 --- a/spec/support/epp.rb +++ b/spec/support/epp.rb @@ -92,8 +92,10 @@ module Epp end def server + port = ENV['epp_port'] || 700 + hostname = ENV['epp_hostname'] || 'localhost' # tag and password not in use, add those at login xml - @server ||= Epp::Server.new({ server: 'localhost', port: 701, tag: '', password: '' }) + @server ||= Epp::Server.new({ server: hostname, port: port, tag: '', password: '' }) end def parse_response(raw) From e702cbde958675dc2d4a2b4c21a2c827929c1921 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Wed, 21 Oct 2015 16:22:34 +0300 Subject: [PATCH 4/9] test case: BUGFIX ensure test setup, new Domain object for each instance before :all runs once per context, before :example runs for each it block be sure test cases with hacks/forced changes do not impact later tests --- spec/models/domain_spec.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 015a407e0..a6a0cfbf8 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -64,10 +64,15 @@ describe Domain do end context 'with valid attributes' do - before :all do + before :example do @domain = Fabricate(:domain) end + after do + @domain.delete + @domain = nil + end + it 'should be valid' do @domain.valid? @domain.errors.full_messages.should match_array([]) @@ -458,7 +463,7 @@ describe Domain do end context 'about registrant update confirm' do - before :all do + before :example do @domain.registrant_verification_token = 123 @domain.registrant_verification_asked_at = Time.zone.now @domain.statuses << DomainStatus::PENDING_UPDATE @@ -479,7 +484,7 @@ describe Domain do end context 'about registrant update confirm when domain is invalid' do - before :all do + before :example do @domain.registrant_verification_token = 123 @domain.registrant_verification_asked_at = Time.zone.now @domain.statuses << DomainStatus::PENDING_UPDATE From 4de83da19b53d1941b328aafd3a5add21dab51cc Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Wed, 21 Oct 2015 17:48:14 +0300 Subject: [PATCH 5/9] test: added new test cases for forceDelete (no update, no renew, manualInZone) fails --- spec/models/domain_spec.rb | 123 ++++++++++++++++++++++++++++++------- 1 file changed, 102 insertions(+), 21 deletions(-) diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index a6a0cfbf8..76c2fc43b 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -163,27 +163,6 @@ describe Domain do @domain.statuses.include?(DomainStatus::EXPIRED).should == true end - it 'should start redemption grace period' do - Domain.start_redemption_grace_period - @domain.reload - @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false - - @domain.outzone_at = Time.zone.now - @domain.statuses << DomainStatus::SERVER_MANUAL_INZONE # this prohibits server_hold - @domain.save - - Domain.start_redemption_grace_period - @domain.reload - @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false - - @domain.statuses = [] - @domain.save - - Domain.start_redemption_grace_period - @domain.reload - @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == true - end - it 'should start delete period' do Domain.start_delete_period @domain.reload @@ -291,6 +270,108 @@ describe Domain do ]) end + it 'should should be manual in zone and held after force delete' do + @domain.valid? + @domain.outzone_at = Time.zone.now + 1.day # before redemption grace period + # what should this be? + # @domain.server_holdable?.should be true + @domain.statuses.include?(DomainStatus::SERVER_HOLD).should be false + @domain.statuses.include?(DomainStatus::SERVER_MANUAL_INZONE).should be false + @domain.set_force_delete + @domain.server_holdable?.should be false + @domain.statuses.include?(DomainStatus::SERVER_MANUAL_INZONE).should be true + @domain.statuses.include?(DomainStatus::SERVER_HOLD).should be false + end + + it 'should not allow update after force delete' do + @domain.valid? + @domain.pending_update_prohibited?.should be false + @domain.update_prohibited?.should be false + @domain.set_force_delete + @domain.pending_update_prohibited?.should be true + @domain.update_prohibited?.should be true + end + + context 'with time period settings' do + before :all do + @save_days_to_renew = Setting.days_to_renew_domain_before_expire + @save_warning_period = Setting.expire_warning_period + @save_grace_period = Setting.redemption_grace_period + end + + after :all do + Setting.days_to_renew_domain_before_expire = @save_days_to_renew + Setting.expire_warning_period = @save_warning_period + Setting.redemption_grace_period = @save_grace_period + end + + before :example do + @domain.valid? + end + + context 'with no renewal limit, renew anytime' do + before do + Setting.days_to_renew_domain_before_expire = 0 + end + + it 'should always renew with no policy' do + @domain.renewable?.should be true + end + + it 'should not allow to renew after force delete' do + @domain.set_force_delete + @domain.renewable?.should be false + end + end + + context 'with renew policy' do + before :all do + @policy = 30 + Setting.days_to_renew_domain_before_expire = @policy + end + + it 'should not allow renew before policy' do + @domain.valid_to = Time.zone.now.beginning_of_day + @policy.days * 2 + @domain.renewable?.should be false + end + + context 'ready to renew' do + before { @domain.valid_to = Time.zone.now + (@policy - 2).days } + + it 'should allow renew' do + @domain.renewable?.should be true + end + + it 'should not allow to renew after force delete' do + @domain.set_force_delete + @domain.renewable?.should be false + end + end + end + end + + it 'should start redemption grace period' do + Domain.start_redemption_grace_period + @domain.reload + @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false + + @domain.outzone_at = Time.zone.now + @domain.statuses << DomainStatus::SERVER_MANUAL_INZONE # this prohibits server_hold + @domain.save + + Domain.start_redemption_grace_period + @domain.reload + @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false + + @domain.statuses = [] + @domain.save + + Domain.start_redemption_grace_period + @domain.reload + @domain.statuses.include?(DomainStatus::SERVER_HOLD).should == true + end + + it 'should set expired status and update outzone_at and delete_at' do domain = Fabricate(:domain) domain.statuses.should == ['ok'] From 8f2595c0ca3c0d17b59d8bca47bd2bf49cabf340 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Wed, 21 Oct 2015 18:54:27 +0300 Subject: [PATCH 6/9] FIX: 104525314 -- forceDelete prohibits renew --- app/models/domain.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index 3a7b401a9..c09094c7d 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -344,7 +344,7 @@ class Domain < ActiveRecord::Base end end - return false if statuses.include?(DomainStatus::DELETE_CANDIDATE) + return false if statuses.include?(DomainStatus::DELETE_CANDIDATE) || statuses.include?(DomainStatus::FORCE_DELETE) true end From 3fba8442afb640cdd70f1b8bab5a26ab7df4563b Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Fri, 23 Oct 2015 19:36:01 +0300 Subject: [PATCH 7/9] FEATURE 104525314.6&7: do not allow changes to admin or tech contact if prohibited --- app/models/domain.rb | 13 +++++++++++-- app/models/epp/domain.rb | 26 +++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index c09094c7d..84ce6af5d 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -12,9 +12,10 @@ class Domain < ActiveRecord::Base has_many :domain_contacts, dependent: :destroy has_many :admin_domain_contacts - accepts_nested_attributes_for :admin_domain_contacts, allow_destroy: true + accepts_nested_attributes_for :admin_domain_contacts, allow_destroy: !:admin_change_prohibited?, reject_if: :admin_change_prohibited? has_many :tech_domain_contacts - accepts_nested_attributes_for :tech_domain_contacts, allow_destroy: true + accepts_nested_attributes_for :tech_domain_contacts, allow_destroy: !:tech_change_prohibited?, reject_if: :tech_change_prohibited? + has_many :contacts, through: :domain_contacts, source: :contact has_many :admin_contacts, through: :admin_domain_contacts, source: :contact @@ -172,6 +173,14 @@ class Domain < ActiveRecord::Base nameservers.select { |x| !x.hostname.end_with?(name) } end + def admin_change_prohibited? + statuses.include? DomainStatus::SERVER_ADMIN_CHANGE_PROHIBITED + end + + def tech_change_prohibited? + statuses.include? DomainStatus::SERVER_TECH_CHANGE_PROHIBITED + end + class << self def convert_period_to_time(period, unit) return (period.to_i / 365).years if unit == 'd' diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 83a62d1e9..12369c284 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -211,6 +211,11 @@ class Epp::Domain < Domain def admin_domain_contacts_attrs(frame, action) admin_attrs = domain_contact_attrs_from(frame, action, 'admin') + if action && !admin_attrs.empty? && admin_change_prohibited? + add_epp_error('2304', 'admin', DomainStatus::SERVER_ADMIN_CHANGE_PROHIBITED, I18n.t(:object_status_prohibits_operation)) + return [] + end + case action when 'rem' return destroy_attrs(admin_attrs, admin_domain_contacts) @@ -222,6 +227,11 @@ class Epp::Domain < Domain def tech_domain_contacts_attrs(frame, action) tech_attrs = domain_contact_attrs_from(frame, action, 'tech') + if action && !tech_attrs.empty? && tech_change_prohibited? + add_epp_error('2304', 'tech', DomainStatus::SERVER_TECH_CHANGE_PROHIBITED, I18n.t(:object_status_prohibits_operation)) + return [] + end + case action when 'rem' return destroy_attrs(tech_attrs, tech_domain_contacts) @@ -355,7 +365,6 @@ class Epp::Domain < Domain def domain_statuses_attrs(frame, action) status_list = domain_status_list_from(frame) - if action == 'rem' to_destroy = [] status_list.each do |x| @@ -407,8 +416,19 @@ class Epp::Domain < Domain at_add = attrs_from(frame.css('add'), current_user) at[:nameservers_attributes] += at_add[:nameservers_attributes] - at[:admin_domain_contacts_attributes] += at_add[:admin_domain_contacts_attributes] - at[:tech_domain_contacts_attributes] += at_add[:tech_domain_contacts_attributes] + + if !at[:admin_domain_contacts_attributes].empty? && admin_change_prohibited? + add_epp_error('2304', 'admin', DomainStatus::SERVER_ADMIN_CHANGE_PROHIBITED, I18n.t(:object_status_prohibits_operation)) + else + at[:admin_domain_contacts_attributes] += at_add[:admin_domain_contacts_attributes] + end + + if !at[:tech_domain_contacts_attributes].empty? && tech_change_prohibited? + add_epp_error('2304', 'tech', DomainStatus::SERVER_TECH_CHANGE_PROHIBITED, I18n.t(:object_status_prohibits_operation)) + else + at[:tech_domain_contacts_attributes] += at_add[:tech_domain_contacts_attributes] + end + at[:dnskeys_attributes] += at_add[:dnskeys_attributes] at[:statuses] = statuses - domain_statuses_attrs(frame.css('rem'), 'rem') + domain_statuses_attrs(frame.css('add'), 'add') From 567e0bbddd78e80a74488e4dccdbe8aad731f43d Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Fri, 23 Oct 2015 19:36:41 +0300 Subject: [PATCH 8/9] FEATURE 104525314.6&7 add admin and tech change prohbited to the schema --- lib/schemas/domain-eis-1.0.xsd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/schemas/domain-eis-1.0.xsd b/lib/schemas/domain-eis-1.0.xsd index 222d3d6f4..4febe6f15 100644 --- a/lib/schemas/domain-eis-1.0.xsd +++ b/lib/schemas/domain-eis-1.0.xsd @@ -396,6 +396,10 @@ + + + + From bd83463c2902d4bf01790b109421eb46b83cc200 Mon Sep 17 00:00:00 2001 From: Matt Farnsworth Date: Mon, 26 Oct 2015 11:38:24 +0200 Subject: [PATCH 9/9] Story: #104525314 allow admin to set values [admin,tech]ChangeProhibited --- app/models/domain_status.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/domain_status.rb b/app/models/domain_status.rb index 66908c16e..cec3c077d 100644 --- a/app/models/domain_status.rb +++ b/app/models/domain_status.rb @@ -128,8 +128,8 @@ class DomainStatus < ActiveRecord::Base # SERVER_RENEW_PROHIBITED, # SERVER_TRANSFER_PROHIBITED, # SERVER_REGISTRANT_CHANGE_PROHIBITED, - # SERVER_ADMIN_CHANGE_PROHIBITED, - # SERVER_TECH_CHANGE_PROHIBITED, + SERVER_ADMIN_CHANGE_PROHIBITED, + SERVER_TECH_CHANGE_PROHIBITED, SERVER_DELETE_PROHIBITED, SERVER_UPDATE_PROHIBITED ] @@ -144,8 +144,8 @@ class DomainStatus < ActiveRecord::Base # ['RenewProhibited', SERVER_RENEW_PROHIBITED], # ['TransferProhibited', SERVER_TRANSFER_PROHIBITED], # ['RegistrantChangeProhibited', SERVER_REGISTRANT_CHANGE_PROHIBITED], - # ['AdminChangeProhibited', SERVER_ADMIN_CHANGE_PROHIBITED], - # ['TechChangeProhibited', SERVER_TECH_CHANGE_PROHIBITED], + ['AdminChangeProhibited', SERVER_ADMIN_CHANGE_PROHIBITED], + ['TechChangeProhibited', SERVER_TECH_CHANGE_PROHIBITED], # [''], ['UpdateProhibited', SERVER_UPDATE_PROHIBITED], ['DeleteProhibited', SERVER_DELETE_PROHIBITED]