Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle IDN domain names in EPP check and EPP create #1140

Merged
merged 2 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/epp/domains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def create

if Domain.release_to_auction
request_domain_name = params[:parsed_frame].css('name').text.strip.downcase
domain_name = DNS::DomainName.new(request_domain_name)
domain_name = DNS::DomainName.new(SimpleIDN.to_unicode(request_domain_name))

if domain_name.at_auction?
throw :epp_error,
Expand Down
2 changes: 1 addition & 1 deletion app/models/epp/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ def check_availability(domain_names)
next
end

domain_name = DNS::DomainName.new(domain_name_as_string)
domain_name = DNS::DomainName.new(SimpleIDN.to_unicode(domain_name_as_string))

if domain_name.unavailable?
reason = I18n.t("errors.messages.epp_domain_#{domain_name.unavailability_reason}")
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/auctions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ one:
domain: auction.test
status: <%= Auction.statuses[:no_bids] %>
uuid: 1b3ee442-e8fe-4922-9492-8fcb9dccc69c

idn:
domain: "püramiid.test"
status: <%= Auction.statuses[:no_bids] %>
uuid: d05455cd-67c9-431e-bdbc-03487da9cbfa
52 changes: 52 additions & 0 deletions test/integration/epp/domain/check/auction_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# encoding: UTF-8
require 'test_helper'

class EppDomainCheckAuctionTest < ApplicationIntegrationTest
setup do
@auction = auctions(:one)
@idn_auction = auctions(:idn)
Domain.release_to_auction = true
end

Expand Down Expand Up @@ -35,6 +37,56 @@ def test_domain_is_unavailable_when_at_auction
assert_equal 'Domain is at auction', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
end

def test_idn_ascii_domain_is_unavailable_when_at_auction
@idn_auction.update!(status: Auction.statuses[:started])

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>
<domain:check xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>xn--pramiid-n2a.test</domain:name>
</domain: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 '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail']
assert_equal 'Domain is at auction', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
end

def test_idn_unicode_domain_is_unavailable_when_at_auction
@idn_auction.update!(status: Auction.statuses[:started])

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>
<domain:check xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>püramiid.test</domain:name>
</domain: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 '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail']
assert_equal 'Domain is at auction', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
end

def test_domain_is_unavailable_when_awaiting_payment
@auction.update!(status: Auction.statuses[:awaiting_payment])

Expand Down
282 changes: 282 additions & 0 deletions test/integration/epp/domain/create/auction_idn_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
# encoding: UTF-8
require 'test_helper'

class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest
def setup
super

@idn_auction = auctions(:idn)
Domain.release_to_auction = true
end

def teardown
super

Domain.release_to_auction = false
end

def test_registers_domain_with_ascii_idn_cannot_be_registered_without_registration_code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this. Forgot to delete registers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy and paste error

@idn_auction.update!(status: Auction.statuses[:payment_received],
registration_code: "auction001")

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>xn--pramiid-n2a.test</domain:name>
<domain:registrant>#{contacts(:john).code}</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

refute Domain.where(name: @idn_auction.domain).exists?

@idn_auction.reload
refute @idn_auction.domain_registered?

response_xml = Nokogiri::XML(response.body)
assert_equal '2003', response_xml.at_css('result')[:code]
assert_equal 'Required parameter missing; reserved>pw element is required',
response_xml.at_css('result msg').text
end

def test_registers_domain_with_unicode_idn_cannot_be_registered_without_registration_code
@idn_auction.update!(status: Auction.statuses[:payment_received],
registration_code: "auction001")

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>püramiid.test</domain:name>
<domain:registrant>#{contacts(:john).code}</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

refute Domain.where(name: @idn_auction.domain).exists?

@idn_auction.reload
refute @idn_auction.domain_registered?

response_xml = Nokogiri::XML(response.body)
assert_equal '2003', response_xml.at_css('result')[:code]
assert_equal 'Required parameter missing; reserved>pw element is required',
response_xml.at_css('result msg').text
end

def test_registers_domain_with_ascii_idn_cannot_be_registered_without_winning_the_auction
@idn_auction.started!

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>xn--pramiid-n2a.test</domain:name>
<domain:registrant>#{contacts(:john).code}</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

refute Domain.where(name: @idn_auction.domain).exists?

@idn_auction.reload
refute @idn_auction.domain_registered?

response_xml = Nokogiri::XML(response.body)
assert_equal '2306', response_xml.at_css('result')[:code]
assert_equal 'Parameter value policy error: domain is at auction',
response_xml.at_css('result msg').text
end

def test_registers_domain_with_unicode_idn_cannot_be_registered_without_winning_the_auction
@idn_auction.started!

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>püramiid.test</domain:name>
<domain:registrant>#{contacts(:john).code}</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

refute Domain.where(name: @idn_auction.domain).exists?

@idn_auction.reload
refute @idn_auction.domain_registered?

response_xml = Nokogiri::XML(response.body)
assert_equal '2306', response_xml.at_css('result')[:code]
assert_equal 'Parameter value policy error: domain is at auction',
response_xml.at_css('result msg').text
end

def test_registers_domain_with_unicode_idn_cannot_be_registered_without_winning_the_auction
@idn_auction.started!

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>püramiid.test</domain:name>
<domain:registrant>#{contacts(:john).code}</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

refute Domain.where(name: @idn_auction.domain).exists?

@idn_auction.reload
refute @idn_auction.domain_registered?

response_xml = Nokogiri::XML(response.body)
assert_equal '2306', response_xml.at_css('result')[:code]
assert_equal 'Parameter value policy error: domain is at auction',
response_xml.at_css('result msg').text
end

def test_registers_unicode_domain_with_correct_registration_code_when_payment_is_received
@idn_auction.update!(status: Auction.statuses[:payment_received],
registration_code: 'auction001')

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>püramiid.test</domain:name>
<domain:registrant>#{contacts(:john).code}</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>auction001</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

@idn_auction.reload
assert @idn_auction.domain_registered?
assert Domain.where(name: @idn_auction.domain).exists?

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_registers_ascii_domain_with_correct_registration_code_when_payment_is_received
@idn_auction.update!(status: Auction.statuses[:payment_received],
registration_code: 'auction001')

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>xn--pramiid-n2a.test</domain:name>
<domain:registrant>#{contacts(:john).code}</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>auction001</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

@idn_auction.reload
assert @idn_auction.domain_registered?
assert Domain.where(name: @idn_auction.domain).exists?

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
end