diff --git a/app/api/repp/api.rb b/app/api/repp/api.rb index c2a2c7715..8a2ac761f 100644 --- a/app/api/repp/api.rb +++ b/app/api/repp/api.rb @@ -9,7 +9,7 @@ module Repp before do unless Rails.env.development? - error! 'IP is not whitelisted', 401 unless @current_user.registrar.repp_ip_white?(request.ip) + error! I18n.t('ip_is_not_whitelisted'), 401 unless @current_user.registrar.repp_ip_white?(request.ip) end next if Rails.env.test? || Rails.env.development? diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index c27ce1e6b..770ee0c56 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -80,7 +80,11 @@ class EppController < ApplicationController end # VALIDATION + # rubocop: disable Metrics/PerceivedComplexity + # rubocop: disable Metrics/CyclomaticComplexity def validate_request + handle_errors and return unless ip_white? + validation_method = "validate_#{params[:action]}" return unless respond_to?(validation_method, true) send(validation_method) @@ -93,6 +97,22 @@ class EppController < ApplicationController handle_errors and return if epp_errors.any? end + # rubocop: enable Metrics/PerceivedComplexity + # rubocop: enable Metrics/CyclomaticComplexity + + def ip_white? + if current_user + unless current_user.registrar.epp_ip_white?(request.ip) + epp_errors << { + msg: t('ip_is_not_whitelisted'), + code: '2201' + } + return false + end + end + + true + end # let's follow grape's validations: https://github.com/intridea/grape/#parameter-validation-and-coercion diff --git a/app/controllers/registrar/domains_controller.rb b/app/controllers/registrar/domains_controller.rb index d7e7fa34a..5da13d089 100644 --- a/app/controllers/registrar/domains_controller.rb +++ b/app/controllers/registrar/domains_controller.rb @@ -24,7 +24,7 @@ class Registrar::DomainsController < Registrar::DeppController # EPP controller if response_ok? render 'info' else - flash[:alert] = t(:domain_not_found) + flash[:alert] = @data.css('msg').text redirect_to registrar_domains_url and return end end @@ -118,9 +118,9 @@ class Registrar::DomainsController < Registrar::DeppController # EPP controller end def init_contacts_autocomplete_map - @contacts_autocomplete_map ||= + @contacts_autocomplete_map ||= current_user.registrar.contacts.pluck(:name, :code).map { |c| ["#{c.second} #{c.first}", c.second] } - # @priv_contacts_autocomplete_map ||= + # @priv_contacts_autocomplete_map ||= # current_user.registrar.priv_contacts.pluck(:name, :code).map { |c| ["#{c.second} #{c.first}", c.second] } end end diff --git a/app/models/depp/user.rb b/app/models/depp/user.rb index 16eacb25b..36cd08115 100644 --- a/app/models/depp/user.rb +++ b/app/models/depp/user.rb @@ -32,6 +32,8 @@ module Depp def request(xml) Nokogiri::XML(server.request(xml)).remove_namespaces! + rescue EppErrorResponse => e + Nokogiri::XML(e.response_xml.to_s).remove_namespaces! end def repp_request(path, params = {}) diff --git a/config/locales/en.yml b/config/locales/en.yml index adc329141..c3bd4256e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -795,3 +795,4 @@ en: domain_registrant_change_rejected_body: 'You have rejected domain owner change.' registrant_domain_verification_rejected: 'Domain owner change has been rejected successfully.' registrant_domain_verification_rejected_failed: 'Something went wrong' + ip_is_not_whitelisted: 'IP is not whitelisted' diff --git a/spec/fabricators/registrar_fabricator.rb b/spec/fabricators/registrar_fabricator.rb index 6816f0253..d5e1ca5f7 100644 --- a/spec/fabricators/registrar_fabricator.rb +++ b/spec/fabricators/registrar_fabricator.rb @@ -10,7 +10,7 @@ Fabricator(:registrar) do code { sequence(:code) { |i| "REGISTRAR#{i}" } } reference_no { sequence(:reference_no) { |i| "RF#{i}" } } accounts(count: 1) - white_ips { [Fabricate(:white_ip_repp, ipv4: '127.0.0.1')] } + white_ips { [Fabricate(:white_ip_repp, ipv4: '127.0.0.1'), Fabricate(:white_ip, ipv4: '127.0.0.1')] } end Fabricator(:registrar_with_no_account_activities, from: :registrar) do