mirror of
https://github.com/internetee/registry.git
synced 2025-06-08 21:54:48 +02:00
Merge pull request #1155 from internetee/add-basic-epp-contact-tests
Add basic EPP contact tests
This commit is contained in:
commit
b96aa87120
7 changed files with 355 additions and 51 deletions
|
@ -1,50 +0,0 @@
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe 'EPP contact:delete' do
|
|
||||||
let(:session_id) { create(:epp_session, user: user).session_id }
|
|
||||||
let(:user) { create(:api_user, registrar: registrar) }
|
|
||||||
let(:registrar) { create(:registrar) }
|
|
||||||
let!(:registrant) { create(:registrant, registrar: registrar, code: 'TEST') }
|
|
||||||
let(:request) { post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => "session=#{session_id}" }
|
|
||||||
let(: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>
|
|
||||||
<delete>
|
|
||||||
<contact:delete xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
|
||||||
<contact:id>test</contact:id>
|
|
||||||
</contact:delete>
|
|
||||||
</delete>
|
|
||||||
</command>
|
|
||||||
</epp>
|
|
||||||
XML
|
|
||||||
}
|
|
||||||
|
|
||||||
before do
|
|
||||||
sign_in user
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when contact is used' do
|
|
||||||
let!(:domain) { create(:domain, registrant: registrant) }
|
|
||||||
|
|
||||||
specify do
|
|
||||||
request
|
|
||||||
expect(response).to have_code_of(2305)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not delete contact' do
|
|
||||||
expect { request }.to_not change { Contact.count }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when contact is not used' do
|
|
||||||
specify do
|
|
||||||
request
|
|
||||||
expect(response).to have_code_of(1000)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'deletes contact' do
|
|
||||||
expect { request }.to change { Contact.count }.from(1).to(0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
5
test/fixtures/contacts.yml
vendored
5
test/fixtures/contacts.yml
vendored
|
@ -8,6 +8,9 @@ john:
|
||||||
registrar: bestnames
|
registrar: bestnames
|
||||||
code: john-001
|
code: john-001
|
||||||
auth_info: cacb5b
|
auth_info: cacb5b
|
||||||
|
statuses:
|
||||||
|
- ok
|
||||||
|
- linked
|
||||||
uuid: eb2f2766-b44c-4e14-9f16-32ab1a7cb957
|
uuid: eb2f2766-b44c-4e14-9f16-32ab1a7cb957
|
||||||
created_at: <%= Time.zone.parse('2010-07-05') %>
|
created_at: <%= Time.zone.parse('2010-07-05') %>
|
||||||
updated_at: <%= Time.zone.parse('2010-07-06') %>
|
updated_at: <%= Time.zone.parse('2010-07-06') %>
|
||||||
|
@ -79,7 +82,7 @@ not_in_use:
|
||||||
name: Useless
|
name: Useless
|
||||||
email: useless@inbox.test
|
email: useless@inbox.test
|
||||||
registrar: bestnames
|
registrar: bestnames
|
||||||
code: useless-001
|
code: not-in-use
|
||||||
auth_info: e75a2a
|
auth_info: e75a2a
|
||||||
uuid: ca613cc5-a8dc-48c1-8d32-d3c6a0b6c952
|
uuid: ca613cc5-a8dc-48c1-8d32-d3c6a0b6c952
|
||||||
|
|
||||||
|
|
103
test/integration/epp/contact/check/base_test.rb
Normal file
103
test/integration/epp/contact/check/base_test.rb
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class EppContactCheckBaseTest < ActionDispatch::IntegrationTest
|
||||||
|
setup do
|
||||||
|
@contact = contacts(:john)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_returns_valid_response
|
||||||
|
assert_equal 'john-001', @contact.code
|
||||||
|
|
||||||
|
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>
|
||||||
|
<check>
|
||||||
|
<contact:check xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||||
|
<contact:id>john-001</contact:id>
|
||||||
|
</contact:check>
|
||||||
|
</check>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
|
||||||
|
|
||||||
|
response_xml = Nokogiri::XML(response.body)
|
||||||
|
assert_equal '1000', response_xml.at_css('result')[:code]
|
||||||
|
assert_equal 1, response_xml.css('result').size
|
||||||
|
assert_equal 'john-001', response_xml.at_xpath('//contact:id', contact: xml_schema).text
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_contact_is_available
|
||||||
|
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>
|
||||||
|
<check>
|
||||||
|
<contact:check xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||||
|
<contact:id>non-existing-id</contact:id>
|
||||||
|
</contact:check>
|
||||||
|
</check>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
|
||||||
|
|
||||||
|
response_xml = Nokogiri::XML(response.body)
|
||||||
|
assert_equal '1', response_xml.at_xpath('//contact:id', contact: xml_schema)['avail']
|
||||||
|
assert_nil response_xml.at_xpath('//contact:reason', contact: xml_schema)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_contact_is_unavailable
|
||||||
|
assert_equal 'john-001', @contact.code
|
||||||
|
|
||||||
|
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>
|
||||||
|
<check>
|
||||||
|
<contact:check xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||||
|
<contact:id>john-001</contact:id>
|
||||||
|
</contact:check>
|
||||||
|
</check>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
|
||||||
|
|
||||||
|
response_xml = Nokogiri::XML(response.body)
|
||||||
|
assert_equal '0', response_xml.at_xpath('//contact:id', contact: xml_schema)['avail']
|
||||||
|
assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_multiple_contacts
|
||||||
|
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>
|
||||||
|
<check>
|
||||||
|
<contact:check xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||||
|
<contact:id>one.test</contact:id>
|
||||||
|
<contact:id>two.test</contact:id>
|
||||||
|
<contact:id>three.test</contact:id>
|
||||||
|
</contact:check>
|
||||||
|
</check>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
|
||||||
|
|
||||||
|
response_xml = Nokogiri::XML(response.body)
|
||||||
|
assert_equal 3, response_xml.xpath('//contact:cd', contact: xml_schema).size
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def xml_schema
|
||||||
|
'https://epp.tld.ee/schema/contact-ee-1.1.xsd'
|
||||||
|
end
|
||||||
|
end
|
40
test/integration/epp/contact/create/base_test.rb
Normal file
40
test/integration/epp/contact/create/base_test.rb
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class EppContactCreateBaseTest < ActionDispatch::IntegrationTest
|
||||||
|
def test_creates_new_contact_with_minimum_required_parameters
|
||||||
|
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>
|
||||||
|
<create>
|
||||||
|
<contact:create xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||||
|
<contact:postalInfo>
|
||||||
|
<contact:name>New</contact:name>
|
||||||
|
</contact:postalInfo>
|
||||||
|
<contact:voice>+123.4</contact:voice>
|
||||||
|
<contact:email>new@inbox.test</contact:email>
|
||||||
|
</contact:create>
|
||||||
|
</create>
|
||||||
|
<extension>
|
||||||
|
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
|
||||||
|
<eis:ident type="priv" cc="US">test</eis:ident>
|
||||||
|
</eis:extdata>
|
||||||
|
</extension>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
assert_difference 'Contact.count' do
|
||||||
|
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
|
||||||
|
end
|
||||||
|
|
||||||
|
response_xml = Nokogiri::XML(response.body)
|
||||||
|
assert_equal '1000', response_xml.at_css('result')[:code]
|
||||||
|
|
||||||
|
contact = Contact.last
|
||||||
|
assert_not_empty contact.code
|
||||||
|
assert_equal 'New', contact.name
|
||||||
|
assert_equal 'new@inbox.test', contact.email
|
||||||
|
assert_equal '+123.4', contact.phone
|
||||||
|
end
|
||||||
|
end
|
60
test/integration/epp/contact/delete/base_test.rb
Normal file
60
test/integration/epp/contact/delete/base_test.rb
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class EppContactDeleteBaseTest < ActionDispatch::IntegrationTest
|
||||||
|
def setup
|
||||||
|
@contact = contacts(:john)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_deletes_a_contact_that_is_not_in_use
|
||||||
|
@contact = contacts(:not_in_use)
|
||||||
|
|
||||||
|
# https://github.com/internetee/registry/issues/415
|
||||||
|
@contact.update_columns(code: @contact.code.upcase)
|
||||||
|
|
||||||
|
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>
|
||||||
|
<delete>
|
||||||
|
<contact:delete xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||||
|
<contact:id>not-in-use</contact:id>
|
||||||
|
</contact:delete>
|
||||||
|
</delete>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
assert_difference 'Contact.count', -1 do
|
||||||
|
post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
|
||||||
|
end
|
||||||
|
response_xml = Nokogiri::XML(response.body)
|
||||||
|
assert_equal '1000', response_xml.at_css('result')[:code]
|
||||||
|
assert_equal 1, response_xml.css('result').size
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_contact_that_is_in_use_cannot_be_deleted
|
||||||
|
assert_equal 'john-001', @contact.code
|
||||||
|
|
||||||
|
# https://github.com/internetee/registry/issues/415
|
||||||
|
@contact.update_columns(code: @contact.code.upcase)
|
||||||
|
|
||||||
|
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>
|
||||||
|
<delete>
|
||||||
|
<contact:delete xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||||
|
<contact:id>john-001</contact:id>
|
||||||
|
</contact:delete>
|
||||||
|
</delete>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
assert_no_difference 'Contact.count' do
|
||||||
|
post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
|
||||||
|
end
|
||||||
|
response_xml = Nokogiri::XML(response.body)
|
||||||
|
assert_equal '2305', response_xml.at_css('result')[:code]
|
||||||
|
end
|
||||||
|
end
|
74
test/integration/epp/contact/info/base_test.rb
Normal file
74
test/integration/epp/contact/info/base_test.rb
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class EppContactInfoBaseTest < ActionDispatch::IntegrationTest
|
||||||
|
setup do
|
||||||
|
@contact = contacts(:john)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_returns_valid_response
|
||||||
|
assert_equal 'john-001', @contact.code
|
||||||
|
assert_equal [Contact::OK, Contact::LINKED], @contact.statuses
|
||||||
|
assert_equal 'john@inbox.test', @contact.email
|
||||||
|
assert_equal '+555.555', @contact.phone
|
||||||
|
assert_equal 'bestnames', @contact.registrar.code
|
||||||
|
assert_equal Time.zone.parse('2010-07-05'), @contact.created_at
|
||||||
|
|
||||||
|
# https://github.com/internetee/registry/issues/415
|
||||||
|
@contact.update_columns(code: @contact.code.upcase)
|
||||||
|
|
||||||
|
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>
|
||||||
|
<info>
|
||||||
|
<contact:info xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||||
|
<contact:id>john-001</contact:id>
|
||||||
|
</contact:info>
|
||||||
|
</info>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
|
||||||
|
|
||||||
|
response_xml = Nokogiri::XML(response.body)
|
||||||
|
assert_equal '1000', response_xml.at_css('result')[:code]
|
||||||
|
assert_equal 1, response_xml.css('result').size
|
||||||
|
assert_equal 'JOHN-001', response_xml.at_xpath('//contact:id', contact: xml_schema).text
|
||||||
|
assert_equal 'ok', response_xml.at_xpath('//contact:status', contact: xml_schema)['s']
|
||||||
|
assert_equal 'john@inbox.test', response_xml.at_xpath('//contact:email', contact: xml_schema)
|
||||||
|
.text
|
||||||
|
assert_equal '+555.555', response_xml.at_xpath('//contact:voice', contact: xml_schema).text
|
||||||
|
assert_equal 'bestnames', response_xml.at_xpath('//contact:clID', contact: xml_schema).text
|
||||||
|
assert_equal '2010-07-05T00:00:00+03:00', response_xml.at_xpath('//contact:crDate',
|
||||||
|
contact: xml_schema).text
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_contact_not_found
|
||||||
|
assert_nil Contact.find_by(code: 'non-existing')
|
||||||
|
|
||||||
|
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>
|
||||||
|
<info>
|
||||||
|
<contact:info xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||||
|
<contact:id>non-existing</contact:id>
|
||||||
|
</contact:info>
|
||||||
|
</info>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
|
||||||
|
|
||||||
|
response_xml = Nokogiri::XML(response.body)
|
||||||
|
assert_equal '2303', response_xml.at_css('result')[:code]
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def xml_schema
|
||||||
|
'https://epp.tld.ee/schema/contact-ee-1.1.xsd'
|
||||||
|
end
|
||||||
|
end
|
74
test/integration/epp/contact/update/base_test.rb
Normal file
74
test/integration/epp/contact/update/base_test.rb
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class EppContactUpdateBaseTest < ActionDispatch::IntegrationTest
|
||||||
|
setup do
|
||||||
|
@contact = contacts(:john)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_updates_contact
|
||||||
|
assert_equal 'john-001', @contact.code
|
||||||
|
assert_not_equal 'new name', @contact.name
|
||||||
|
assert_not_equal 'new-email@inbox.test', @contact.email
|
||||||
|
assert_not_equal '+123.4', @contact.phone
|
||||||
|
|
||||||
|
# https://github.com/internetee/registry/issues/415
|
||||||
|
@contact.update_columns(code: @contact.code.upcase)
|
||||||
|
|
||||||
|
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>
|
||||||
|
<update>
|
||||||
|
<contact:update xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||||
|
<contact:id>john-001</contact:id>
|
||||||
|
<contact:chg>
|
||||||
|
<contact:postalInfo>
|
||||||
|
<contact:name>new name</contact:name>
|
||||||
|
</contact:postalInfo>
|
||||||
|
<contact:voice>+123.4</contact:voice>
|
||||||
|
<contact:email>new-email@inbox.test</contact:email>
|
||||||
|
</contact:chg>
|
||||||
|
</contact:update>
|
||||||
|
</update>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
|
||||||
|
@contact.reload
|
||||||
|
|
||||||
|
response_xml = Nokogiri::XML(response.body)
|
||||||
|
assert_equal '1000', response_xml.at_css('result')[:code]
|
||||||
|
assert_equal 1, response_xml.css('result').size
|
||||||
|
assert_equal 'new name', @contact.name
|
||||||
|
assert_equal 'new-email@inbox.test', @contact.email
|
||||||
|
assert_equal '+123.4', @contact.phone
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_non_existing_contact
|
||||||
|
assert_nil Contact.find_by(code: 'non-existing')
|
||||||
|
|
||||||
|
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>
|
||||||
|
<update>
|
||||||
|
<contact:update xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
|
||||||
|
<contact:id>non-existing</contact:id>
|
||||||
|
<contact:chg>
|
||||||
|
<contact:postalInfo>
|
||||||
|
<contact:name>any</contact:name>
|
||||||
|
</contact:postalInfo>
|
||||||
|
</contact:chg>
|
||||||
|
</contact:update>
|
||||||
|
</update>
|
||||||
|
</command>
|
||||||
|
</epp>
|
||||||
|
XML
|
||||||
|
|
||||||
|
post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
|
||||||
|
|
||||||
|
response_xml = Nokogiri::XML(response.body)
|
||||||
|
assert_equal '2303', response_xml.at_css('result')[:code]
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue