diff --git a/app/controllers/epp/contacts_controller.rb b/app/controllers/epp/contacts_controller.rb index 5509507d3..db96a186d 100644 --- a/app/controllers/epp/contacts_controller.rb +++ b/app/controllers/epp/contacts_controller.rb @@ -5,7 +5,7 @@ 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 + THROTTLED_ACTIONS = %i[info check create renew update transfer delete].freeze include Shunter::Integration::Throttle def info diff --git a/app/controllers/epp/domains_controller.rb b/app/controllers/epp/domains_controller.rb index a05b56531..abf360c55 100644 --- a/app/controllers/epp/domains_controller.rb +++ b/app/controllers/epp/domains_controller.rb @@ -6,7 +6,7 @@ module Epp before_action :set_paper_trail_whodunnit before_action :parse_schemas_prefix_and_version - THROTTLED_ACTIONS = %i[info renew update transfer delete].freeze + THROTTLED_ACTIONS = %i[info create check renew update transfer delete].freeze include Shunter::Integration::Throttle def info diff --git a/app/controllers/epp/polls_controller.rb b/app/controllers/epp/polls_controller.rb index a674bcd45..7fe6d2636 100644 --- a/app/controllers/epp/polls_controller.rb +++ b/app/controllers/epp/polls_controller.rb @@ -1,5 +1,8 @@ module Epp class PollsController < BaseController + THROTTLED_ACTIONS = %i[poll].freeze + include Shunter::Integration::Throttle + def poll authorize! :manage, :poll req_poll if params[:parsed_frame].css('poll').first['op'] == 'req' diff --git a/app/controllers/epp/sessions_controller.rb b/app/controllers/epp/sessions_controller.rb index 8d8b56e62..715b6d8f7 100644 --- a/app/controllers/epp/sessions_controller.rb +++ b/app/controllers/epp/sessions_controller.rb @@ -3,6 +3,9 @@ module Epp skip_authorization_check only: [:hello, :login, :logout] before_action :set_paper_trail_whodunnit + THROTTLED_ACTIONS = %i[login].freeze + include Shunter::Integration::Throttle + def hello render_epp_response('greeting') end diff --git a/test/integration/epp/contact/check/base_test.rb b/test/integration/epp/contact/check/base_test.rb index 6ad027fc6..367436fc5 100644 --- a/test/integration/epp/contact/check/base_test.rb +++ b/test/integration/epp/contact/check/base_test.rb @@ -3,6 +3,9 @@ require 'test_helper' class EppContactCheckBaseTest < EppTestCase setup do @contact = contacts(:john) + + adapter = ENV["shunter_default_adapter"].constantize.new + adapter&.clear! end def test_returns_valid_response @@ -157,6 +160,59 @@ class EppContactCheckBaseTest < EppTestCase # assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text end + def test_returns_valid_response_if_not_throttled + request_xml = <<-XML + + + + + + john-001 + + + + + XML + + post epp_check_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' + + request_xml = <<-XML + + + + + + john-001 + + + + + XML + + post epp_check_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + post epp_check_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 + assert response.body.include?(Shunter.default_error_message) + ENV["shunter_default_threshold"] = '10000' + ENV["shunter_enabled"] = 'false' + end + private def xml_schema diff --git a/test/integration/epp/contact/create/base_test.rb b/test/integration/epp/contact/create/base_test.rb index ba94fcd6f..1f16d531f 100644 --- a/test/integration/epp/contact/create/base_test.rb +++ b/test/integration/epp/contact/create/base_test.rb @@ -1,6 +1,11 @@ require 'test_helper' class EppContactCreateBaseTest < EppTestCase + setup do + adapter = ENV["shunter_default_adapter"].constantize.new + adapter&.clear! + end + def test_creates_new_contact_with_required_attributes name = 'new' email = 'new@registrar.test' @@ -362,4 +367,82 @@ class EppContactCreateBaseTest < EppTestCase assert_equal country_code, contact.country_code assert_equal state, contact.state end + + def test_returns_valid_response_if_not_throttled + name = 'new' + email = 'new@registrar.test' + phone = '+1.2' + + request_xml = <<-XML + + + + + + + #{name} + + #{phone} + #{email} + + + + + any + + + + + XML + + post epp_create_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' + name = 'new' + email = 'new@registrar.test' + phone = '+1.2' + + request_xml = <<-XML + + + + + + + #{name} + + #{phone} + #{email} + + + + + any + + + + + XML + + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + post epp_create_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 + assert response.body.include?(Shunter.default_error_message) + ENV["shunter_default_threshold"] = '10000' + ENV["shunter_enabled"] = 'false' + end end diff --git a/test/integration/epp/contact/info/base_test.rb b/test/integration/epp/contact/info/base_test.rb index dc8fcd5f7..09d0b0308 100644 --- a/test/integration/epp/contact/info/base_test.rb +++ b/test/integration/epp/contact/info/base_test.rb @@ -3,6 +3,9 @@ require 'test_helper' class EppContactInfoBaseTest < EppTestCase setup do @contact = contacts(:john) + + adapter = ENV["shunter_default_adapter"].constantize.new + adapter&.clear! end def test_returns_valid_response @@ -129,6 +132,62 @@ class EppContactInfoBaseTest < EppTestCase assert_equal 'No access', response_xml.at_xpath('//contact:name', contact: xml_schema).text end + def test_returns_valid_response_if_not_throttled + @contact.update_columns(code: @contact.code.upcase) + + request_xml = <<-XML + + + + + + john-001 + + + + + 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' + @contact.update_columns(code: @contact.code.upcase) + + request_xml = <<-XML + + + + + + john-001 + + + + + 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 + assert response.body.include?(Shunter.default_error_message) + ENV["shunter_default_threshold"] = '10000' + ENV["shunter_enabled"] = 'false' + end + private def xml_schema diff --git a/test/integration/epp/contact/update/base_test.rb b/test/integration/epp/contact/update/base_test.rb index 0c55c5223..6999e3f2d 100644 --- a/test/integration/epp/contact/update/base_test.rb +++ b/test/integration/epp/contact/update/base_test.rb @@ -6,6 +6,9 @@ class EppContactUpdateBaseTest < EppTestCase setup do @contact = contacts(:john) ActionMailer::Base.deliveries.clear + + adapter = ENV["shunter_default_adapter"].constantize.new + adapter&.clear! end def test_updates_contact @@ -470,6 +473,76 @@ class EppContactUpdateBaseTest < EppTestCase assert_equal '+123.4', @contact.phone end + def test_returns_valid_response_if_not_throttled + @contact.update_columns(code: @contact.code.upcase) + + request_xml = <<-XML + + + + + + john-001 + + + new name + + +123.4 + new-email@inbox.test + + + + + + XML + + post epp_update_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' + @contact.update_columns(code: @contact.code.upcase) + + request_xml = <<-XML + + + + + + john-001 + + + new name + + +123.4 + new-email@inbox.test + + + + + + XML + + post epp_update_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + post epp_update_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 + assert response.body.include?(Shunter.default_error_message) + ENV["shunter_default_threshold"] = '10000' + ENV["shunter_enabled"] = 'false' + end + private def make_contact_free_of_domains_where_it_acts_as_a_registrant(contact) diff --git a/test/integration/epp/domain/check/base_test.rb b/test/integration/epp/domain/check/base_test.rb index 7a1c20c88..536d6525a 100644 --- a/test/integration/epp/domain/check/base_test.rb +++ b/test/integration/epp/domain/check/base_test.rb @@ -1,6 +1,11 @@ require 'test_helper' class EppDomainCheckBaseTest < EppTestCase + setup do + adapter = ENV["shunter_default_adapter"].constantize.new + adapter&.clear! + end + def test_returns_valid_response request_xml = <<-XML @@ -193,4 +198,56 @@ class EppDomainCheckBaseTest < EppTestCase assert_correct_against_schema response_xml assert_equal 3, response_xml.xpath('//domain:cd', 'domain' => "#{Xsd::Schema.filename(for_prefix: 'domain-ee', for_version: '1.2')}").size end + + def test_returns_valid_response_if_not_throttled + request_xml = <<-XML + + + + + + some.test + + + + + XML + + post epp_check_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' + request_xml = <<-XML + + + + + + some.test + + + + + XML + + post epp_check_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + post epp_check_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 + assert response.body.include?(Shunter.default_error_message) + ENV["shunter_default_threshold"] = '10000' + ENV["shunter_enabled"] = 'false' + end end diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb index 4932c6989..180d165b3 100644 --- a/test/integration/epp/domain/create/base_test.rb +++ b/test/integration/epp/domain/create/base_test.rb @@ -1,6 +1,10 @@ require 'test_helper' class EppDomainCreateBaseTest < EppTestCase + setup do + adapter = ENV["shunter_default_adapter"].constantize.new + adapter&.clear! + end def test_illegal_chars_in_dns_key name = "new.#{dns_zones(:one).origin}" @@ -852,4 +856,85 @@ class EppDomainCreateBaseTest < EppTestCase assert_correct_against_schema response_xml assert_epp_response :completed_successfully end + + def test_returns_valid_response_if_not_throttled + now = Time.zone.parse('2010-07-05') + travel_to now + disputed_domain = disputes(:active) + password = disputed_domain.password + + request_xml = <<-XML + + + + + + #{disputed_domain.domain_name} + #{contacts(:john).code} + + + + + #{'test' * 2000} + + #{password} + + + + + + XML + + post epp_create_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' + + now = Time.zone.parse('2010-07-05') + travel_to now + disputed_domain = disputes(:active) + password = disputed_domain.password + + request_xml = <<-XML + + + + + + #{disputed_domain.domain_name} + #{contacts(:john).code} + + + + + #{'test' * 2000} + + #{password} + + + + + + XML + + post epp_create_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + post epp_create_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 + assert response.body.include?(Shunter.default_error_message) + ENV["shunter_default_threshold"] = '10000' + ENV["shunter_enabled"] = 'false' + end end diff --git a/test/integration/epp/domain/info/base_test.rb b/test/integration/epp/domain/info/base_test.rb index 56f9cd775..15939e212 100644 --- a/test/integration/epp/domain/info/base_test.rb +++ b/test/integration/epp/domain/info/base_test.rb @@ -234,6 +234,7 @@ class EppDomainInfoBaseTest < EppTestCase headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } response_xml = Nokogiri::XML(response.body) + # binding.pry assert_epp_response :session_limit_exceeded_server_closing_connection assert_correct_against_schema response_xml assert response.body.include?(Shunter.default_error_message) diff --git a/test/integration/epp/domain/update/base_test.rb b/test/integration/epp/domain/update/base_test.rb index 10c92ebc5..dbcbe3cb2 100644 --- a/test/integration/epp/domain/update/base_test.rb +++ b/test/integration/epp/domain/update/base_test.rb @@ -10,6 +10,9 @@ class EppDomainUpdateBaseTest < EppTestCase @original_registrant_change_verification = Setting.request_confirmation_on_registrant_change_enabled ActionMailer::Base.deliveries.clear + + adapter = ENV["shunter_default_adapter"].constantize.new + adapter&.clear! end teardown do @@ -882,6 +885,88 @@ class EppDomainUpdateBaseTest < EppTestCase assert_epp_response :object_does_not_exist end + def test_returns_valid_response_if_not_throttled + ENV['obj_and_extensions_prohibited'] = 'true' + @domain = domains(:shop) + @domain.statuses << DomainStatus::SERVER_EXTENSION_UPDATE_PROHIBITED + @domain.save + + request_xml = <<-XML + + + + + + shop.test + + + + #{nameservers(:shop_ns1).hostname} + + + #{nameservers(:shop_ns2).hostname} + + + + + + + + XML + + post epp_update_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' + ENV['obj_and_extensions_prohibited'] = 'true' + @domain = domains(:shop) + @domain.statuses << DomainStatus::SERVER_EXTENSION_UPDATE_PROHIBITED + @domain.save + + request_xml = <<-XML + + + + + + shop.test + + + + #{nameservers(:shop_ns1).hostname} + + + #{nameservers(:shop_ns2).hostname} + + + + + + + + XML + + post epp_update_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + post epp_update_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 + assert response.body.include?(Shunter.default_error_message) + ENV["shunter_default_threshold"] = '10000' + ENV["shunter_enabled"] = 'false' + end + private def assert_verification_and_notification_emails diff --git a/test/integration/epp/login_test.rb b/test/integration/epp/login_test.rb index 80d7251d6..0e07da9c6 100644 --- a/test/integration/epp/login_test.rb +++ b/test/integration/epp/login_test.rb @@ -3,6 +3,11 @@ require 'test_helper' class EppLoginTest < EppTestCase setup do @original_sessions_per_registrar_setting = EppSession.sessions_per_registrar + + ENV["shunter_default_threshold"] = '10000' + ENV["shunter_enabled"] = 'false' + adapter = ENV["shunter_default_adapter"].constantize.new + adapter&.clear! end teardown do @@ -181,6 +186,83 @@ class EppLoginTest < EppTestCase assert_epp_response :session_limit_exceeded_server_closing_connection end + def test_returns_valid_response_if_not_throttled + ENV["shunter_enabled"] = 'true' + user = users(:api_bestnames) + new_session_id = 'new-session-id' + + request_xml = <<-XML + + + + + #{user.username} + #{user.plain_text_password} + + 1.0 + en + + + #{Xsd::Schema.filename(for_prefix: 'domain-ee', for_version: '1.2')} + #{Xsd::Schema.filename(for_prefix: 'contact-ee', for_version: '1.1')} + urn:ietf:params:xml:ns:host-1.0 + urn:ietf:params:xml:ns:keyrelay-1.0 + + + + + XML + + post '/epp/session/login', params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => "session=#{new_session_id}" } + + 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' + user = users(:api_bestnames) + new_session_id = 'new-session-id' + + request_xml = <<-XML + + + + + #{user.username} + #{user.plain_text_password} + + 1.0 + en + + + #{Xsd::Schema.filename(for_prefix: 'domain-ee', for_version: '1.2')} + #{Xsd::Schema.filename(for_prefix: 'contact-ee', for_version: '1.1')} + urn:ietf:params:xml:ns:host-1.0 + urn:ietf:params:xml:ns:keyrelay-1.0 + + + + + XML + + post '/epp/session/login', params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => "session=#{new_session_id}" } + + post '/epp/session/login', params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => "session=#{new_session_id}" } + + 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 eliminate_effect_of_existing_epp_sessions diff --git a/test/integration/epp/poll_test.rb b/test/integration/epp/poll_test.rb index 7b114f7c0..0f7dc3765 100644 --- a/test/integration/epp/poll_test.rb +++ b/test/integration/epp/poll_test.rb @@ -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 + + 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