require 'test_helper'
class EppDomainCreateBaseTest < EppTestCase
def test_not_registers_domain_without_legaldoc
now = Time.zone.parse('2010-07-05')
travel_to now
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
request_xml = <<-XML
#{name}
#{registrant.code}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_epp_response :required_parameter_missing
end
def test_registers_new_domain_with_required_attributes
now = Time.zone.parse('2010-07-05')
travel_to now
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
request_xml = <<-XML
#{name}
#{registrant.code}
#{'test' * 2000}
XML
assert_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_epp_response :completed_successfully
domain = Domain.find_by(name: name)
assert_equal name, domain.name
assert_equal registrant, domain.registrant
assert_equal [contact], domain.admin_contacts
assert_equal [contact], domain.tech_contacts
assert_not_empty domain.transfer_code
default_registration_period = 1.year + 1.day
assert_equal now + default_registration_period, domain.expire_time
end
def test_registers_domain_without_legaldoc_if_optout
now = Time.zone.parse('2010-07-05')
travel_to now
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
registrar = registrant.registrar
registrar.legaldoc_optout = true
registrar.save(validate: false)
request_xml = <<-XML
#{name}
#{registrant.code}
XML
assert_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_epp_response :completed_successfully
domain = Domain.find_by(name: name)
assert_equal name, domain.name
assert_equal registrant, domain.registrant
end
def test_does_not_registers_domain_without_legaldoc_if_mandatory
now = Time.zone.parse('2010-07-05')
travel_to now
name = "new.#{dns_zones(:one).origin}"
contact = contacts(:john)
registrant = contact.becomes(Registrant)
registrar = registrant.registrar
assert registrar.legaldoc_mandatory?
request_xml = <<-XML
#{name}
#{registrant.code}
XML
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_epp_response :required_parameter_missing
Setting.legal_document_is_mandatory = false
assert_not registrar.legaldoc_mandatory?
assert_not Setting.legal_document_is_mandatory
assert_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
end
def test_registers_reserved_domain_with_registration_code
reserved_domain = reserved_domains(:one)
registration_code = reserved_domain.registration_code
request_xml = <<-XML
#{reserved_domain.name}
#{contacts(:john).code}
#{'test' * 2000}
#{registration_code}
XML
assert_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_epp_response :completed_successfully
reserved_domain.reload
assert_not_equal registration_code, reserved_domain.registration_code
end
def test_respects_custom_transfer_code
name = "new.#{dns_zones(:one).origin}"
transfer_code = 'custom-transfer-code'
request_xml = <<-XML
#{name}
#{contacts(:john).code}
#{transfer_code}
#{'test' * 2000}
XML
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_epp_response :completed_successfully
assert_equal transfer_code, Domain.find_by(name: name).transfer_code
end
def test_blocked_domain_cannot_be_registered
blocked_domain = 'blocked.test'
assert BlockedDomain.find_by(name: blocked_domain)
request_xml = <<-XML
#{blocked_domain}
#{contacts(:john).code}
#{'test' * 2000}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_epp_response :data_management_policy_violation
end
def test_blocked_punicode_domain_cannot_be_registered
blocked_domain = 'blockedäöüõ.test'
assert BlockedDomain.find_by(name: blocked_domain)
request_xml = <<-XML
#{SimpleIDN.to_ascii('blockedäöüõ.test')}
#{contacts(:john).code}
#{'test' * 2000}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_epp_response :data_management_policy_violation
end
def test_reserved_domain_cannot_be_registered_with_wrong_registration_code
request_xml = <<-XML
#{reserved_domains(:one).name}
#{contacts(:john).code}
#{'test' * 2000}
wrong
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_epp_response :invalid_authorization_information
end
def test_reserved_domain_cannot_be_registered_without_registration_code
reserved_domain = reserved_domains(:one)
request_xml = <<-XML
#{reserved_domain.name}
#{contacts(:john).code}
#{'test' * 2000}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_epp_response :required_parameter_missing
end
def test_insufficient_funds
session = epp_sessions(:api_bestnames)
session.user.registrar.accounts.first.update!(balance: 0)
request_xml = <<-XML
new.test
#{contacts(:john).code}
#{'test' * 2000}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => "session=#{session.session_id}" }
end
assert_epp_response :billing_failure
end
def test_no_price
assert_nil Billing::Price.find_by(duration: '2 months')
request_xml = <<-XML
new.test
2
john-001
#{'test' * 2000}
XML
assert_no_difference 'Domain.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
assert_epp_response :billing_failure
end
end