Skip to content

Commit

Permalink
Merge pull request #1066 from internetee/add-epp-domain-create-tests
Browse files Browse the repository at this point in the history
Add epp domain create tests
  • Loading branch information
vohmar authored Jan 16, 2019
2 parents 8b7a633 + 6f580d3 commit 640faaa
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/reserved_domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class ReservedDomain < ActiveRecord::Base

validates :name, domain_name: true, uniqueness: true

alias_attribute :registration_code, :password

class << self
def pw_for(domain_name)
name_in_ascii = SimpleIDN.to_ascii(domain_name)
Expand Down
142 changes: 142 additions & 0 deletions test/integration/epp/domain/create/reserved_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
require 'test_helper'

class EppDomainCreateReservedTest < ApplicationIntegrationTest
setup do
@reserved_domain = reserved_domains(:one)
end

def test_registers_reserved_domain_with_correct_registration_code
assert_equal 'reserved.test', @reserved_domain.name
assert_equal 'reserved-001', @reserved_domain.registration_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>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>reserved.test</domain:name>
<domain:registrant>john-001</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
<eis:reserved>
<eis:pw>reserved-001</eis:pw>
</eis:reserved>
</eis:extdata>
</extension>
</command>
</epp>
XML

assert_difference 'Domain.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]
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end

def test_registering_reserved_domain_regenerates_registration_code
assert_equal 'reserved.test', @reserved_domain.name
assert_equal 'reserved-001', @reserved_domain.registration_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>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>reserved.test</domain:name>
<domain:registrant>john-001</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
<eis:reserved>
<eis:pw>reserved-001</eis:pw>
</eis:reserved>
</eis:extdata>
</extension>
</command>
</epp>
XML

post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
@reserved_domain.reload

assert_not_equal 'reserved-001', @reserved_domain.registration_code
end

def test_domain_cannot_be_registered_with_wrong_registration_code
assert_equal 'reserved.test', @reserved_domain.name
assert_equal 'reserved-001', @reserved_domain.registration_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>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>reserved.test</domain:name>
<domain:registrant>john-001</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
<eis:reserved>
<eis:pw>wrong</eis:pw>
</eis:reserved>
</eis:extdata>
</extension>
</command>
</epp>
XML

assert_no_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end

response_xml = Nokogiri::XML(response.body)
assert_equal '2202', response_xml.at_css('result')[:code]
assert_equal 'Invalid authorization information; invalid reserved>pw value',
response_xml.at_css('result msg').text
end

def test_domain_cannot_be_registered_without_registration_code
assert_equal 'reserved.test', @reserved_domain.name

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>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>reserved.test</domain:name>
<domain:registrant>john-001</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
</eis:extdata>
</extension>
</command>
</epp>
XML

assert_no_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end

response_xml = Nokogiri::XML(response.body)
assert_equal '2003', response_xml.at_css('result')[:code]
assert_equal 'Required parameter missing; reserved>pw element required for reserved domains',
response_xml.at_css('result msg').text
end
end
5 changes: 5 additions & 0 deletions test/models/reserved_domain_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ class ReservedDomainTest < ActiveSupport::TestCase
def test_fixture_is_valid
assert @reserved_domain.valid?
end

def test_aliases_registration_code_to_password
reserved_domain = ReservedDomain.new(password: 'reserved-001')
assert_equal 'reserved-001', reserved_domain.registration_code
end
end

0 comments on commit 640faaa

Please sign in to comment.