Merge branch 'master' into improve-registrant-area

This commit is contained in:
Artur Beljajev 2018-09-18 13:04:35 +03:00
commit 1b16c92835
10 changed files with 144 additions and 25 deletions

View file

@ -2,3 +2,15 @@ greeting:
body: Welcome!
queued: true
registrar: bestnames
created_at: <%= Time.zone.parse('2010-07-04') %>
domain_deleted:
body: Your domain has been deleted
queued: true
registrar: bestnames
created_at: <%= Time.zone.parse('2010-07-05') %>
farewell:
body: Good bye!
queued: true
registrar: goodnames

View file

@ -1,24 +1,11 @@
require 'test_helper'
class EppPollTest < ApplicationIntegrationTest
def test_messages
post '/epp/command/poll', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_equal '1301', Nokogiri::XML(response.body).at_css('result')[:code]
assert_equal 1, Nokogiri::XML(response.body).css('msgQ').size
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end
# Deliberately does not conform to RFC5730, which requires the first message to be returned
def test_return_latest_message_when_queue_is_not_empty
message = messages(:domain_deleted)
def test_no_messages
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
def request_xml
<<-XML
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>
@ -26,5 +13,90 @@ class EppPollTest < ApplicationIntegrationTest
</command>
</epp>
XML
post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body)
assert_equal 1301.to_s, response_xml.at_css('result')[:code]
assert_equal 1, response_xml.css('result').size
assert_equal 2.to_s, response_xml.at_css('msgQ')[:count]
assert_equal message.id.to_s, response_xml.at_css('msgQ')[:id]
assert_equal Time.zone.parse('2010-07-05').utc.xmlschema, response_xml.at_css('msgQ qDate').text
assert_equal 'Your domain has been deleted', response_xml.at_css('msgQ msg').text
end
end
def test_no_messages_in_queue
registrars(:bestnames).messages.delete_all(:delete_all)
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="req"/>
</command>
</epp>
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

View file

@ -18,4 +18,10 @@ class MessageTest < ActiveSupport::TestCase
@message.registrar = nil
assert @message.invalid?
end
end
def test_dequeue
@message.dequeue
@message.reload
assert_not @message.queued?
end
end

View file

@ -22,7 +22,6 @@ class WhoisRecordTest < ActiveSupport::TestCase
registrant_kind: 'priv',
email: 'john@inbox.test',
expire: '2010-07-05',
nameservers: ['ns1.bestnames.test', 'ns2.bestnames.test'],
registrar_address: 'Main Street, New York, New York, 12345',
dnssec_keys: [],
}
@ -30,6 +29,10 @@ class WhoisRecordTest < ActiveSupport::TestCase
expected_partial_hash.each do |key, value|
assert_equal(value, @record.generated_json[key])
end
['ns1.bestnames.test', 'ns2.bestnames.test'].each do |item|
assert(@record.generated_json[:nameservers].include?(item))
end
end
def test_generated_body_has_justified_disclaimer