Fixed codeclimate issues

This commit is contained in:
Sergei Tsoganov 2022-11-23 13:14:31 +02:00
parent aaa0e89cfe
commit cadb0a65bb
2 changed files with 27 additions and 19 deletions

View file

@ -15,23 +15,9 @@ module EppRequestable
private private
def validate_epp_user def validate_epp_user
tag = current_user.username return unless handle_hello_request
password = current_user.plain_text_password
res = server.open_connection
unless Nokogiri::XML(res).css('greeting')
server.close_connection # just in case
handle_non_epp_errors(nil, I18n.t('errors.messages.failed_epp_conn'))
return
end
ex = EppXml::Session.new(cl_trid_prefix: tag)
xml = ex.login(clID: { value: tag }, pw: { value: password })
res = server.send_request(xml)
if Nokogiri::XML(res).css('result').first['code'] != '1000'
handle_non_epp_errors(nil, Nokogiri::XML(res).css('result').text)
end
handle_login_request
server.close_connection server.close_connection
rescue OpenSSL::SSL::SSLError => e rescue OpenSSL::SSL::SSLError => e
Rails.logger.error "INVALID CERT: #{e}" Rails.logger.error "INVALID CERT: #{e}"
@ -40,6 +26,26 @@ module EppRequestable
handle_non_epp_errors(nil, I18n.t('errors.messages.invalid_cert')) handle_non_epp_errors(nil, I18n.t('errors.messages.invalid_cert'))
end end
def handle_hello_request
res = server.open_connection
unless Nokogiri::XML(res).css('greeting')
server.close_connection # just in case
handle_non_epp_errors(nil, I18n.t('errors.messages.failed_epp_conn')) and return false
end
true
end
def handle_login_request
tag = current_user.username
ex = EppXml::Session.new(cl_trid_prefix: tag)
xml = ex.login(clID: { value: tag }, pw: { value: current_user.plain_text_password })
res = server.send_request(xml)
return if Nokogiri::XML(res).css('result').first['code'] == '1000'
handle_non_epp_errors(nil, Nokogiri::XML(res).css('result').text)
end
def server def server
client_cert = File.read(ENV['cert_path']) client_cert = File.read(ENV['cert_path'])
client_key = File.read(ENV['key_path']) client_key = File.read(ENV['key_path'])
@ -54,4 +60,4 @@ module EppRequestable
def request_params def request_params
params.require(:xml_console).permit(:payload) params.require(:xml_console).permit(:payload)
end end
end end

View file

@ -13,8 +13,10 @@ module Repp
def load_xml def load_xml
cl_trid = "#{current_user.username}-#{Time.zone.now.to_i}" cl_trid = "#{current_user.username}-#{Time.zone.now.to_i}"
obj = ActionController::Base.helpers.sanitize(params[:obj])
epp_action = ActionController::Base.helpers.sanitize(params[:epp_action])
xml_dir_path = Rails.root.join('app/views/epp/sample_requests').to_s xml_dir_path = Rails.root.join('app/views/epp/sample_requests').to_s
xml = File.read("#{xml_dir_path}/#{params[:obj]}/#{params[:epp_action]}.xml") xml = File.read("#{xml_dir_path}/#{obj}/#{epp_action}.xml")
xml = prepare_payload(xml, cl_trid) xml = prepare_payload(xml, cl_trid)
render_success(data: { xml: xml }) render_success(data: { xml: xml })
@ -52,4 +54,4 @@ module Repp
end end
end end
end end
end end