From 30ac973f9610e685dc58790ee2dbfa9b1a15f351 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 5 Jun 2018 17:26:14 +0300 Subject: [PATCH 01/14] Remove `lib` folder from autoload path - Load extensions explicitly --- app/controllers/epp_controller.rb | 17 ++++++++++++++++- {lib => app/models}/sorted_country.rb | 3 --- config/application.rb | 2 +- config/initializers/devise.rb | 2 ++ config/initializers/ext.rb | 4 ++++ config/initializers/load_class_extensions.rb | 1 - config/routes.rb | 2 +- {config/initializers => lib/core_ext}/array.rb | 0 lib/{ext/xml_builder.rb => gem_ext/builder.rb} | 0 .../relaxed_i18n.rb => lib/gem_ext/i18n.rb | 2 +- .../gem_ext/paper_trail.rb | 0 lib/iptable.rb | 17 ----------------- 12 files changed, 25 insertions(+), 25 deletions(-) rename {lib => app/models}/sorted_country.rb (96%) create mode 100644 config/initializers/ext.rb delete mode 100644 config/initializers/load_class_extensions.rb rename {config/initializers => lib/core_ext}/array.rb (100%) rename lib/{ext/xml_builder.rb => gem_ext/builder.rb} (100%) rename config/initializers/relaxed_i18n.rb => lib/gem_ext/i18n.rb (86%) rename config/initializers/001_paper_trail.rb => lib/gem_ext/paper_trail.rb (100%) delete mode 100644 lib/iptable.rb diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index 3eba05777..5cc006eda 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -1,5 +1,4 @@ class EppController < ApplicationController - include Iptable layout false protect_from_forgery with: :null_session skip_before_action :verify_authenticity_token @@ -407,4 +406,20 @@ class EppController < ApplicationController timeout = 5.minutes epp_session.updated_at < (Time.zone.now - timeout) end + + def counter_update(registrar_code, ip) + counter_proc = "/proc/net/xt_recent/#{registrar_code}" + + begin + File.open(counter_proc, 'a') do |f| + f.puts "+#{ip}" + end + rescue Errno::ENOENT => e + logger.error "IPTABLES COUNTER UPDATE: cannot open #{counter_proc}: #{e}" + rescue Errno::EACCES => e + logger.error "IPTABLES COUNTER UPDATE: no permission #{counter_proc}: #{e}" + rescue IOError => e + logger.error "IPTABLES COUNTER UPDATE: cannot write #{ip} to #{counter_proc}: #{e}" + end + end end diff --git a/lib/sorted_country.rb b/app/models/sorted_country.rb similarity index 96% rename from lib/sorted_country.rb rename to app/models/sorted_country.rb index 8b69d951a..4eb5750f5 100644 --- a/lib/sorted_country.rb +++ b/app/models/sorted_country.rb @@ -1,6 +1,3 @@ -require 'countries' -require 'action_view' - class SortedCountry class << self include ActionView::Helpers diff --git a/config/application.rb b/config/application.rb index 0d043fa5e..400e72124 100644 --- a/config/application.rb +++ b/config/application.rb @@ -40,8 +40,8 @@ module DomainNameRegistry # Autoload all model subdirs config.autoload_paths += Dir[Rails.root.join('app', 'models', '**/')] - config.autoload_paths << Rails.root.join('lib') config.eager_load_paths << config.root.join('lib', 'validators') + config.watchable_dirs['lib'] = %i[rb] # Add the fonts path config.assets.paths << Rails.root.join('vendor', 'assets', 'fonts') diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 3fe74cba6..eceb6d5f2 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,3 +1,5 @@ +require 'devise_custom_failure' + # Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| diff --git a/config/initializers/ext.rb b/config/initializers/ext.rb new file mode 100644 index 000000000..50b8b2791 --- /dev/null +++ b/config/initializers/ext.rb @@ -0,0 +1,4 @@ +require 'core_ext/array' +require 'gem_ext/builder' +require 'gem_ext/i18n' +require 'gem_ext/paper_trail' \ No newline at end of file diff --git a/config/initializers/load_class_extensions.rb b/config/initializers/load_class_extensions.rb deleted file mode 100644 index f9fb4625c..000000000 --- a/config/initializers/load_class_extensions.rb +++ /dev/null @@ -1 +0,0 @@ -Dir[File.join(Rails.root, 'lib', 'ext', '*.rb')].each { |x| require x } diff --git a/config/routes.rb b/config/routes.rb index 5ef26a195..ab6369775 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,4 @@ -require 'epp_constraint' +require_dependency 'epp_constraint' Rails.application.routes.draw do namespace(:epp, defaults: { format: :xml }) do diff --git a/config/initializers/array.rb b/lib/core_ext/array.rb similarity index 100% rename from config/initializers/array.rb rename to lib/core_ext/array.rb diff --git a/lib/ext/xml_builder.rb b/lib/gem_ext/builder.rb similarity index 100% rename from lib/ext/xml_builder.rb rename to lib/gem_ext/builder.rb diff --git a/config/initializers/relaxed_i18n.rb b/lib/gem_ext/i18n.rb similarity index 86% rename from config/initializers/relaxed_i18n.rb rename to lib/gem_ext/i18n.rb index fc9b94983..2f7fceff7 100644 --- a/config/initializers/relaxed_i18n.rb +++ b/lib/gem_ext/i18n.rb @@ -1,5 +1,5 @@ # Don't raise error when nil -# http://stackoverflow.com/questions/9467034/rails-i18n-how-to-handle-case-of-a-nil-date-being-passed-ie-lnil +# http://stackoverflow.com/questions/9467034/rails-i18n-how-to-handle-case-of-a-nil-date-being-passed-ie-lnil module I18n class << self alias_method :original_localize, :localize diff --git a/config/initializers/001_paper_trail.rb b/lib/gem_ext/paper_trail.rb similarity index 100% rename from config/initializers/001_paper_trail.rb rename to lib/gem_ext/paper_trail.rb diff --git a/lib/iptable.rb b/lib/iptable.rb deleted file mode 100644 index c41bc37f4..000000000 --- a/lib/iptable.rb +++ /dev/null @@ -1,17 +0,0 @@ -module Iptable - def counter_update(registrar_code, ip) - counter_proc = "/proc/net/xt_recent/#{registrar_code}" - - begin - File.open(counter_proc, 'a') do |f| - f.puts "+#{ip}" - end - rescue Errno::ENOENT => e - logger.error "IPTABLES COUNTER UPDATE: cannot open #{counter_proc}: #{e}" - rescue Errno::EACCES => e - logger.error "IPTABLES COUNTER UPDATE: no permission #{counter_proc}: #{e}" - rescue IOError => e - logger.error "IPTABLES COUNTER UPDATE: cannot write #{ip} to #{counter_proc}: #{e}" - end - end -end From 9b316b6a49871bf8242f29ec399067abe91a3cf2 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 5 Jun 2018 17:32:49 +0300 Subject: [PATCH 02/14] Remove deprecation message - Then setting `config.active_support.deprecation` to `raise` does not clutter test results --- app/models/contact.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 3bd8bb2ce..e553f2fbf 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -372,8 +372,6 @@ class Contact < ActiveRecord::Base end def related_domain_descriptions - ActiveSupport::Deprecation.warn('Use #domain_names_with_roles') - @desc = {} registrant_domains.each do |dom| From 9f61dfdae71439f6a21d203fe8b31020ffbe22b5 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 5 Jun 2018 17:33:30 +0300 Subject: [PATCH 03/14] Improve test env config --- config/environments/test.rb | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 9b22ad426..595a6a05d 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -12,7 +12,7 @@ Rails.application.configure do # preloads Rails for running tests, you may have to set it to true. config.eager_load = true - # Configure static asset server for tests with Cache-Control for performance. + # Configure static file server for tests with Cache-Control for performance. config.serve_static_files = true config.static_cache_control = 'public, max-age=3600' @@ -31,22 +31,16 @@ Rails.application.configure do # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - ActiveSupport::Deprecation.silenced = true + # Randomize the order test cases are executed. + config.active_support.test_order = :random - # For rails-settings-cached conflict - config.cache_store = :file_store, 'tmp/cache_test' + # Print deprecation notices to the stderr. + config.active_support.deprecation = :raise + # Raises error for missing translations config.action_view.raise_on_missing_translations = true - # The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown, - # corresponding to the log level numbers from 0 up to 5 respectively - config.log_level = :debug - config.active_job.queue_adapter = :test - config.logger = ActiveSupport::Logger.new(nil) - config.active_support.test_order = :random # :random is the default in Rails 5 + config.cache_store = :null_store end -# In this mode, any jobs you queue will be run in the same thread, synchronously -# (that is, MyJob.enqueue runs the job and won't return until it's completed). -# This makes your application's behavior easier to test -Que.mode = :sync +Que.mode = :sync \ No newline at end of file From 132ba8c6e2d1f7638c67ba910c26605ba9bd3f62 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 6 Jun 2018 03:11:28 +0300 Subject: [PATCH 04/14] Hide method --- app/controllers/epp_controller.rb | 12 ++++++------ doc/controllers_complete.svg | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index 5cc006eda..4250e0e84 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -358,12 +358,6 @@ class EppController < ApplicationController # rubocop: enable Metrics/CyclomaticComplexity # rubocop: enable Metrics/PerceivedComplexity - def iptables_counter_update - return if ENV['iptables_counter_enabled'].blank? && ENV['iptables_counter_enabled'] != 'true' - return if current_user.blank? - counter_update(current_user.registrar_code, ENV['iptables_server_ip']) - end - def resource name = self.class.to_s.sub("Epp::","").sub("Controller","").underscore.singularize instance_variable_get("@#{name}") @@ -407,6 +401,12 @@ class EppController < ApplicationController epp_session.updated_at < (Time.zone.now - timeout) end + def iptables_counter_update + return if ENV['iptables_counter_enabled'].blank? && ENV['iptables_counter_enabled'] != 'true' + return if current_user.blank? + counter_update(current_user.registrar_code, ENV['iptables_server_ip']) + end + def counter_update(registrar_code, ip) counter_proc = "/proc/net/xt_recent/#{registrar_code}" diff --git a/doc/controllers_complete.svg b/doc/controllers_complete.svg index dcf736019..7f3644dd3 100644 --- a/doc/controllers_complete.svg +++ b/doc/controllers_complete.svg @@ -668,7 +668,6 @@ generate_svtrid handle_errors has_attribute -iptables_counter_update latin_only mutually_exclusive optional From d87f4992948bc3962978821ba53a0ae710e529b6 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 6 Jun 2018 03:15:58 +0300 Subject: [PATCH 05/14] Remove unneeded require --- lib/gem_ext/builder.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/gem_ext/builder.rb b/lib/gem_ext/builder.rb index 2c933c480..e5038592a 100644 --- a/lib/gem_ext/builder.rb +++ b/lib/gem_ext/builder.rb @@ -1,5 +1,3 @@ -require 'builder' - class Builder::XmlMarkup def epp_head self.instruct! From 3400a1bd3edecf657344cace670c371414c78bb7 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 6 Jun 2018 03:20:25 +0300 Subject: [PATCH 06/14] Fix code style issues from CodeClimate --- app/models/sorted_country.rb | 10 +++++----- lib/core_ext/array.rb | 2 +- lib/gem_ext/builder.rb | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/sorted_country.rb b/app/models/sorted_country.rb index 4eb5750f5..e4f2ad330 100644 --- a/app/models/sorted_country.rb +++ b/app/models/sorted_country.rb @@ -18,12 +18,12 @@ class SortedCountry def quick_list @quick_list ||= [ - ['Estonia', 'EE'], - ['Finland', 'FI'], - ['Latvia', 'LV'], - ['Lithuania', 'LT'], + %w[Estonia' EE], + %w[Finland FI], + %w[Latvia LV], + %w[Lithuania LT], ['Russian Federation', 'RU'], - ['Sweden', 'SE'], + %w[Sweden SE], ['United States', 'US'] ] end diff --git a/lib/core_ext/array.rb b/lib/core_ext/array.rb index b48249d27..ec280ab81 100644 --- a/lib/core_ext/array.rb +++ b/lib/core_ext/array.rb @@ -1,5 +1,5 @@ class Array - def include_any? *args + def include_any?(*args) (self & args).any? end end \ No newline at end of file diff --git a/lib/gem_ext/builder.rb b/lib/gem_ext/builder.rb index e5038592a..8f2945040 100644 --- a/lib/gem_ext/builder.rb +++ b/lib/gem_ext/builder.rb @@ -1,6 +1,6 @@ class Builder::XmlMarkup def epp_head - self.instruct! + instruct! epp( 'xmlns' => 'https://epp.tld.ee/schema/epp-ee-1.0.xsd', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', From 76d10b94c545fbb1fd356442e4df8c86a3695d82 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 6 Jun 2018 04:55:36 +0300 Subject: [PATCH 07/14] Turn off settings by default - `registrar_ip_whitelist_enabled` - `api_ip_whitelist_enabled` --- config/initializers/initial_settings.rb | 4 ++-- lib/tasks/dev.rake | 2 -- spec/features/registrar/contacts/delete_spec.rb | 2 -- spec/features/registrar/ip_restriction_spec.rb | 9 +++++++-- spec/features/registrar/linked_users_spec.rb | 1 - spec/features/registrar/profile_spec.rb | 1 - .../features/registrar/sign_in/mobile_id_spec.rb | 1 - spec/features/registrar/sign_in/password_spec.rb | 4 ---- spec/features/registrar/sign_out_spec.rb | 1 - spec/models/authorization/restricted_ip_spec.rb | 12 ++++++++---- spec/requests/registrar/ip_restriction_spec.rb | 16 ++++++++-------- spec/requests/registrar/sign_in/password_spec.rb | 4 ---- spec/requests/registrar/sign_out_spec.rb | 1 - 13 files changed, 25 insertions(+), 33 deletions(-) diff --git a/config/initializers/initial_settings.rb b/config/initializers/initial_settings.rb index b6efea6eb..4f4e30057 100644 --- a/config/initializers/initial_settings.rb +++ b/config/initializers/initial_settings.rb @@ -51,8 +51,8 @@ if con.present? && con.table_exists?('settings') Setting.save_default(:redemption_grace_period, 30) Setting.save_default(:expiration_reminder_mail, 2) - Setting.save_default(:registrar_ip_whitelist_enabled, true) - Setting.save_default(:api_ip_whitelist_enabled, true) + Setting.save_default(:registrar_ip_whitelist_enabled, false) + Setting.save_default(:api_ip_whitelist_enabled, false) Setting.save_default(:registry_juridical_name, 'Eesti Interneti SA') Setting.save_default(:registry_reg_no, '90010019') diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index e4c120a8d..163e3ad1f 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -171,9 +171,7 @@ namespace :dev do end end - Setting.api_ip_whitelist_enabled = false Setting.address_processing = false - Setting.registrar_ip_whitelist_enabled = false ActiveRecord::Base.transaction do generate_default_data diff --git a/spec/features/registrar/contacts/delete_spec.rb b/spec/features/registrar/contacts/delete_spec.rb index dd6305a10..d0169ad54 100644 --- a/spec/features/registrar/contacts/delete_spec.rb +++ b/spec/features/registrar/contacts/delete_spec.rb @@ -31,8 +31,6 @@ RSpec.feature 'Contact deletion in registrar area' do background do allow(Depp::Contact).to receive(:find_by_id).and_return(FakeDeppContact.new) allow(Depp::Contact).to receive(:new).and_return(FakeDeppContact.new) - Setting.api_ip_whitelist_enabled = false - Setting.registrar_ip_whitelist_enabled = false sign_in_to_registrar_area(user: create(:api_user_with_unlimited_balance, registrar: registrar)) end diff --git a/spec/features/registrar/ip_restriction_spec.rb b/spec/features/registrar/ip_restriction_spec.rb index dc9631057..264c45283 100644 --- a/spec/features/registrar/ip_restriction_spec.rb +++ b/spec/features/registrar/ip_restriction_spec.rb @@ -1,11 +1,16 @@ require 'rails_helper' RSpec.feature 'Registrar area IP restriction', settings: false do - background do - Setting.registrar_ip_whitelist_enabled = true + before do + @original_registrar_ip_whitelist_enabled = Setting.registrar_ip_whitelist_enabled + end + + after do + Setting.registrar_ip_whitelist_enabled = @original_registrar_ip_whitelist_enabled end scenario 'notifies the user if his IP is not allowed' do + Setting.registrar_ip_whitelist_enabled = true visit registrar_root_path expect(page).to have_text('Access denied from IP 127.0.0.1') end diff --git a/spec/features/registrar/linked_users_spec.rb b/spec/features/registrar/linked_users_spec.rb index 2f5fbbd28..f7731a168 100644 --- a/spec/features/registrar/linked_users_spec.rb +++ b/spec/features/registrar/linked_users_spec.rb @@ -6,7 +6,6 @@ RSpec.feature 'Registrar area linked users', settings: false do username: 'new-user-name') } background do - Setting.registrar_ip_whitelist_enabled = false sign_in_to_registrar_area(user: current_user) end diff --git a/spec/features/registrar/profile_spec.rb b/spec/features/registrar/profile_spec.rb index 195458576..745542b58 100644 --- a/spec/features/registrar/profile_spec.rb +++ b/spec/features/registrar/profile_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' RSpec.feature 'Registrar area profile', settings: false do background do - Setting.registrar_ip_whitelist_enabled = false sign_in_to_registrar_area(user: create(:api_user_with_unlimited_balance)) end diff --git a/spec/features/registrar/sign_in/mobile_id_spec.rb b/spec/features/registrar/sign_in/mobile_id_spec.rb index 5373be4ec..bc26daff5 100644 --- a/spec/features/registrar/sign_in/mobile_id_spec.rb +++ b/spec/features/registrar/sign_in/mobile_id_spec.rb @@ -4,7 +4,6 @@ RSpec.feature 'Mobile ID login', db: true do given!(:api_user) { create(:api_user, identity_code: 1234) } background do - Setting.registrar_ip_whitelist_enabled = false digidoc_client = instance_double(Digidoc::Client, authenticate: OpenStruct.new(user_id_code: 1234), session_code: 1234) allow(Digidoc::Client).to receive(:new).and_return(digidoc_client) end diff --git a/spec/features/registrar/sign_in/password_spec.rb b/spec/features/registrar/sign_in/password_spec.rb index f0cc3ed49..64e22b8f4 100644 --- a/spec/features/registrar/sign_in/password_spec.rb +++ b/spec/features/registrar/sign_in/password_spec.rb @@ -1,10 +1,6 @@ require 'rails_helper' RSpec.feature 'Registrar area password sign-in' do - background do - Setting.registrar_ip_whitelist_enabled = false - end - scenario 'signs in the user with valid credentials' do create(:api_user_with_unlimited_balance, active: true, diff --git a/spec/features/registrar/sign_out_spec.rb b/spec/features/registrar/sign_out_spec.rb index 33acc52ab..09ae011cd 100644 --- a/spec/features/registrar/sign_out_spec.rb +++ b/spec/features/registrar/sign_out_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' RSpec.feature 'Registrar area sign-out', settings: false do background do - Setting.registrar_ip_whitelist_enabled = false sign_in_to_registrar_area(user: create(:api_user_with_unlimited_balance)) end diff --git a/spec/models/authorization/restricted_ip_spec.rb b/spec/models/authorization/restricted_ip_spec.rb index e64a1739f..b432d46e4 100644 --- a/spec/models/authorization/restricted_ip_spec.rb +++ b/spec/models/authorization/restricted_ip_spec.rb @@ -2,6 +2,14 @@ require 'rails_helper' RSpec.describe Authorization::RestrictedIP do describe '::enabled?', db: true, settings: false do + before do + @original_registrar_ip_whitelist_enabled = Setting.registrar_ip_whitelist_enabled + end + + after do + Setting.registrar_ip_whitelist_enabled = @original_registrar_ip_whitelist_enabled + end + context 'when "registrar_ip_whitelist_enabled" is true' do before do Setting.registrar_ip_whitelist_enabled = true @@ -13,10 +21,6 @@ RSpec.describe Authorization::RestrictedIP do end context 'when "registrar_ip_whitelist_enabled" is false' do - before do - Setting.registrar_ip_whitelist_enabled = false - end - specify do expect(described_class).to_not be_enabled end diff --git a/spec/requests/registrar/ip_restriction_spec.rb b/spec/requests/registrar/ip_restriction_spec.rb index 3effb72a6..69ba33602 100644 --- a/spec/requests/registrar/ip_restriction_spec.rb +++ b/spec/requests/registrar/ip_restriction_spec.rb @@ -1,6 +1,14 @@ require 'rails_helper' RSpec.describe 'Registrar area IP restriction', settings: false do + before do + @original_registrar_ip_whitelist_enabled = Setting.registrar_ip_whitelist_enabled + end + + after do + Setting.registrar_ip_whitelist_enabled = @original_registrar_ip_whitelist_enabled + end + context 'when authenticated' do before do sign_in_to_registrar_area @@ -39,10 +47,6 @@ RSpec.describe 'Registrar area IP restriction', settings: false do end context 'when IP restriction is disabled' do - before do - Setting.registrar_ip_whitelist_enabled = false - end - specify do get registrar_root_url follow_redirect! @@ -77,10 +81,6 @@ RSpec.describe 'Registrar area IP restriction', settings: false do end context 'when IP restriction is disabled' do - before do - Setting.registrar_ip_whitelist_enabled = false - end - specify do get registrar_login_path expect(response).to be_success diff --git a/spec/requests/registrar/sign_in/password_spec.rb b/spec/requests/registrar/sign_in/password_spec.rb index f419ffa01..b875de98a 100644 --- a/spec/requests/registrar/sign_in/password_spec.rb +++ b/spec/requests/registrar/sign_in/password_spec.rb @@ -3,10 +3,6 @@ require 'rails_helper' RSpec.describe 'Registrar area password sign-in', settings: false do let!(:user) { create(:api_user, active: true, login: 'test', password: 'testtest') } - before do - Setting.registrar_ip_whitelist_enabled = false - end - it 'signs the user in' do post registrar_sessions_path, depp_user: { tag: 'test', password: 'testtest' } follow_redirect! diff --git a/spec/requests/registrar/sign_out_spec.rb b/spec/requests/registrar/sign_out_spec.rb index 086b95f64..4f5b099c0 100644 --- a/spec/requests/registrar/sign_out_spec.rb +++ b/spec/requests/registrar/sign_out_spec.rb @@ -2,7 +2,6 @@ require 'rails_helper' RSpec.describe 'Registrar area sign-out', settings: false do before do - Setting.registrar_ip_whitelist_enabled = false sign_in_to_registrar_area end From 73a96141b6b31c593fa4be60cf2736639141145c Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 6 Jun 2018 05:38:17 +0300 Subject: [PATCH 08/14] Update registrar factory --- spec/factories/registrar.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/factories/registrar.rb b/spec/factories/registrar.rb index 3b2a3e730..c77e8dc66 100644 --- a/spec/factories/registrar.rb +++ b/spec/factories/registrar.rb @@ -10,6 +10,7 @@ FactoryBot.define do email 'test@test.com' country_code 'US' accounting_customer_code 'test' + language 'en' factory :registrar_with_unlimited_balance do after :create do |registrar| From 19e0e7c8f81d130a4020979811dd48e7706786fa Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 6 Jun 2018 06:27:29 +0300 Subject: [PATCH 09/14] Improve test env config --- config/environments/test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 595a6a05d..3da6a0d68 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -40,7 +40,9 @@ Rails.application.configure do # Raises error for missing translations config.action_view.raise_on_missing_translations = true - config.cache_store = :null_store + # If set to :null_store, Setting.x returns nil after first spec runs (database is emptied) + config.cache_store = :memory_store + config.logger = ActiveSupport::Logger.new(nil) end Que.mode = :sync \ No newline at end of file From d83e11a85db68bdaf0ae99c438fe064dd845398f Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 6 Jun 2018 07:21:30 +0300 Subject: [PATCH 10/14] Remove unused methods --- app/models/domain.rb | 15 --------------- app/models/domain_cron.rb | 2 +- spec/models/domain_spec.rb | 32 -------------------------------- 3 files changed, 1 insertion(+), 48 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index 55596aedf..1486bf5e5 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -199,21 +199,6 @@ class Domain < ActiveRecord::Base statuses.include? DomainStatus::SERVER_TECH_CHANGE_PROHIBITED end - def self.clean_expired_pendings - ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__) - DomainCron.send(__method__) - end - - def self.start_redemption_grace_period - ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__) - DomainCron.send(__method__) - end - - def self.destroy_delete_candidates - ActiveSupport::Deprecation.instance.deprecation_warning(DomainCron, __method__) - DomainCron.send(__method__) - end - class << self def nameserver_required? Setting.nameserver_required diff --git a/app/models/domain_cron.rb b/app/models/domain_cron.rb index fb3b7644d..80bf32c5a 100644 --- a/app/models/domain_cron.rb +++ b/app/models/domain_cron.rb @@ -92,7 +92,7 @@ class DomainCron if domain.save(validate: false) ::PaperTrail.whodunnit = "cron - #{__method__}" DomainDeleteJob.enqueue(domain.id, run_at: rand(((24*60) - (DateTime.now.hour * 60 + DateTime.now.minute))).minutes.from_now) - STDOUT << "#{Time.zone.now.utc} Domain.destroy_delete_candidates: job added by deleteCandidate status ##{domain.id} (#{domain.name})\n" unless Rails.env.test? + STDOUT << "#{Time.zone.now.utc} DomainCron.destroy_delete_candidates: job added by deleteCandidate status ##{domain.id} (#{domain.name})\n" unless Rails.env.test? c += 1 end end diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index cc1fe52a2..6b282d651 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -108,30 +108,6 @@ RSpec.describe Domain do @domain.registrant_update_confirmable?('123').should == false end - it 'should not find any domain pendings to clean' do - Domain.clean_expired_pendings.should == 0 - end - - it 'should not find any domains with wrong pendings' do - domain = create(:domain) - domain.registrant_verification_asked!('frame-str', '1') - domain.registrant_verification_asked_at = 30.days.ago - domain.save - - Domain.clean_expired_pendings.should == 0 - end - - it 'should clean domain pendings' do - domain = create(:domain) - domain.registrant_verification_asked!('frame-str', '1') - domain.registrant_verification_asked_at = 30.days.ago - domain.pending_delete! - - DomainCron.clean_expired_pendings.should == 1 - domain.reload.pending_delete?.should == false - domain.pending_json.should == {} - end - it 'should expire domains' do Setting.expire_warning_period = 1 Setting.redemption_grace_period = 1 @@ -164,14 +140,6 @@ RSpec.describe Domain do @domain.statuses.include?(DomainStatus::EXPIRED).should == true end - it 'should start redemption grace period' do - domain = create(:domain) - - DomainCron.start_redemption_grace_period - domain.reload - domain.statuses.include?(DomainStatus::SERVER_HOLD).should == false - end - context 'with time period settings' do before :example do @save_days_to_renew = Setting.days_to_renew_domain_before_expire From eb0d799207713313223021ba6cc2492847296326 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 6 Jun 2018 07:23:39 +0300 Subject: [PATCH 11/14] Specify view extensions explicitly --- spec/views/admin/billing/prices/_form.html.erb_spec.rb | 2 +- spec/views/admin/dns/zones/index.html.erb_spec.rb | 2 +- spec/views/admin/domains/edit.html.erb_spec.rb | 4 ++-- spec/views/registrar/contacts/_form.haml_spec.rb | 10 +++++----- spec/views/registrar/contacts/show.haml_spec.rb | 10 +++++----- spec/views/registrar/domains/_form.haml_spec.rb | 8 ++++---- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/spec/views/admin/billing/prices/_form.html.erb_spec.rb b/spec/views/admin/billing/prices/_form.html.erb_spec.rb index 9f4ba785c..2349a5d1e 100644 --- a/spec/views/admin/billing/prices/_form.html.erb_spec.rb +++ b/spec/views/admin/billing/prices/_form.html.erb_spec.rb @@ -12,7 +12,7 @@ RSpec.describe 'admin/billing/prices/_form' do allow(view).to receive(:durations).and_return([]) end - stub_template '_form_errors' => '' + stub_template '_form_errors.html.erb' => '' end describe 'price' do diff --git a/spec/views/admin/dns/zones/index.html.erb_spec.rb b/spec/views/admin/dns/zones/index.html.erb_spec.rb index 3ebbc468d..e066ce79b 100644 --- a/spec/views/admin/dns/zones/index.html.erb_spec.rb +++ b/spec/views/admin/dns/zones/index.html.erb_spec.rb @@ -5,7 +5,7 @@ RSpec.describe 'admin/dns/zones/index' do before :example do assign(:zones, zones) - stub_template '_zone' => 'zone-row' + stub_template '_zone.html.erb' => 'zone-row' end it 'has title' do diff --git a/spec/views/admin/domains/edit.html.erb_spec.rb b/spec/views/admin/domains/edit.html.erb_spec.rb index 212b8091b..3f74a1f2e 100644 --- a/spec/views/admin/domains/edit.html.erb_spec.rb +++ b/spec/views/admin/domains/edit.html.erb_spec.rb @@ -13,8 +13,8 @@ RSpec.describe 'admin/domains/edit' do assign(:domain, domain) - stub_template '_form' => '' - stub_template '_force_delete_dialog' => '' + stub_template '_form.html.erb' => '' + stub_template '_force_delete_dialog.html.erb' => '' end it 'has force_delete_toggle_btn' do diff --git a/spec/views/registrar/contacts/_form.haml_spec.rb b/spec/views/registrar/contacts/_form.haml_spec.rb index c1588f0ec..4feead879 100644 --- a/spec/views/registrar/contacts/_form.haml_spec.rb +++ b/spec/views/registrar/contacts/_form.haml_spec.rb @@ -10,11 +10,11 @@ RSpec.describe 'registrar/contacts/_form' do assign(:contact, contact) - stub_template 'registrar/shared/_error_messages' => '' - stub_template 'registrar/contacts/form/_general' => '' - stub_template 'registrar/contacts/form/_address' => 'address info' - stub_template 'registrar/contacts/form/_code' => '' - stub_template 'registrar/contacts/form/_legal_document' => '' + stub_template 'registrar/shared/_error_messages.haml' => '' + stub_template 'registrar/contacts/form/_general.html.haml' => '' + stub_template 'registrar/contacts/form/_address.html.haml' => 'address info' + stub_template 'registrar/contacts/form/_code.html.haml' => '' + stub_template 'registrar/contacts/form/_legal_document.html.haml' => '' end context 'when address processing is enabled' do diff --git a/spec/views/registrar/contacts/show.haml_spec.rb b/spec/views/registrar/contacts/show.haml_spec.rb index 65fca2863..666d151ff 100644 --- a/spec/views/registrar/contacts/show.haml_spec.rb +++ b/spec/views/registrar/contacts/show.haml_spec.rb @@ -5,11 +5,11 @@ RSpec.describe 'registrar/contacts/show' do before do assign(:contact, contact) - stub_template 'shared/_title' => '' - stub_template 'registrar/contacts/partials/_general' => '' - stub_template 'registrar/contacts/partials/_statuses' => '' - stub_template 'registrar/contacts/partials/_domains' => '' - stub_template 'registrar/contacts/partials/_address' => 'address info' + stub_template 'shared/_title.html.haml' => '' + stub_template 'registrar/contacts/partials/_general.html.haml' => '' + stub_template 'registrar/contacts/partials/_statuses.html.haml' => '' + stub_template 'registrar/contacts/partials/_domains.html.haml' => '' + stub_template 'registrar/contacts/partials/_address.html.haml' => 'address info' end context 'when address processing is enabled' do diff --git a/spec/views/registrar/domains/_form.haml_spec.rb b/spec/views/registrar/domains/_form.haml_spec.rb index f0e646fb8..723ab081b 100644 --- a/spec/views/registrar/domains/_form.haml_spec.rb +++ b/spec/views/registrar/domains/_form.haml_spec.rb @@ -10,10 +10,10 @@ RSpec.describe 'registrar/domains/_form' do assign(:domain, domain) - stub_template 'registrar/domains/form/_general' => '' - stub_template 'registrar/domains/form/_contacts' => '' - stub_template 'registrar/domains/form/_nameservers' => '' - stub_template 'registrar/domains/form/_dnskeys' => '' + stub_template 'registrar/domains/form/_general.html.haml' => '' + stub_template 'registrar/domains/form/_contacts.html.haml' => '' + stub_template 'registrar/domains/form/_nameservers.html.haml' => '' + stub_template 'registrar/domains/form/_dnskeys.html.haml' => '' end it 'has legal document' do From b62158ae8d263ede848b59f521a386595245e5e0 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 6 Jun 2018 07:28:39 +0300 Subject: [PATCH 12/14] Remove unneeded setup step --- test/integration/registrar/domain_transfers_test.rb | 1 - test/integration/registrar/nameserver_replacement_test.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/test/integration/registrar/domain_transfers_test.rb b/test/integration/registrar/domain_transfers_test.rb index 4cd6fc66c..59202c624 100644 --- a/test/integration/registrar/domain_transfers_test.rb +++ b/test/integration/registrar/domain_transfers_test.rb @@ -2,7 +2,6 @@ require 'test_helper' class RegistrarDomainTransfersTest < ActionDispatch::IntegrationTest setup do - WebMock.reset! login_as users(:api_goodnames) end diff --git a/test/integration/registrar/nameserver_replacement_test.rb b/test/integration/registrar/nameserver_replacement_test.rb index 8ed0f9419..8469fb5bf 100644 --- a/test/integration/registrar/nameserver_replacement_test.rb +++ b/test/integration/registrar/nameserver_replacement_test.rb @@ -2,7 +2,6 @@ require 'test_helper' class RegistrarNameserverReplacementTest < ActionDispatch::IntegrationTest setup do - WebMock.reset! login_as users(:api_goodnames) end From 0863b4ca25acf0fdeab9acb93972691f151c347f Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 6 Jun 2018 11:30:47 +0300 Subject: [PATCH 13/14] Remove default comments --- config/environments/test.rb | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 3da6a0d68..3b82ee748 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,48 +1,28 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - # The test environment is used exclusively to run your application's - # test suite. You never need to work with it otherwise. Remember that - # your test database is "scratch space" for the test suite and is wiped - # and recreated between test runs. Don't rely on the data there! config.cache_classes = true - - # Do not eager load code on boot. This avoids loading your whole application - # just for the purpose of running a single test. If you are using a tool that - # preloads Rails for running tests, you may have to set it to true. config.eager_load = true - # Configure static file server for tests with Cache-Control for performance. config.serve_static_files = true config.static_cache_control = 'public, max-age=3600' - # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false - # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false - # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false - - # Tell Action Mailer not to deliver emails to the real world. - # The :test delivery method accumulates sent emails in the - # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - - # Randomize the order test cases are executed. config.active_support.test_order = :random - # Print deprecation notices to the stderr. config.active_support.deprecation = :raise + config.logger = ActiveSupport::Logger.new(nil) - # Raises error for missing translations config.action_view.raise_on_missing_translations = true # If set to :null_store, Setting.x returns nil after first spec runs (database is emptied) config.cache_store = :memory_store - config.logger = ActiveSupport::Logger.new(nil) end Que.mode = :sync \ No newline at end of file From 7a5a46b158dcd1cb2597606711e0a202fa1ded65 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 6 Jun 2018 22:04:26 +0300 Subject: [PATCH 14/14] Fix CodeClimate issues --- app/models/sorted_country.rb | 8 ++++---- lib/core_ext/array.rb | 2 +- lib/gem_ext/builder.rb | 20 +++++++++++--------- lib/gem_ext/paper_trail.rb | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/models/sorted_country.rb b/app/models/sorted_country.rb index e4f2ad330..19ad5f4f3 100644 --- a/app/models/sorted_country.rb +++ b/app/models/sorted_country.rb @@ -3,13 +3,13 @@ class SortedCountry include ActionView::Helpers def all_options(selected = nil) - quick_options = options_for_select(quick_list, { selected: selected }) + quick_options = options_for_select(quick_list, selected: selected) # no double select - selected = quick_list.map(&:second).include?(selected) ? '' : selected + selected = quick_list.map(&:second).include?(selected) ? '' : selected - all_options = options_for_select([['---', '---']] + all_sorted_truncated, - { selected: selected, disabled: ['---'] }) + all_options = options_for_select([['---', '---']] + all_sorted_truncated, + selected: selected, disabled: ['---']) quick_options + all_options end diff --git a/lib/core_ext/array.rb b/lib/core_ext/array.rb index ec280ab81..2dee1d56a 100644 --- a/lib/core_ext/array.rb +++ b/lib/core_ext/array.rb @@ -2,4 +2,4 @@ class Array def include_any?(*args) (self & args).any? end -end \ No newline at end of file +end diff --git a/lib/gem_ext/builder.rb b/lib/gem_ext/builder.rb index 8f2945040..d4ebe2efd 100644 --- a/lib/gem_ext/builder.rb +++ b/lib/gem_ext/builder.rb @@ -1,12 +1,14 @@ -class Builder::XmlMarkup - def epp_head - instruct! - epp( - 'xmlns' => 'https://epp.tld.ee/schema/epp-ee-1.0.xsd', - 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation' => 'lib/schemas/epp-ee-1.0.xsd' - ) do - yield +module Builder + class XmlMarkup + def epp_head + instruct! + epp( + 'xmlns' => 'https://epp.tld.ee/schema/epp-ee-1.0.xsd', + 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', + 'xsi:schemaLocation' => 'lib/schemas/epp-ee-1.0.xsd' + ) do + yield + end end end end diff --git a/lib/gem_ext/paper_trail.rb b/lib/gem_ext/paper_trail.rb index 9dec5fb12..200e71d48 100644 --- a/lib/gem_ext/paper_trail.rb +++ b/lib/gem_ext/paper_trail.rb @@ -8,7 +8,7 @@ end # Store console and rake changes in versions if defined?(::Rails::Console) || File.basename($PROGRAM_NAME).split(' ').first == 'spring' PaperTrail.whodunnit = "console-#{`whoami`.strip}" -elsif File.basename($PROGRAM_NAME) == "rake" +elsif File.basename($PROGRAM_NAME) == 'rake' # rake username does not work when spring enabled PaperTrail.whodunnit = "rake-#{`whoami`.strip} #{ARGV.join ' '}" end