mirror of
https://github.com/internetee/registry.git
synced 2025-06-09 14:14:49 +02:00
Define message order explicitly, improve EPP poll tests
This commit is contained in:
parent
4bf24d8ba7
commit
00f3a01e5c
4 changed files with 81 additions and 13 deletions
|
@ -9,7 +9,7 @@ class Epp::PollsController < EppController
|
||||||
private
|
private
|
||||||
|
|
||||||
def req_poll
|
def req_poll
|
||||||
@message = current_user.queued_messages.last
|
@message = current_user.queued_messages.order('created_at DESC').take
|
||||||
|
|
||||||
render_epp_response '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
|
||||||
|
|
6
test/fixtures/messages.yml
vendored
6
test/fixtures/messages.yml
vendored
|
@ -2,9 +2,15 @@ greeting:
|
||||||
body: Welcome!
|
body: Welcome!
|
||||||
queued: true
|
queued: true
|
||||||
registrar: bestnames
|
registrar: bestnames
|
||||||
|
created_at: <%= Time.zone.parse('2010-07-04') %>
|
||||||
|
|
||||||
domain_deleted:
|
domain_deleted:
|
||||||
body: Your domain has been deleted
|
body: Your domain has been deleted
|
||||||
queued: true
|
queued: true
|
||||||
registrar: bestnames
|
registrar: bestnames
|
||||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||||
|
|
||||||
|
farewell:
|
||||||
|
body: Good bye!
|
||||||
|
queued: true
|
||||||
|
registrar: goodnames
|
|
@ -24,17 +24,11 @@ class EppPollTest < ApplicationIntegrationTest
|
||||||
assert_equal 'Your domain has been deleted', response_xml.at_css('msgQ msg').text
|
assert_equal 'Your domain has been deleted', response_xml.at_css('msgQ msg').text
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_no_messages
|
def test_no_messages_in_queue
|
||||||
registrars(:bestnames).messages.delete_all(:delete_all)
|
registrars(:bestnames).messages.delete_all(:delete_all)
|
||||||
post '/epp/command/poll', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
|
||||||
assert_equal '1300', Nokogiri::XML(response.body).at_css('result')[:code]
|
|
||||||
assert_equal 1, Nokogiri::XML(response.body).css('result').size
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
request_xml =
|
||||||
|
<<-XML
|
||||||
def request_xml
|
|
||||||
<<-XML
|
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||||
<command>
|
<command>
|
||||||
|
@ -42,5 +36,67 @@ class EppPollTest < ApplicationIntegrationTest
|
||||||
</command>
|
</command>
|
||||||
</epp>
|
</epp>
|
||||||
XML
|
XML
|
||||||
|
post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
|
||||||
|
response_xml = Nokogiri::XML(response.body)
|
||||||
|
|
||||||
|
assert_equal 1300.to_s, response_xml.at_css('result')[:code]
|
||||||
|
assert_equal 1, response_xml.css('result').size
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_dequeue_message
|
||||||
|
message = messages(:greeting)
|
||||||
|
|
||||||
|
request_xml = <<-XML
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||||
|
<command>
|
||||||
|
<poll op="ack" msgID="#{message.id}"/>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
|
||||||
|
message.reload
|
||||||
|
response_xml = Nokogiri::XML(response.body)
|
||||||
|
|
||||||
|
assert_not message.queued?
|
||||||
|
assert_equal 1000.to_s, response_xml.at_css('result')[:code]
|
||||||
|
assert_equal 1, response_xml.css('result').size
|
||||||
|
assert_equal 1.to_s, response_xml.at_css('msgQ')[:count]
|
||||||
|
assert_equal message.id.to_s, response_xml.at_css('msgQ')[:id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_message_of_other_registrars_cannot_be_dequeued
|
||||||
|
message = messages(:farewell)
|
||||||
|
|
||||||
|
request_xml = <<-XML
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||||
|
<command>
|
||||||
|
<poll op="ack" msgID="#{message.id}"/>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
|
||||||
|
response_xml = Nokogiri::XML(response.body)
|
||||||
|
message.reload
|
||||||
|
|
||||||
|
assert message.queued?
|
||||||
|
assert_equal 2303.to_s, response_xml.at_css('result')[:code]
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_message_not_found
|
||||||
|
request_xml = <<-XML
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
|
||||||
|
<command>
|
||||||
|
<poll op="ack" msgID="0"/>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
|
||||||
|
response_xml = Nokogiri::XML(response.body)
|
||||||
|
|
||||||
|
assert_equal 2303.to_s, response_xml.at_css('result')[:code]
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -18,4 +18,10 @@ class MessageTest < ActiveSupport::TestCase
|
||||||
@message.registrar = nil
|
@message.registrar = nil
|
||||||
assert @message.invalid?
|
assert @message.invalid?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_dequeue
|
||||||
|
@message.dequeue
|
||||||
|
@message.reload
|
||||||
|
assert_not @message.queued?
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Add table
Add a link
Reference in a new issue