mirror of
https://github.com/internetee/registry.git
synced 2025-07-27 21:16:12 +02:00
Add shunter gem support & tests
This commit is contained in:
parent
4db0ab558f
commit
83413213d9
5 changed files with 79 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -198,6 +198,7 @@ test:
|
|||
dnssec_resolver_ips: 8.8.8.8, 8.8.4.4
|
||||
legal_documents_dir: 'test/fixtures/files'
|
||||
shunter_default_adapter: "Shunter::Adapters::Memory"
|
||||
shunter_enabled: "false"
|
||||
|
||||
openssl_config_path: 'test/fixtures/files/test_ca/openssl.cnf'
|
||||
crl_dir: 'test/fixtures/files/test_ca/crl'
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
require 'test_helper'
|
||||
|
||||
class EppDomainInfoBaseTest < EppTestCase
|
||||
setup do
|
||||
adapter = ENV["shunter_default_adapter"].constantize.new
|
||||
adapter&.clear!
|
||||
end
|
||||
|
||||
def test_returns_valid_response
|
||||
assert_equal 'john-001', contacts(:john).code
|
||||
domains(:shop).update_columns(statuses: [DomainStatus::OK],
|
||||
|
@ -180,6 +185,61 @@ class EppDomainInfoBaseTest < EppTestCase
|
|||
assert_correct_against_schema response_xml
|
||||
end
|
||||
|
||||
def test_returns_valid_response_if_not_throttled
|
||||
domain = domains(:shop)
|
||||
|
||||
request_xml = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee')}">
|
||||
<command>
|
||||
<info>
|
||||
<domain:info xmlns:domain="#{Xsd::Schema.filename(for_prefix: 'domain-ee')}">
|
||||
<domain:name>#{domain.name}</domain:name>
|
||||
</domain:info>
|
||||
</info>
|
||||
</command>
|
||||
</epp>
|
||||
XML
|
||||
|
||||
post epp_info_path, params: { frame: request_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
|
||||
response_xml = Nokogiri::XML(response.body)
|
||||
assert_epp_response :completed_successfully
|
||||
assert_correct_against_schema response_xml
|
||||
end
|
||||
|
||||
def test_returns_error_response_if_throttled
|
||||
ENV["shunter_default_threshold"] = '1'
|
||||
ENV["shunter_enabled"] = 'true'
|
||||
domain = domains(:shop)
|
||||
|
||||
request_xml = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee')}">
|
||||
<command>
|
||||
<info>
|
||||
<domain:info xmlns:domain="#{Xsd::Schema.filename(for_prefix: 'domain-ee')}">
|
||||
<domain:name>#{domain.name}</domain:name>
|
||||
</domain:info>
|
||||
</info>
|
||||
</command>
|
||||
</epp>
|
||||
XML
|
||||
|
||||
post epp_info_path, params: { frame: request_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
|
||||
post epp_info_path, params: { frame: request_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
|
||||
response_xml = Nokogiri::XML(response.body)
|
||||
assert_epp_response :session_limit_exceeded_server_closing_connection
|
||||
assert_correct_against_schema response_xml
|
||||
ENV["shunter_default_threshold"] = '10000'
|
||||
ENV["shunter_enabled"] = 'false'
|
||||
end
|
||||
|
||||
def test_returns_valid_response_if_release_prohibited
|
||||
domain = domains(:shop)
|
||||
domain.update_columns(statuses: [DomainStatus::SERVER_RELEASE_PROHIBITED],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue