Add shunter gem support & tests

This commit is contained in:
Alex Sherman 2021-06-18 17:46:17 +05:00 committed by olegphenomenon
parent 4db0ab558f
commit 83413213d9
5 changed files with 79 additions and 5 deletions

View file

@ -21,12 +21,22 @@ module Epp
rescue_from StandardError, with: :respond_with_command_failed_error
rescue_from AuthorizationError, with: :respond_with_authorization_error
rescue_from ActiveRecord::RecordNotFound, with: :respond_with_object_does_not_exist_error
rescue_from Shunter::ThrottleError, with: :respond_with_session_limit_exceeded_error
before_action :set_paper_trail_whodunnit
skip_before_action :validate_against_schema
protected
def respond_with_session_limit_exceeded_error(exception)
epp_errors.add(:epp_errors,
code: '2502',
message: 'Session limit exceeded, try again later')
handle_errors
log_exception(exception)
end
def respond_with_command_failed_error(exception)
epp_errors.add(:epp_errors,
code: '2400',
@ -51,6 +61,11 @@ module Epp
private
def throttled_user
authorize!(:throttled_user, @domain) unless current_user
current_user
end
def wrap_exceptions
yield
rescue CanCan::AccessDenied

View file

@ -5,6 +5,9 @@ module Epp
before_action :find_contact, only: [:info, :update, :delete]
before_action :find_password, only: [:info, :update, :delete]
THROTTLED_ACTIONS = %i[info renew update transfer delete].freeze
include Shunter::Integration::Throttle
def info
authorize! :info, @contact, @password
render_epp_response 'epp/contacts/info'

View file

@ -134,11 +134,6 @@ module Epp
private
def throttled_user
authorize!(:throttled_user, @domain) unless current_user
current_user
end
def validate_info
@prefix = 'info > info >'
requires('name')