Add rate limiting to all EPP actions

This commit is contained in:
Thiago Youssef 2022-08-02 06:14:21 -03:00 committed by olegphenomenon
parent 1a8d8b52e7
commit fb60466194
14 changed files with 629 additions and 2 deletions

View file

@ -2,6 +2,8 @@ require 'test_helper'
class EppPollTest < EppTestCase
setup do
adapter = ENV["shunter_default_adapter"].constantize.new
adapter&.clear!
@notification = notifications(:complete)
end
@ -149,6 +151,44 @@ class EppPollTest < EppTestCase
assert_epp_response :authorization_error
end
def test_returns_valid_response_if_not_throttled
notification = notifications(:greeting)
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee', for_version: '1.0')}">
<command>
<poll op="ack" msgID="#{notification.id}"/>
</command>
</epp>
XML
post epp_poll_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'
post epp_poll_path, params: { frame: request_req_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
post epp_poll_path, params: { frame: request_req_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
assert response.body.include?(Shunter.default_error_message)
ENV["shunter_default_threshold"] = '10000'
ENV["shunter_enabled"] = 'false'
end
private
def request_req_xml