This commit is contained in:
Martin Lensment 2015-01-12 18:18:51 +02:00
parent d2c31021a9
commit 360c2d3db8
8 changed files with 98 additions and 13 deletions

View file

@ -121,7 +121,6 @@ module Epp::Common
def write_to_epp_log def write_to_epp_log
request_object = OBJECT_TYPES[params_hash['epp']['xmlns:ns2']] if params[:frame] request_object = OBJECT_TYPES[params_hash['epp']['xmlns:ns2']] if params[:frame]
ApiLog::EppLog.create!({ ApiLog::EppLog.create!({
request: params[:frame], request: params[:frame],
request_command: params[:command], request_command: params[:command],

View file

@ -2,7 +2,7 @@ module Epp::ContactsHelper
def create_contact def create_contact
@contact = Contact.new(contact_and_address_attributes) @contact = Contact.new(contact_and_address_attributes)
@contact.registrar = current_epp_user.registrar @contact.registrar = current_epp_user.registrar
render '/epp/contacts/create' and return if stamp(@contact) && @contact.save render_epp_response '/epp/contacts/create' and return if stamp(@contact) && @contact.save
handle_errors(@contact) handle_errors(@contact)
end end
@ -12,7 +12,7 @@ module Epp::ContactsHelper
@contact = Contact.where(code: code).first @contact = Contact.where(code: code).first
# if update_rights? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update)) # if update_rights? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update))
if owner? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update)) if owner? && stamp(@contact) && @contact.update_attributes(contact_and_address_attributes(:update))
render 'epp/contacts/update' render_epp_response 'epp/contacts/update'
else else
contact_exists?(code) contact_exists?(code)
handle_errors(@contact) and return handle_errors(@contact) and return
@ -26,14 +26,14 @@ module Epp::ContactsHelper
handle_errors(@contact) and return unless @contact handle_errors(@contact) and return unless @contact
handle_errors(@contact) and return unless @contact.destroy_and_clean handle_errors(@contact) and return unless @contact.destroy_and_clean
render '/epp/contacts/delete' render_epp_response '/epp/contacts/delete'
end end
# rubocop:enable Metrics/CyclomaticComplexity # rubocop:enable Metrics/CyclomaticComplexity
def check_contact def check_contact
ph = params_hash['epp']['command']['check']['check'] ph = params_hash['epp']['command']['check']['check']
@contacts = Contact.check_availability(ph[:id]) @contacts = Contact.check_availability(ph[:id])
render '/epp/contacts/check' render_epp_response '/epp/contacts/check'
end end
def info_contact def info_contact
@ -42,7 +42,7 @@ module Epp::ContactsHelper
@disclosure = ContactDisclosure.default_values.merge(@contact.disclosure.try(:as_hash) || {}) @disclosure = ContactDisclosure.default_values.merge(@contact.disclosure.try(:as_hash) || {})
@disclosure_policy = @contact.disclosure.try(:attributes_with_flag) @disclosure_policy = @contact.disclosure.try(:attributes_with_flag)
@owner = owner?(false) @owner = owner?(false)
render 'epp/contacts/info' render_epp_response 'epp/contacts/info'
end end
def renew_contact def renew_contact

View file

@ -10,7 +10,7 @@ module Epp::KeyrelayHelper
handle_errors(@domain) and return unless @domain.authenticate(parsed_frame.css('pw').text) handle_errors(@domain) and return unless @domain.authenticate(parsed_frame.css('pw').text)
handle_errors(@domain) and return unless @domain.keyrelay(parsed_frame, current_epp_user.registrar) handle_errors(@domain) and return unless @domain.keyrelay(parsed_frame, current_epp_user.registrar)
render '/epp/shared/success' render_epp_response '/epp/shared/success'
end end
private private

View file

@ -6,18 +6,16 @@ module Epp::PollHelper
def req_poll def req_poll
@message = current_epp_user.queued_messages.last @message = current_epp_user.queued_messages.last
render 'epp/poll/poll_no_messages' and return unless @message render_epp_response 'epp/poll/poll_no_messages' and return unless @message
if @message.attached_obj_type && @message.attached_obj_id if @message.attached_obj_type && @message.attached_obj_id
@object = Object.const_get(@message.attached_obj_type).find(@message.attached_obj_id) @object = Object.const_get(@message.attached_obj_type).find(@message.attached_obj_id)
end end
if @message.attached_obj_type == 'Keyrelay' if @message.attached_obj_type == 'Keyrelay'
@response = render_to_string('epp/poll/poll_keyrelay') render_epp_response 'epp/poll/poll_keyrelay'
render xml: @response
# render 'epp/poll/poll_keyrelay'
else else
render 'epp/poll/poll_req' render_epp_response 'epp/poll/poll_req'
end end
end end
@ -34,7 +32,7 @@ module Epp::PollHelper
end end
handle_errors(@message) and return unless @message.dequeue handle_errors(@message) and return unless @message.dequeue
render 'epp/poll/poll_ack' render_epp_response 'epp/poll/poll_ack'
end end
private private

View file

@ -78,6 +78,30 @@ describe 'EPP Contact', epp: true do
expect(Contact.first.ident).to eq '37605030299' expect(Contact.first.ident).to eq '37605030299'
expect(Contact.first.address.street).to eq('123 Example') expect(Contact.first.address.street).to eq('123 Example')
log = ApiLog::EppLog.all
expect(log.length).to eq(4)
expect(log[0].request_command).to eq('hello')
expect(log[0].request_successful).to eq(true)
expect(log[1].request_command).to eq('login')
expect(log[1].request_successful).to eq(true)
expect(log[1].api_user_name).to eq('zone')
expect(log[1].api_user_registrar).to eq('Registrar OÜ')
expect(log[2].request_command).to eq('create')
expect(log[2].request_object).to eq('contact')
expect(log[2].request_successful).to eq(true)
expect(log[2].api_user_name).to eq('zone')
expect(log[2].api_user_registrar).to eq('Registrar OÜ')
expect(log[2].request).not_to be_blank
expect(log[2].response).not_to be_blank
expect(log[3].request_command).to eq('logout')
expect(log[3].request_successful).to eq(true)
expect(log[3].api_user_name).to eq('zone')
expect(log[3].api_user_registrar).to eq('Registrar OÜ')
end end
it 'successfully adds registrar' do it 'successfully adds registrar' do

View file

@ -39,6 +39,30 @@ describe 'EPP Keyrelay', epp: true do
expect(response[:result_code]).to eq('1000') expect(response[:result_code]).to eq('1000')
expect(zone.messages.queued.count).to eq(1) expect(zone.messages.queued.count).to eq(1)
log = ApiLog::EppLog.all
expect(log.length).to eq(4)
expect(log[0].request_command).to eq('hello')
expect(log[0].request_successful).to eq(true)
expect(log[1].request_command).to eq('login')
expect(log[1].request_successful).to eq(true)
expect(log[1].api_user_name).to eq('elkdata')
expect(log[1].api_user_registrar).to eq('Elkdata')
expect(log[2].request_command).to eq('keyrelay')
expect(log[2].request_object).to eq('domain')
expect(log[2].request_successful).to eq(true)
expect(log[2].api_user_name).to eq('elkdata')
expect(log[2].api_user_registrar).to eq('Elkdata')
expect(log[2].request).not_to be_blank
expect(log[2].response).not_to be_blank
expect(log[3].request_command).to eq('logout')
expect(log[3].request_successful).to eq(true)
expect(log[3].api_user_name).to eq('elkdata')
expect(log[3].api_user_registrar).to eq('Elkdata')
end end
it 'returns an error when parameters are missing' do it 'returns an error when parameters are missing' do

View file

@ -20,6 +20,30 @@ describe 'EPP Poll', epp: true do
expect(response[:msg]).to eq('Command completed successfully; no messages') expect(response[:msg]).to eq('Command completed successfully; no messages')
expect(response[:result_code]).to eq('1300') expect(response[:result_code]).to eq('1300')
log = ApiLog::EppLog.all
expect(log.length).to eq(4)
expect(log[0].request_command).to eq('hello')
expect(log[0].request_successful).to eq(true)
expect(log[1].request_command).to eq('login')
expect(log[1].request_successful).to eq(true)
expect(log[1].api_user_name).to eq('zone')
expect(log[1].api_user_registrar).to eq('Registrar OÜ')
expect(log[2].request_command).to eq('poll')
expect(log[2].request_object).to eq(nil)
expect(log[2].request_successful).to eq(true)
expect(log[2].api_user_name).to eq('zone')
expect(log[2].api_user_registrar).to eq('Registrar OÜ')
expect(log[2].request).not_to be_blank
expect(log[2].response).not_to be_blank
expect(log[3].request_command).to eq('logout')
expect(log[3].request_successful).to eq(true)
expect(log[3].api_user_name).to eq('zone')
expect(log[3].api_user_registrar).to eq('Registrar OÜ')
end end
it 'queues and dequeues messages' do it 'queues and dequeues messages' do

View file

@ -65,6 +65,22 @@ describe 'EPP Session', epp: true do
response = epp_plain_request(login_xml_cache, :xml) response = epp_plain_request(login_xml_cache, :xml)
expect(response[:result_code]).to eq('2002') expect(response[:result_code]).to eq('2002')
expect(response[:msg]).to match(/Already logged in. Use/) expect(response[:msg]).to match(/Already logged in. Use/)
log = ApiLog::EppLog.all
expect(log.length).to eq(3)
expect(log[0].request_command).to eq('hello')
expect(log[0].request_successful).to eq(true)
expect(log[1].request_command).to eq('login')
expect(log[1].request_successful).to eq(true)
expect(log[1].api_user_name).to eq('gitlab')
expect(log[1].api_user_registrar).to eq('Registrar OÜ')
expect(log[2].request_command).to eq('login')
expect(log[2].request_successful).to eq(false)
expect(log[2].api_user_name).to eq('gitlab')
expect(log[2].api_user_registrar).to eq('Registrar OÜ')
end end
end end
end end