mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
Merge branch 'master' into refactor-contact-archivation
This commit is contained in:
commit
b2dab0d316
23 changed files with 253 additions and 36 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
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
|
01.09.2020
|
||||||
* Removed some unused settings from admin [#1668](https://github.com/internetee/registry/issues/1668)
|
* Removed some unused settings from admin [#1668](https://github.com/internetee/registry/issues/1668)
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,8 @@ module Epp
|
||||||
before_action :latin_only
|
before_action :latin_only
|
||||||
before_action :validate_against_schema
|
before_action :validate_against_schema
|
||||||
before_action :validate_request
|
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
|
around_action :wrap_exceptions
|
||||||
|
|
||||||
|
@ -349,32 +350,22 @@ module Epp
|
||||||
raise 'EPP session id is empty' unless epp_session_id.present?
|
raise 'EPP session id is empty' unless epp_session_id.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_epp_session
|
def enforce_epp_session_timeout
|
||||||
iptables_counter_update
|
if epp_session.timed_out?
|
||||||
|
|
||||||
if session_timeout_reached?
|
|
||||||
@api_user = current_user # cache current_user for logging
|
|
||||||
epp_session.destroy
|
|
||||||
|
|
||||||
epp_errors << {
|
epp_errors << {
|
||||||
msg: t('session_timeout'),
|
code: '2201',
|
||||||
code: '2201'
|
msg: 'Authorization error: Session timeout',
|
||||||
}
|
}
|
||||||
|
handle_errors
|
||||||
handle_errors and return
|
epp_session.destroy!
|
||||||
else
|
else
|
||||||
epp_session.update_column(:updated_at, Time.zone.now)
|
epp_session.update_last_access
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def session_timeout_reached?
|
|
||||||
timeout = 5.minutes
|
|
||||||
epp_session.updated_at < (Time.zone.now - timeout)
|
|
||||||
end
|
|
||||||
|
|
||||||
def iptables_counter_update
|
def iptables_counter_update
|
||||||
return if ENV['iptables_counter_enabled'].blank? && ENV['iptables_counter_enabled'] != 'true'
|
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'])
|
counter_update(current_user.registrar_code, ENV['iptables_server_ip'])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
module Epp
|
module Epp
|
||||||
class PollsController < BaseController
|
class PollsController < BaseController
|
||||||
skip_authorization_check # TODO: move authorization under ability
|
|
||||||
|
|
||||||
def poll
|
def poll
|
||||||
|
authorize! :manage, :poll
|
||||||
req_poll if params[:parsed_frame].css('poll').first['op'] == 'req'
|
req_poll if params[:parsed_frame].css('poll').first['op'] == 'req'
|
||||||
ack_poll if params[:parsed_frame].css('poll').first['op'] == 'ack'
|
ack_poll if params[:parsed_frame].css('poll').first['op'] == 'ack'
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,8 +22,6 @@ class Contact < ApplicationRecord
|
||||||
alias_attribute :kind, :ident_type
|
alias_attribute :kind, :ident_type
|
||||||
alias_attribute :copy_from_id, :original_id # Old attribute name; for PaperTrail
|
alias_attribute :copy_from_id, :original_id # Old attribute name; for PaperTrail
|
||||||
|
|
||||||
accepts_nested_attributes_for :legal_documents
|
|
||||||
|
|
||||||
scope :email_verification_failed, lambda {
|
scope :email_verification_failed, lambda {
|
||||||
joins('LEFT JOIN email_address_verifications emv ON contacts.email = emv.email')
|
joins('LEFT JOIN email_address_verifications emv ON contacts.email = emv.email')
|
||||||
.where('success = false and verified_at IS NOT NULL')
|
.where('success = false and verified_at IS NOT NULL')
|
||||||
|
|
|
@ -55,7 +55,6 @@ class Domain < ApplicationRecord
|
||||||
accepts_nested_attributes_for :dnskeys, allow_destroy: true
|
accepts_nested_attributes_for :dnskeys, allow_destroy: true
|
||||||
|
|
||||||
has_many :legal_documents, as: :documentable
|
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
|
has_many :registrant_verifications, dependent: :destroy
|
||||||
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
|
|
13
app/models/epp/expired_sessions.rb
Normal file
13
app/models/epp/expired_sessions.rb
Normal file
|
@ -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
|
|
@ -3,6 +3,11 @@ class EppSession < ApplicationRecord
|
||||||
|
|
||||||
validates :session_id, uniqueness: true, presence: true
|
validates :session_id, uniqueness: true, presence: true
|
||||||
|
|
||||||
|
class_attribute :timeout
|
||||||
|
self.timeout = (ENV['epp_session_timeout_seconds'] || 300).to_i.seconds
|
||||||
|
|
||||||
|
alias_attribute :last_access, :updated_at
|
||||||
|
|
||||||
def self.limit_per_registrar
|
def self.limit_per_registrar
|
||||||
4
|
4
|
||||||
end
|
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 = where(user_id: registrar.api_users.ids).where('updated_at >= ?', Time.zone.now - 1.second).count
|
||||||
count >= limit_per_registrar
|
count >= limit_per_registrar
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
class LegalDocument < ApplicationRecord
|
class LegalDocument < ApplicationRecord
|
||||||
cattr_accessor :explicitly_write_file
|
|
||||||
include EppErrors
|
include EppErrors
|
||||||
MIN_BODY_SIZE = (1.37 * 3.kilobytes).ceil
|
MIN_BODY_SIZE = (1.37 * 3.kilobytes).ceil
|
||||||
|
|
||||||
|
@ -44,7 +43,7 @@ class LegalDocument < ApplicationRecord
|
||||||
break unless File.file?(path)
|
break unless File.file?(path)
|
||||||
end
|
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) } unless Rails.env.test?
|
||||||
self.path = path
|
self.path = path
|
||||||
self.checksum = digest
|
self.checksum = digest
|
||||||
end
|
end
|
||||||
|
|
|
@ -153,6 +153,8 @@ lhv_keystore_password:
|
||||||
lhv_ca_file: # Needed only in dev mode
|
lhv_ca_file: # Needed only in dev mode
|
||||||
lhv_dev_mode: 'false'
|
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.
|
# Since the keys for staging are absent from the repo, we need to supply them separate for testing.
|
||||||
test:
|
test:
|
||||||
payments_seb_bank_certificate: 'test/fixtures/files/seb_bank_cert.pem'
|
payments_seb_bank_certificate: 'test/fixtures/files/seb_bank_cert.pem'
|
||||||
|
|
|
@ -202,7 +202,7 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
resources :zonefiles
|
resources :zonefiles
|
||||||
resources :zones, controller: 'dns/zones', except: %i[show destroy]
|
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
|
resources :prices, controller: 'billing/prices', except: %i[show destroy] do
|
||||||
member do
|
member do
|
||||||
patch :expire
|
patch :expire
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class ChangeLegalDocumentsPathToNotNull < ActiveRecord::Migration[5.0]
|
||||||
|
def change
|
||||||
|
change_column_null :legal_documents, :path, false
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
class ChangeLegalDocumentsDocumentTypeToNotNull < ActiveRecord::Migration[5.0]
|
||||||
|
def change
|
||||||
|
change_column_null :legal_documents, :document_type, false
|
||||||
|
end
|
||||||
|
end
|
|
@ -1069,12 +1069,12 @@ ALTER SEQUENCE public.invoices_id_seq OWNED BY public.invoices.id;
|
||||||
|
|
||||||
CREATE TABLE public.legal_documents (
|
CREATE TABLE public.legal_documents (
|
||||||
id integer NOT NULL,
|
id integer NOT NULL,
|
||||||
document_type character varying,
|
document_type character varying NOT NULL,
|
||||||
documentable_id integer,
|
documentable_id integer,
|
||||||
documentable_type character varying,
|
documentable_type character varying,
|
||||||
created_at timestamp without time zone,
|
created_at timestamp without time zone,
|
||||||
creator_str character varying,
|
creator_str character varying,
|
||||||
path character varying,
|
path character varying NOT NULL,
|
||||||
checksum character varying
|
checksum character varying
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -4828,6 +4828,8 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||||
('20191203083643'),
|
('20191203083643'),
|
||||||
('20191206183853'),
|
('20191206183853'),
|
||||||
('20191212133136'),
|
('20191212133136'),
|
||||||
|
('20191219112434'),
|
||||||
|
('20191219124429'),
|
||||||
('20191227110904'),
|
('20191227110904'),
|
||||||
('20200113091254'),
|
('20200113091254'),
|
||||||
('20200115102202'),
|
('20200115102202'),
|
||||||
|
@ -4850,3 +4852,4 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||||
('20200812090409'),
|
('20200812090409'),
|
||||||
('20200812125810'),
|
('20200812125810'),
|
||||||
('20200902131603');
|
('20200902131603');
|
||||||
|
|
||||||
|
|
7
lib/tasks/epp/clear_expired_sessions.rake
Normal file
7
lib/tasks/epp/clear_expired_sessions.rake
Normal file
|
@ -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
|
4
test/fixtures/legal_documents.yml
vendored
Normal file
4
test/fixtures/legal_documents.yml
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
one:
|
||||||
|
documentable: shop (Domain)
|
||||||
|
document_type: pdf
|
||||||
|
path: some
|
|
@ -7,6 +7,14 @@ class DummyEppController < Epp::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
class EppBaseTest < EppTestCase
|
class EppBaseTest < EppTestCase
|
||||||
|
setup do
|
||||||
|
@original_session_timeout = EppSession.timeout
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
EppSession.timeout = @original_session_timeout
|
||||||
|
end
|
||||||
|
|
||||||
def test_internal_error
|
def test_internal_error
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
post 'epp/command/internal_error', to: 'dummy_epp#internal_error',
|
post 'epp/command/internal_error', to: 'dummy_epp#internal_error',
|
||||||
|
@ -81,6 +89,63 @@ class EppBaseTest < EppTestCase
|
||||||
assert_epp_response :authorization_error
|
assert_epp_response :authorization_error
|
||||||
end
|
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
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||||
|
<command>
|
||||||
|
<info>
|
||||||
|
<domain:info xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
|
||||||
|
<domain:name>#{domains(:shop).name}</domain:name>
|
||||||
|
</domain:info>
|
||||||
|
</info>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
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)
|
||||||
|
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
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||||
|
<command>
|
||||||
|
<info>
|
||||||
|
<domain:info xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
|
||||||
|
<domain:name>#{domains(:shop).name}</domain:name>
|
||||||
|
</domain:info>
|
||||||
|
</info>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
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
|
||||||
|
assert_equal now, session.last_access
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def valid_command_path
|
def valid_command_path
|
||||||
|
|
|
@ -27,7 +27,7 @@ class EppDomainDeleteBaseTest < EppTestCase
|
||||||
</delete>
|
</delete>
|
||||||
<extension>
|
<extension>
|
||||||
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
||||||
<eis:legalDocument type="pdf">dGVzdCBmYWlsCg==</eis:legalDocument>
|
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
|
||||||
</eis:extdata>
|
</eis:extdata>
|
||||||
</extension>
|
</extension>
|
||||||
</command>
|
</command>
|
||||||
|
@ -35,6 +35,7 @@ class EppDomainDeleteBaseTest < EppTestCase
|
||||||
XML
|
XML
|
||||||
|
|
||||||
post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
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_includes Domain.find_by(name: 'invalid.test').statuses, DomainStatus::PENDING_DELETE_CONFIRMATION
|
||||||
assert_epp_response :completed_successfully_action_pending
|
assert_epp_response :completed_successfully_action_pending
|
||||||
end
|
end
|
||||||
|
@ -54,7 +55,7 @@ class EppDomainDeleteBaseTest < EppTestCase
|
||||||
</delete>
|
</delete>
|
||||||
<extension>
|
<extension>
|
||||||
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
||||||
<eis:legalDocument type="pdf">dGVzdCBmYWlsCg==</eis:legalDocument>
|
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
|
||||||
</eis:extdata>
|
</eis:extdata>
|
||||||
</extension>
|
</extension>
|
||||||
</command>
|
</command>
|
||||||
|
@ -82,7 +83,7 @@ class EppDomainDeleteBaseTest < EppTestCase
|
||||||
</delete>
|
</delete>
|
||||||
<extension>
|
<extension>
|
||||||
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
||||||
<eis:legalDocument type="pdf">dGVzdCBmYWlsCg==</eis:legalDocument>
|
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
|
||||||
</eis:extdata>
|
</eis:extdata>
|
||||||
</extension>
|
</extension>
|
||||||
</command>
|
</command>
|
||||||
|
@ -113,7 +114,7 @@ class EppDomainDeleteBaseTest < EppTestCase
|
||||||
</delete>
|
</delete>
|
||||||
<extension>
|
<extension>
|
||||||
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
||||||
<eis:legalDocument type="pdf">dGVzdCBmYWlsCg==</eis:legalDocument>
|
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
|
||||||
</eis:extdata>
|
</eis:extdata>
|
||||||
</extension>
|
</extension>
|
||||||
</command>
|
</command>
|
||||||
|
@ -144,7 +145,7 @@ class EppDomainDeleteBaseTest < EppTestCase
|
||||||
</delete>
|
</delete>
|
||||||
<extension>
|
<extension>
|
||||||
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
||||||
<eis:legalDocument type="pdf">dGVzdCBmYWlsCg==</eis:legalDocument>
|
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
|
||||||
</eis:extdata>
|
</eis:extdata>
|
||||||
</extension>
|
</extension>
|
||||||
</command>
|
</command>
|
||||||
|
|
|
@ -150,7 +150,7 @@ class EppDomainTransferRequestTest < EppTestCase
|
||||||
</transfer>
|
</transfer>
|
||||||
<extension>
|
<extension>
|
||||||
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
||||||
<eis:legalDocument type="pdf">test</eis:legalDocument>
|
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
|
||||||
</eis:extdata>
|
</eis:extdata>
|
||||||
</extension>
|
</extension>
|
||||||
</command>
|
</command>
|
||||||
|
|
|
@ -124,4 +124,20 @@ class EppPollTest < EppTestCase
|
||||||
|
|
||||||
assert_epp_response :object_does_not_exist
|
assert_epp_response :object_does_not_exist
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_anonymous_user_cannot_access
|
||||||
|
request_xml = <<-XML
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||||
|
<command>
|
||||||
|
<poll op="req"/>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
post '/epp/command/poll', params: { frame: request_xml },
|
||||||
|
headers: { 'HTTP_COOKIE' => 'session=non-existent' }
|
||||||
|
|
||||||
|
assert_epp_response :authorization_error
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ class DomainUpdateConfirmJobTest < ActiveSupport::TestCase
|
||||||
@domain = domains(:shop)
|
@domain = domains(:shop)
|
||||||
@new_registrant = contacts(:william)
|
@new_registrant = contacts(:william)
|
||||||
@user = users(:api_bestnames)
|
@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,
|
@domain.update!(pending_json: { new_registrant_id: @new_registrant.id,
|
||||||
new_registrant_name: @new_registrant.name,
|
new_registrant_name: @new_registrant.name,
|
||||||
|
|
|
@ -3,6 +3,11 @@ require 'test_helper'
|
||||||
class EppSessionTest < ActiveSupport::TestCase
|
class EppSessionTest < ActiveSupport::TestCase
|
||||||
setup do
|
setup do
|
||||||
@epp_session = epp_sessions(:api_bestnames)
|
@epp_session = epp_sessions(:api_bestnames)
|
||||||
|
@original_session_timeout = EppSession.timeout
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
EppSession.timeout = @original_session_timeout
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_valid
|
def test_valid
|
||||||
|
@ -60,4 +65,39 @@ class EppSessionTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
refute EppSession.limit_reached?(registrars(:bestnames))
|
refute EppSession.limit_reached?(registrars(:bestnames))
|
||||||
end
|
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
|
end
|
||||||
|
|
14
test/models/legal_document_test.rb
Normal file
14
test/models/legal_document_test.rb
Normal file
|
@ -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
|
||||||
|
|
29
test/tasks/epp/clear_expired_sessions_test.rb
Normal file
29
test/tasks/epp/clear_expired_sessions_test.rb
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
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
|
||||||
|
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
|
||||||
|
|
||||||
|
def run_task
|
||||||
|
Rake::Task['epp:clear_expired_sessions'].execute
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue