From fd95d76c49087ce852b860c37baac1c9ffe321fa Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 18 Dec 2019 05:40:53 +0200 Subject: [PATCH 01/15] Remove dead code --- app/models/contact.rb | 2 -- app/models/domain.rb | 1 - app/models/legal_document.rb | 3 +-- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 1143c0e34..11c8bdc8a 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -21,8 +21,6 @@ class Contact < ApplicationRecord alias_attribute :kind, :ident_type alias_attribute :copy_from_id, :original_id # Old attribute name; for PaperTrail - accepts_nested_attributes_for :legal_documents - scope :email_verification_failed, lambda { joins('LEFT JOIN email_address_verifications emv ON contacts.email = emv.email') .where('success = false and verified_at IS NOT NULL') diff --git a/app/models/domain.rb b/app/models/domain.rb index c60d11f3f..b706744bd 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -55,7 +55,6 @@ class Domain < ApplicationRecord accepts_nested_attributes_for :dnskeys, allow_destroy: true has_many :legal_documents, as: :documentable - accepts_nested_attributes_for :legal_documents, reject_if: proc { |attrs| attrs[:body].blank? } has_many :registrant_verifications, dependent: :destroy after_initialize do diff --git a/app/models/legal_document.rb b/app/models/legal_document.rb index 446087124..0328e4b03 100644 --- a/app/models/legal_document.rb +++ b/app/models/legal_document.rb @@ -1,5 +1,4 @@ class LegalDocument < ApplicationRecord - cattr_accessor :explicitly_write_file include EppErrors MIN_BODY_SIZE = (1.37 * 3.kilobytes).ceil @@ -44,7 +43,7 @@ class LegalDocument < ApplicationRecord break unless File.file?(path) end - File.open(path, 'wb') { |f| f.write(binary) } if !Rails.env.test? || self.class.explicitly_write_file + File.open(path, 'wb') { |f| f.write(binary) } if !Rails.env.test? self.path = path self.checksum = digest end From 1c042877d54be3a0bc271769a85a41a4a54e332f Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 18 Dec 2019 05:52:13 +0200 Subject: [PATCH 02/15] Remove unused routes --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 1c03129db..2f341866b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -202,7 +202,7 @@ Rails.application.routes.draw do resources :zonefiles resources :zones, controller: 'dns/zones', except: %i[show destroy] - resources :legal_documents + resources :legal_documents, only: :show resources :prices, controller: 'billing/prices', except: %i[show destroy] do member do patch :expire From 24ba00896e36f4ec7d8dc9e3f9e2e23fb9b31e9d Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 18 Dec 2019 05:52:39 +0200 Subject: [PATCH 03/15] Add fixture --- test/fixtures/legal_documents.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 test/fixtures/legal_documents.yml diff --git a/test/fixtures/legal_documents.yml b/test/fixtures/legal_documents.yml new file mode 100644 index 000000000..3781f5b0c --- /dev/null +++ b/test/fixtures/legal_documents.yml @@ -0,0 +1,2 @@ +one: + documentable: shop (Domain) From 15a8a13a5ddad1f42e9e4ce0a08624a0a84e9f04 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 19 Dec 2019 13:26:17 +0200 Subject: [PATCH 04/15] Make `legal_documents.path` database column NOT NULL --- ...20191219112434_change_legal_documents_path_to_not_null.rb | 5 +++++ db/structure.sql | 5 ++--- test/fixtures/legal_documents.yml | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20191219112434_change_legal_documents_path_to_not_null.rb diff --git a/db/migrate/20191219112434_change_legal_documents_path_to_not_null.rb b/db/migrate/20191219112434_change_legal_documents_path_to_not_null.rb new file mode 100644 index 000000000..1198d00f0 --- /dev/null +++ b/db/migrate/20191219112434_change_legal_documents_path_to_not_null.rb @@ -0,0 +1,5 @@ +class ChangeLegalDocumentsPathToNotNull < ActiveRecord::Migration[5.0] + def change + change_column_null :legal_documents, :path, false + end +end diff --git a/db/structure.sql b/db/structure.sql index 0ce89f0d2..5ce5c7382 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1074,7 +1074,7 @@ CREATE TABLE public.legal_documents ( documentable_type character varying, created_at timestamp without time zone, creator_str character varying, - path character varying, + path character varying NOT NULL, checksum character varying ); @@ -4828,6 +4828,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20191203083643'), ('20191206183853'), ('20191212133136'), +('20191219112434'), ('20191227110904'), ('20200113091254'), ('20200115102202'), @@ -4849,5 +4850,3 @@ INSERT INTO "schema_migrations" (version) VALUES ('20200811074839'), ('20200812090409'), ('20200812125810'); - - diff --git a/test/fixtures/legal_documents.yml b/test/fixtures/legal_documents.yml index 3781f5b0c..f4b4213c9 100644 --- a/test/fixtures/legal_documents.yml +++ b/test/fixtures/legal_documents.yml @@ -1,2 +1,3 @@ one: documentable: shop (Domain) + path: some From 5004e2982484eebbb11ef82d96786e94c9c312cd Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 19 Dec 2019 14:53:53 +0200 Subject: [PATCH 05/15] ChangeLegalDocumentsDocumentTypeToNotNull --- ...24429_change_legal_documents_document_type_to_not_null.rb | 5 +++++ db/structure.sql | 3 ++- test/fixtures/legal_documents.yml | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20191219124429_change_legal_documents_document_type_to_not_null.rb diff --git a/db/migrate/20191219124429_change_legal_documents_document_type_to_not_null.rb b/db/migrate/20191219124429_change_legal_documents_document_type_to_not_null.rb new file mode 100644 index 000000000..dc6b86a3e --- /dev/null +++ b/db/migrate/20191219124429_change_legal_documents_document_type_to_not_null.rb @@ -0,0 +1,5 @@ +class ChangeLegalDocumentsDocumentTypeToNotNull < ActiveRecord::Migration[5.0] + def change + change_column_null :legal_documents, :document_type, false + end +end diff --git a/db/structure.sql b/db/structure.sql index 5ce5c7382..377259100 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1069,7 +1069,7 @@ ALTER SEQUENCE public.invoices_id_seq OWNED BY public.invoices.id; CREATE TABLE public.legal_documents ( id integer NOT NULL, - document_type character varying, + document_type character varying NOT NULL, documentable_id integer, documentable_type character varying, created_at timestamp without time zone, @@ -4829,6 +4829,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20191206183853'), ('20191212133136'), ('20191219112434'), +('20191219124429'), ('20191227110904'), ('20200113091254'), ('20200115102202'), diff --git a/test/fixtures/legal_documents.yml b/test/fixtures/legal_documents.yml index f4b4213c9..4de700bd1 100644 --- a/test/fixtures/legal_documents.yml +++ b/test/fixtures/legal_documents.yml @@ -1,3 +1,4 @@ one: documentable: shop (Domain) + document_type: pdf path: some From 0161556c541abbc8cb522e7a48cebc88f2fc0ca4 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 19 Dec 2019 16:12:41 +0200 Subject: [PATCH 06/15] Add test --- test/models/legal_document_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 test/models/legal_document_test.rb diff --git a/test/models/legal_document_test.rb b/test/models/legal_document_test.rb new file mode 100644 index 000000000..f09c52047 --- /dev/null +++ b/test/models/legal_document_test.rb @@ -0,0 +1,14 @@ +require 'test_helper' + +class LegalDocumentTest < ActiveSupport::TestCase + def test_valid_legal_document_fixture_is_valid + assert valid_legal_document.valid?, proc { valid_legal_document.errors.full_messages } + end + + private + + def valid_legal_document + legal_documents(:one) + end +end + From 66e05c7791093d1eea85d2f8e58cac603b210720 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Fri, 28 Aug 2020 12:58:52 +0500 Subject: [PATCH 07/15] Fix tests & CC --- app/models/legal_document.rb | 2 +- test/integration/epp/domain/delete/base_test.rb | 11 ++++++----- test/integration/epp/domain/transfer/request_test.rb | 2 +- test/jobs/domain_update_confirm_job_test.rb | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/models/legal_document.rb b/app/models/legal_document.rb index 0328e4b03..e4aab5869 100644 --- a/app/models/legal_document.rb +++ b/app/models/legal_document.rb @@ -43,7 +43,7 @@ class LegalDocument < ApplicationRecord break unless File.file?(path) end - File.open(path, 'wb') { |f| f.write(binary) } if !Rails.env.test? + File.open(path, 'wb') { |f| f.write(binary) } unless Rails.env.test? self.path = path self.checksum = digest end diff --git a/test/integration/epp/domain/delete/base_test.rb b/test/integration/epp/domain/delete/base_test.rb index c7147957c..bfdfa9f75 100644 --- a/test/integration/epp/domain/delete/base_test.rb +++ b/test/integration/epp/domain/delete/base_test.rb @@ -27,7 +27,7 @@ class EppDomainDeleteBaseTest < EppTestCase - dGVzdCBmYWlsCg== + #{'test' * 2000} @@ -35,6 +35,7 @@ class EppDomainDeleteBaseTest < EppTestCase XML post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + # binding.pry assert_includes Domain.find_by(name: 'invalid.test').statuses, DomainStatus::PENDING_DELETE_CONFIRMATION assert_epp_response :completed_successfully_action_pending end @@ -54,7 +55,7 @@ class EppDomainDeleteBaseTest < EppTestCase - dGVzdCBmYWlsCg== + #{'test' * 2000} @@ -82,7 +83,7 @@ class EppDomainDeleteBaseTest < EppTestCase - dGVzdCBmYWlsCg== + #{'test' * 2000} @@ -113,7 +114,7 @@ class EppDomainDeleteBaseTest < EppTestCase - dGVzdCBmYWlsCg== + #{'test' * 2000} @@ -144,7 +145,7 @@ class EppDomainDeleteBaseTest < EppTestCase - dGVzdCBmYWlsCg== + #{'test' * 2000} diff --git a/test/integration/epp/domain/transfer/request_test.rb b/test/integration/epp/domain/transfer/request_test.rb index c7a838ca6..1c3614421 100644 --- a/test/integration/epp/domain/transfer/request_test.rb +++ b/test/integration/epp/domain/transfer/request_test.rb @@ -150,7 +150,7 @@ class EppDomainTransferRequestTest < EppTestCase - test + #{'test' * 2000} diff --git a/test/jobs/domain_update_confirm_job_test.rb b/test/jobs/domain_update_confirm_job_test.rb index 59bbf758d..9cca81eb7 100644 --- a/test/jobs/domain_update_confirm_job_test.rb +++ b/test/jobs/domain_update_confirm_job_test.rb @@ -7,7 +7,7 @@ class DomainUpdateConfirmJobTest < ActiveSupport::TestCase @domain = domains(:shop) @new_registrant = contacts(:william) @user = users(:api_bestnames) - @legal_doc_path = 'test/fixtures/files/legaldoc.pdf' + @legal_doc_path = "#{'test' * 2000}" @domain.update!(pending_json: { new_registrant_id: @new_registrant.id, new_registrant_name: @new_registrant.name, From 44e9b1b5c46720c4415fcafa3fd47e8fe0c9ec9a Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 17 Sep 2019 18:24:15 +0300 Subject: [PATCH 08/15] Remove hardcoded value --- app/controllers/epp/base_controller.rb | 2 +- config/application.yml.sample | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/epp/base_controller.rb b/app/controllers/epp/base_controller.rb index e9d58a4ed..ee8592c82 100644 --- a/app/controllers/epp/base_controller.rb +++ b/app/controllers/epp/base_controller.rb @@ -368,7 +368,7 @@ module Epp end def session_timeout_reached? - timeout = 5.minutes + timeout = ENV['epp_session_timeout_seconds'].to_i.seconds epp_session.updated_at < (Time.zone.now - timeout) end diff --git a/config/application.yml.sample b/config/application.yml.sample index 2cd19b768..c35a8a5bb 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -153,6 +153,8 @@ lhv_keystore_password: lhv_ca_file: # Needed only in dev mode lhv_dev_mode: 'false' +epp_session_timeout_seconds: '300' + # Since the keys for staging are absent from the repo, we need to supply them separate for testing. test: payments_seb_bank_certificate: 'test/fixtures/files/seb_bank_cert.pem' From 4c884cce3781faad036e7466953c3d188996ecf7 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 18 Sep 2019 17:35:29 +0300 Subject: [PATCH 09/15] Clear expired EPP sessions Fixes #711 --- lib/tasks/epp/clear_expired_sessions.rake | 7 +++++++ test/tasks/epp/clear_expired_sessions_test.rb | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 lib/tasks/epp/clear_expired_sessions.rake create mode 100644 test/tasks/epp/clear_expired_sessions_test.rb diff --git a/lib/tasks/epp/clear_expired_sessions.rake b/lib/tasks/epp/clear_expired_sessions.rake new file mode 100644 index 000000000..296b463d9 --- /dev/null +++ b/lib/tasks/epp/clear_expired_sessions.rake @@ -0,0 +1,7 @@ +namespace :epp do + desc 'Clear expired EPP sessions' + + task clear_expired_sessions: :environment do + Epp::ExpiredSessions.new(EppSession.expired).clear + end +end diff --git a/test/tasks/epp/clear_expired_sessions_test.rb b/test/tasks/epp/clear_expired_sessions_test.rb new file mode 100644 index 000000000..bd6c5c14f --- /dev/null +++ b/test/tasks/epp/clear_expired_sessions_test.rb @@ -0,0 +1,20 @@ +require 'test_helper' + +class EppClearExpiredSessionsTaskTest < ActiveSupport::TestCase + def test_clears_expired_epp_sessions + idle_timeout = 0.second + EppSession.idle_timeout = idle_timeout + session = epp_sessions(:api_bestnames) + session.update!(updated_at: Time.zone.now - idle_timeout - 1.second) + + run_task + + assert_nil EppSession.find_by(session_id: session.session_id) + end + + private + + def run_task + Rake::Task['epp:clear_expired_sessions'].execute + end +end From 9baa65a7759740d4680e070ca201a03d5d74ca41 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 18 Sep 2019 17:35:52 +0300 Subject: [PATCH 10/15] Refactor --- app/controllers/epp/base_controller.rb | 28 +++----- app/models/epp/expired_sessions.rb | 13 ++++ app/models/epp_session.rb | 22 +++++++ test/integration/epp/base_test.rb | 64 +++++++++++++++++++ test/models/epp_session_test.rb | 40 ++++++++++++ test/tasks/epp/clear_expired_sessions_test.rb | 14 +++- 6 files changed, 159 insertions(+), 22 deletions(-) create mode 100644 app/models/epp/expired_sessions.rb diff --git a/app/controllers/epp/base_controller.rb b/app/controllers/epp/base_controller.rb index ee8592c82..51561f1ee 100644 --- a/app/controllers/epp/base_controller.rb +++ b/app/controllers/epp/base_controller.rb @@ -10,7 +10,8 @@ module Epp before_action :latin_only before_action :validate_against_schema before_action :validate_request - before_action :update_epp_session, if: -> { signed_in? } + before_action :enforce_epp_session_timeout, if: :signed_in? + before_action :iptables_counter_update, if: :signed_in? around_action :wrap_exceptions @@ -349,32 +350,21 @@ module Epp raise 'EPP session id is empty' unless epp_session_id.present? end - def update_epp_session - iptables_counter_update - - if session_timeout_reached? - @api_user = current_user # cache current_user for logging - epp_session.destroy - + def enforce_epp_session_timeout + if epp_session.timed_out? epp_errors << { - msg: t('session_timeout'), - code: '2201' + code: '2201', + msg: 'Authorization error: Session timeout', } - - handle_errors and return + handle_errors + epp_session.destroy! else - epp_session.update_column(:updated_at, Time.zone.now) + epp_session.update_last_access end end - def session_timeout_reached? - timeout = ENV['epp_session_timeout_seconds'].to_i.seconds - 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 diff --git a/app/models/epp/expired_sessions.rb b/app/models/epp/expired_sessions.rb new file mode 100644 index 000000000..f9fefac46 --- /dev/null +++ b/app/models/epp/expired_sessions.rb @@ -0,0 +1,13 @@ +module Epp + class ExpiredSessions + attr_reader :sessions + + def initialize(sessions) + @sessions = sessions + end + + def clear + sessions.find_each(&:destroy!) + end + end +end diff --git a/app/models/epp_session.rb b/app/models/epp_session.rb index 6427c503c..f833b4894 100644 --- a/app/models/epp_session.rb +++ b/app/models/epp_session.rb @@ -3,6 +3,11 @@ class EppSession < ApplicationRecord validates :session_id, uniqueness: true, presence: true + class_attribute :timeout + self.timeout = ENV['epp_session_timeout_seconds'].to_i.seconds + + alias_attribute :last_access, :updated_at + def self.limit_per_registrar 4 end @@ -11,4 +16,21 @@ class EppSession < ApplicationRecord count = where(user_id: registrar.api_users.ids).where('updated_at >= ?', Time.zone.now - 1.second).count count >= limit_per_registrar end + + def self.expired + interval = "#{timeout.parts.first.second} #{timeout.parts.first.first}" + where(':now > (updated_at + interval :interval)', now: Time.zone.now, interval: interval) + end + + def update_last_access + touch + end + + def timed_out? + (updated_at + self.class.timeout).past? + end + + def expired? + timed_out? + end end diff --git a/test/integration/epp/base_test.rb b/test/integration/epp/base_test.rb index 456e7b41e..2610ddb98 100644 --- a/test/integration/epp/base_test.rb +++ b/test/integration/epp/base_test.rb @@ -7,6 +7,14 @@ class DummyEppController < Epp::BaseController end class EppBaseTest < EppTestCase + setup do + @original_session_timeout = EppSession.timeout + end + + teardown do + EppSession.timeout = @original_session_timeout + end + def test_internal_error Rails.application.routes.draw do post 'epp/command/internal_error', to: 'dummy_epp#internal_error', @@ -81,6 +89,62 @@ class EppBaseTest < EppTestCase assert_epp_response :authorization_error end + def test_deletes_session_when_timed_out + now = Time.zone.parse('2010-07-05') + travel_to now + timeout = 0.second + EppSession.timeout = timeout + session = epp_sessions(:api_bestnames) + session.update!(updated_at: now - timeout - 1.second) + + authentication_enabled_epp_request_xml = <<-XML + + + + + + #{domains(:shop).name} + + + + + XML + post '/epp/command/info', { frame: authentication_enabled_epp_request_xml }, + 'HTTP_COOKIE' => "session=#{session.session_id}" + + assert_epp_response :authorization_error + assert_nil EppSession.find_by(session_id: session.session_id) + end + + def test_session_last_access_is_updated_when_not_timed_out + now = Time.zone.parse('2010-07-05') + travel_to now + timeout = 1.seconds + EppSession.timeout = timeout + session = epp_sessions(:api_bestnames) + session.last_access = now - timeout + + authentication_enabled_epp_request_xml = <<-XML + + + + + + #{domains(:shop).name} + + + + + XML + + post '/epp/command/info', { frame: authentication_enabled_epp_request_xml }, + 'HTTP_COOKIE' => "session=#{session.session_id}" + session.reload + + assert_epp_response :completed_successfully + assert_equal now, session.last_access + end + private def valid_command_path diff --git a/test/models/epp_session_test.rb b/test/models/epp_session_test.rb index 6f90e2445..8ed63f6ab 100644 --- a/test/models/epp_session_test.rb +++ b/test/models/epp_session_test.rb @@ -3,6 +3,11 @@ require 'test_helper' class EppSessionTest < ActiveSupport::TestCase setup do @epp_session = epp_sessions(:api_bestnames) + @original_session_timeout = EppSession.timeout + end + + teardown do + EppSession.timeout = @original_session_timeout end def test_valid @@ -60,4 +65,39 @@ class EppSessionTest < ActiveSupport::TestCase refute EppSession.limit_reached?(registrars(:bestnames)) end + + def test_expired_scope + now = Time.zone.parse('2010-07-05') + travel_to now + session = epp_sessions(:api_bestnames) + timeout = 0.seconds + EppSession.timeout = timeout + + session.update!(last_access: now - timeout - 1.second) + assert_includes EppSession.expired, session, 'Expired session should be returned' + + session.update!(last_access: now - timeout) + + assert_not_includes EppSession.expired, session, 'Unexpired session should not be returned' + end + + def test_expired_when_timed_out + now = Time.zone.parse('2010-07-05') + travel_to now + timeout = 0.seconds + EppSession.timeout = timeout + @epp_session.last_access = now - timeout - 1.second + + assert @epp_session.expired? + end + + def test_not_expired_when_not_timed_out + now = Time.zone.parse('2010-07-05') + travel_to now + timeout = 0.seconds + EppSession.timeout = timeout + @epp_session.last_access = now - timeout + + assert_not @epp_session.expired? + end end diff --git a/test/tasks/epp/clear_expired_sessions_test.rb b/test/tasks/epp/clear_expired_sessions_test.rb index bd6c5c14f..a839afb9a 100644 --- a/test/tasks/epp/clear_expired_sessions_test.rb +++ b/test/tasks/epp/clear_expired_sessions_test.rb @@ -1,11 +1,19 @@ require 'test_helper' class EppClearExpiredSessionsTaskTest < ActiveSupport::TestCase + setup do + @original_session_timeout = EppSession.timeout + end + + teardown do + EppSession.timeout = @original_session_timeout + end + def test_clears_expired_epp_sessions - idle_timeout = 0.second - EppSession.idle_timeout = idle_timeout + timeout = 0.second + EppSession.timeout = timeout session = epp_sessions(:api_bestnames) - session.update!(updated_at: Time.zone.now - idle_timeout - 1.second) + session.update!(updated_at: Time.zone.now - timeout - 1.second) run_task From 16db7358cd14a0ba68632b0343abd1ddd3329dc4 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Mon, 31 Aug 2020 13:48:11 +0500 Subject: [PATCH 11/15] Fix CC & tests --- app/controllers/epp/base_controller.rb | 1 + test/integration/epp/base_test.rb | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/epp/base_controller.rb b/app/controllers/epp/base_controller.rb index 51561f1ee..e3ac81815 100644 --- a/app/controllers/epp/base_controller.rb +++ b/app/controllers/epp/base_controller.rb @@ -365,6 +365,7 @@ module Epp def iptables_counter_update return if ENV['iptables_counter_enabled'].blank? && ENV['iptables_counter_enabled'] != 'true' + counter_update(current_user.registrar_code, ENV['iptables_server_ip']) end diff --git a/test/integration/epp/base_test.rb b/test/integration/epp/base_test.rb index 2610ddb98..2d19a6fa8 100644 --- a/test/integration/epp/base_test.rb +++ b/test/integration/epp/base_test.rb @@ -109,8 +109,8 @@ class EppBaseTest < EppTestCase XML - post '/epp/command/info', { frame: authentication_enabled_epp_request_xml }, - 'HTTP_COOKIE' => "session=#{session.session_id}" + post '/epp/command/info', params: { frame: authentication_enabled_epp_request_xml }, + headers: { 'HTTP_COOKIE' => "session=#{session.session_id}" } assert_epp_response :authorization_error assert_nil EppSession.find_by(session_id: session.session_id) @@ -137,8 +137,9 @@ class EppBaseTest < EppTestCase XML - post '/epp/command/info', { frame: authentication_enabled_epp_request_xml }, - 'HTTP_COOKIE' => "session=#{session.session_id}" + post '/epp/command/info', params: { frame: authentication_enabled_epp_request_xml }, + headers: { 'HTTP_COOKIE' => "session=#{session.session_id}" } + session.reload assert_epp_response :completed_successfully From 517b4b2fe2b2d935065000b51d449c9e5f75b472 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Thu, 3 Sep 2020 12:43:33 +0500 Subject: [PATCH 12/15] Add default timeout value & task test --- app/models/epp_session.rb | 2 +- test/tasks/epp/clear_expired_sessions_test.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/epp_session.rb b/app/models/epp_session.rb index f833b4894..f1b641aa0 100644 --- a/app/models/epp_session.rb +++ b/app/models/epp_session.rb @@ -4,7 +4,7 @@ class EppSession < ApplicationRecord validates :session_id, uniqueness: true, presence: true class_attribute :timeout - self.timeout = ENV['epp_session_timeout_seconds'].to_i.seconds + self.timeout = (ENV['epp_session_timeout_seconds'] || 300).to_i.seconds alias_attribute :last_access, :updated_at diff --git a/test/tasks/epp/clear_expired_sessions_test.rb b/test/tasks/epp/clear_expired_sessions_test.rb index a839afb9a..c7bebcd97 100644 --- a/test/tasks/epp/clear_expired_sessions_test.rb +++ b/test/tasks/epp/clear_expired_sessions_test.rb @@ -10,14 +10,15 @@ class EppClearExpiredSessionsTaskTest < ActiveSupport::TestCase end def test_clears_expired_epp_sessions - timeout = 0.second - EppSession.timeout = timeout + timeout = EppSession.timeout session = epp_sessions(:api_bestnames) + next_session = epp_sessions(:api_goodnames) session.update!(updated_at: Time.zone.now - timeout - 1.second) run_task assert_nil EppSession.find_by(session_id: session.session_id) + assert EppSession.find_by(session_id: next_session.session_id) end private From 6cbe9d814495c23e844b85e24addffdcd5f2fe06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 3 Sep 2020 13:05:55 +0300 Subject: [PATCH 13/15] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2e5749c0..321911525 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +03.09.2020 +* Improved error handling for epp requests without proper session [#1276](https://github.com/internetee/registry/pull/1276) + 01.09.2020 * Removed some unused settings from admin [#1668](https://github.com/internetee/registry/issues/1668) From 0189dcfca0d4db87c2c810034d83568f6daa120c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 3 Sep 2020 13:39:00 +0300 Subject: [PATCH 14/15] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 321911525..d0160ae6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ 03.09.2020 +* Refactored session timeout management [#711](https://github.com/internetee/registry/issues/711) * Improved error handling for epp requests without proper session [#1276](https://github.com/internetee/registry/pull/1276) 01.09.2020 From bfa60a9c178bd930ecd32e5e0af75dc1b0727a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Thu, 3 Sep 2020 13:42:41 +0300 Subject: [PATCH 15/15] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0160ae6d..74c177bf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ 03.09.2020 * Refactored session timeout management [#711](https://github.com/internetee/registry/issues/711) * Improved error handling for epp requests without proper session [#1276](https://github.com/internetee/registry/pull/1276) +* Refactored legal document epp extension [#1451](https://github.com/internetee/registry/pull/1451) 01.09.2020 * Removed some unused settings from admin [#1668](https://github.com/internetee/registry/issues/1668)